bitorch_engine.layers.qconv.binary.cutlass.layer.BinaryConv2dForward

class bitorch_engine.layers.qconv.binary.cutlass.layer.BinaryConv2dForward(*args, **kwargs)[source]

Implements the forward pass for a binary convolutional layer.

This class defines a custom forward and backward pass for binary convolution using PyTorch. The forward pass includes integrated scaling and value range conversion for the inputs and weights. If the operation is performed during training, necessary variables for the backward pass are saved.

Methods

backward

Implements the backward pass for binary convolution.

forward

Performs the forward pass of the binary convolution.

Attributes

static backward(ctx: BackwardCFunction, output_gradient: Tensor) Tuple[Tensor, ...][source]

Implements the backward pass for binary convolution.

Parameters:
  • ctx – The context object with saved variables from the forward pass.

  • output_gradient (torch.Tensor) – Gradient of the loss with respect to the output.

Returns:

Gradients of the loss with respect to the inputs and weights, and None for non-tensor arguments.

Return type:

Tuple[torch.Tensor, …]

static forward(ctx, x: Tensor, weight: Tensor, scale_a: Tensor, scale_w: Tensor, is_train: bool, kernel_size: int, stride: int, padding: int, dilation: int) Tensor[source]

Performs the forward pass of the binary convolution.

Parameters:
  • ctx – Context object to stash information for backward computation.

  • x (torch.Tensor) – Input tensor.

  • weight (torch.Tensor) – Filter weights.

  • scale_a (torch.Tensor) – Scaling factor for the input.

  • scale_w (torch.Tensor) – Scaling factor for the weights.

  • is_train (bool) – Flag indicating if the forward pass is for training.

  • kernel_size (int) –

  • stride (int) – Stride of the convolution.

  • padding (int) – Padding added to all four sides of the input.

  • dilation (int) – Spacing between kernel elements.

Returns:

The output tensor of the binary convolution operation.

Return type:

torch.Tensor