qbm4eo.encoder module


This file is a part of qbm4eo.rst project.

https://github.com/FeralQubits/qbm4eo


It has been modified as a part of the EuroHPC PL project funded at the Smart Growth Operational Programme 2014-2020, Measure 4.2 under the grant agreement no. POIR.04.02.00-00-D014/20-00.


class qbm4eo.encoder.LBAEEncoder(input_size: Tuple[int, ...], out_channels: int, latent_space_size: int, num_layers: int, *args: Dict[str, Any], quantize: bool, negative_slope: float = 0.02, bias: bool = False, **kwargs: Dict[str, Any])[source]

Bases: Module

A class implementing the encoder of the LBAE model.

A default constructor for the LBAEEncoder class.

Parameters:
  • input_size – The size of the input image.

  • out_channels – The number of channels in the output image.

  • latent_space_size – The size of the latent space.

  • num_layers – The number of layers in the encoder.

forward(x: Tensor) Tuple[Tensor, Tensor][source]

A method implementing the forward pass of the LBAEEncoder class.

Parameters:

x – The input tensor.

Returns:

The output tensor.

class qbm4eo.encoder.QuantizerFunc(*args, **kwargs)[source]

Bases: Function

A class implementing the quantizer function.

Note:

This class is used to implement the quantizer function as a PyTorch autograd function. This is done to allow the quantizer function to be used in the forward pass of the LBAE model.

Note:

The forward and backward methods do not match signatures of their base methods.

static backward(_ctx, grad_output)[source]

A method implementing the backward pass of the QuantizerFunc class.

Parameters:
  • ctx – A context object.

  • grad_output – The gradient of the output tensor.

Returns:

Clone of the gradient output.

static forward(_ctx, f_input, dropout: int = 0)[source]

A method implementing the forward pass of the QuantizerFunc class.

Parameters:
  • ctx – A context object.

  • f_input – The input tensor.

  • dropout – The dropout rate.

Returns:

The quantized output tensor.

class qbm4eo.encoder.ResBlockConv(channels: int, *args: Dict[str, Any], in_channels: int | None = None, negative_slope: float = 0.02, bias: bool = False, **kwargs: Dict[str, Any])[source]

Bases: Module

A class implementing a residual block for convolutional layers.

A default constructor for the ResBlockConv class.

Parameters:
  • channels – The number of channels of the output tensors.

  • in_channels – The number of channels of the input tensor. If None, then the number of channels of the input tensor is assumed to be equal to the number of channels of the output tensor.

  • negative_slope – The negative slope of the LeakyReLU activation function.

  • bias – A boolean flag indicating whether to use a bias term in the convolutional layer.

forward(x: Tensor) Tensor[source]

A method implementing the forward pass of the ResBlockConv class.

Parameters:

x – The input tensor.

class qbm4eo.encoder.ResBlockConvPart(channels: int, *args: Dict[str, Any], negative_slope: float = 0.02, bias: bool = False, **kwargs: Dict[str, Any])[source]

Bases: Module

A class implementing a single part of a residual block for convolutional layers.

A default constructor for the ResBlockConvPart class.

Parameters:
  • channels – The number of channels of the input and output tensors.

  • negative_slope – The negative slope of the LeakyReLU activation function.

  • bias – A boolean flag indicating whether to use a bias term in the convolutional layer.

  • args – Additional positional arguments.

  • kwargs – Additional keyword arguments.

forward(x: Tensor) Tensor[source]

A method implementing the forward pass of the ResBlockConvPart class.

Parameters:

x – The input tensor.