mqbench.fake_quantize package

Submodules

mqbench.fake_quantize.dorefa

class mqbench.fake_quantize.dorefa.DoReFaFakeQuantize(observer, **observer_kwargs)[source]

Bases: QuantizeBase

fake_quant_enabled: Tensor
forward(X)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

observer_enabled: Tensor

mqbench.fake_quantize.dsq

class mqbench.fake_quantize.dsq.DSQFakeQuantize(observer, alpha=0.4, **observer_kwargs)[source]

Bases: QuantizeBase

fake_quant_enabled: Tensor
forward(X)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

observer_enabled: Tensor
class mqbench.fake_quantize.dsq.FakeQuantizeDSQPerchannel[source]

Bases: Function

static forward(ctx, x, scale, zero_point, quant_min, quant_max, ch_axis, alpha)[source]

Performs the operation.

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).

The context can be used to store tensors that can be then retrieved during the backward pass.

static symbolic(g, x, scale, zero_point, quant_min, quant_max, ch_axis, alpha)[source]
class mqbench.fake_quantize.dsq.FakeQuantizeDSQPertensor[source]

Bases: Function

static forward(ctx, x, scale, zero_point, quant_min, quant_max, alpha)[source]

Performs the operation.

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).

The context can be used to store tensors that can be then retrieved during the backward pass.

static symbolic(g, x, scale, zero_point, quant_min, quant_max, alpha)[source]
mqbench.fake_quantize.dsq.dsq_function_per_channel(x, scale, zero_point, quant_min, quant_max, ch_axis, alpha)[source]
mqbench.fake_quantize.dsq.dsq_function_per_tensor(x, scale, zero_point, quant_min, quant_max, alpha)[source]

mqbench.fake_quantize.fixed

class mqbench.fake_quantize.fixed.FixedFakeQuantize(observer, **observer_kwargs)[source]

Bases: QuantizeBase

This is actually torch.quantization.FakeQuantize.

extra_repr()[source]

Set the extra representation of the module

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

fake_quant_enabled: Tensor
forward(X)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

observer_enabled: Tensor

mqbench.fake_quantize.lsq

class mqbench.fake_quantize.lsq.FakeQuantizeLearnablePerchannelAffine[source]

Bases: Function

static forward(ctx, x, scale, zero_point, ch_axis, quant_min, quant_max, grad_factor)[source]

Performs the operation.

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).

The context can be used to store tensors that can be then retrieved during the backward pass.

static symbolic(g, x, scale, zero_point, ch_axis, quant_min, quant_max, grad_factor)[source]
class mqbench.fake_quantize.lsq.LearnableFakeQuantize(observer, scale=1.0, zero_point=0.0, use_grad_scaling=True, **observer_kwargs)[source]

Bases: QuantizeBase

This is an extension of the FakeQuantize module in fake_quantize.py, which supports more generalized lower-bit quantization and support learning of the scale and zero point parameters through backpropagation. For literature references, please see the class _LearnableFakeQuantizePerTensorOp. In addition to the attributes in the original FakeQuantize module, the _LearnableFakeQuantize module also includes the following attributes to support quantization parameter learning.

extra_repr()[source]

Set the extra representation of the module

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

fake_quant_enabled: Tensor
forward(X)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

observer_enabled: Tensor
mqbench.fake_quantize.lsq.grad_scale(t, scale)[source]

mqbench.fake_quantize.nnie

class mqbench.fake_quantize.nnie.NNIEFakeQuantize(observer, **observer_kwargs)[source]

Bases: QuantizeBase

fake_quant_enabled: Tensor
forward(X)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

observer_enabled: Tensor
class mqbench.fake_quantize.nnie.NNIEQuantizeFunc[source]

Bases: Function

static backward(ctx, grad_output)[source]

Defines a formula for differentiating the operation.

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by as many outputs did forward() return, and it should return as many tensors, as there were inputs to forward(). Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input.

The context can be used to retrieve tensors saved during the forward pass. It also has an attribute ctx.needs_input_grad as a tuple of booleans representing whether each input needs gradient. E.g., backward() will have ctx.needs_input_grad[0] = True if the first input to forward() needs gradient computated w.r.t. the output.

static forward(ctx, x, data_max)[source]

Performs the operation.

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).

The context can be used to store tensors that can be then retrieved during the backward pass.

static symbolic(g, x, data_max)[source]

mqbench.fake_quantize.pact

class mqbench.fake_quantize.pact.PACTFakeQuantize(observer, alpha=6.0, **observer_kwargs)[source]

Bases: QuantizeBase

extra_repr()[source]

Set the extra representation of the module

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

fake_quant_enabled: Tensor
forward(X)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

observer_enabled: Tensor

mqbench.fake_quantize.quantize_base

class mqbench.fake_quantize.quantize_base.QuantizeBase(observer=<class 'torch.quantization.observer.MovingAverageMinMaxObserver'>, **observer_kwargs)[source]

Bases: FakeQuantizeBase

This is an extension of the FakeQuantize module in fake_quantize.py, which supports more generalized lower-bit quantization and support learning of the scale and zero point parameters through backpropagation. For literature references, please see the class _LearnableFakeQuantizePerTensorOp. In addition to the attributes in the original FakeQuantize module, the _LearnableFakeQuantize module also includes the following attributes to support quantization parameter learning.

calculate_qparams()[source]
extra_repr()[source]

Set the extra representation of the module

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

fake_quant_enabled: Tensor
observer_enabled: Tensor

Module contents