bitorch.quantizations.base.Quantization

class bitorch.quantizations.base.Quantization[source]

superclass for quantization modules

Methods

forward

Quantizes the tensor using this classes quantize-method.

quantize

Apply the quantization function to the input tensor.

Attributes

bit_width

bitwidth

name

forward(x: Tensor) Tensor[source]

Quantizes the tensor using this classes quantize-method. Subclasses shall add some semantic there.

Parameters:

x (torch.Tensor) – tensor to be forwarded.

Returns:

quantized tensor x

Return type:

torch.Tensor

quantize(x: Tensor) Tensor[source]

Apply the quantization function to the input tensor.

It is recommended to use a torch.Function to also manipulate backwards behavior. See the implementations of sign or dorefa quantization functions for more examples.

Parameters:

x (torch.Tensor) – the input to be quantized

Raises:

NotImplementedError – raised if quantize function of superclass is called.

Returns:

the quantized tensor

Return type:

torch.Tensor