bitorch.quantizations.quantization_scheduler.ScheduledQuantizer

class bitorch.quantizations.quantization_scheduler.ScheduledQuantizer(quantizations: List[Quantization] = [], steps: int = 0)[source]

Base class for scheduled quantizers to inherit from. You can also use this quantization method to indicate to the quantization scheduler that only this quantization should be scheduled.

e.g. ``` model = Sequential(

QConv2d(3, 64, input_quantization=”scheduled_quantizer”, weight_quantization=”sign”), ReLU(), flatten(), QLinear(1000, 10, input_quantization=”sign”, weight_quantization=”sign”), Softmax(),

) # this replaces all quantizations in the model with scheduled quantizers and schedules them during training scheduler = Quantization_Scheduler(model, [Identity(), InputDorefa()], replace_all_quantizations=True)

# this only replaces the one instance of the ScheduledQuantizer and leaves the rest unchanged scheduler = Quantization_Scheduler(model, [Identity(), InputDorefa()], replace_all_quantizations=False) ```

Methods

__init__

Initias scheduled optimizer and sets bitwidth to width of last quantization to be scheduled.

quantize

dummy quantization function for compability reasons.

step

increments step count and updates internal factor variable

Attributes

bit_width

name

__init__(quantizations: List[Quantization] = [], steps: int = 0) None[source]

Initias scheduled optimizer and sets bitwidth to width of last quantization to be scheduled.

Parameters:
  • quantizations (List[Quantization]) – list of quantizations to be scheduled

  • steps (int) – number of steps. at the end of each step, the step() method has to be called once.

quantize(x: Tensor) Tensor[source]

dummy quantization function for compability reasons.

Parameters:

x (torch.Tensor) – input tensor

Returns:

unchanged input tensor

Return type:

torch.Tensor

step() None[source]

increments step count and updates internal factor variable