Skip to main content
`Ctrl`+`K`

# brevitas.core package

## Subpackages

- brevitas.core.bit_width package
  - Submodules
  - brevitas.core.bit_width.const module
    - `BitWidthConst`
      - `BitWidthConst.forward()`
    - `BitWidthStatefulConst`
      - `BitWidthStatefulConst.forward()`
    - `MsbClampBitWidth`
      - `MsbClampBitWidth.forward()`
  - brevitas.core.bit_width.parameter module
    - `BitWidthParameter`
      - `BitWidthParameter.forward()`
    - `RemoveBitwidthParameter`
      - `RemoveBitwidthParameter.forward()`
  - Module contents
- brevitas.core.function_wrapper package
  - Submodules
  - brevitas.core.function_wrapper.clamp module
    - `ClampMin`
      - `ClampMin.forward()`
    - `FloatClamp`
      - `FloatClamp.forward()`
      - `FloatClamp.inf_nan_clamp()`
      - `FloatClamp.saturating_clamp()`
    - `ScalarClamp`
      - `ScalarClamp.forward()`
    - `TensorClamp`
      - `TensorClamp.forward()`
  - brevitas.core.function_wrapper.misc module
    - `Identity`
      - `Identity.forward()`
    - `InplaceLogTwo`
      - `InplaceLogTwo.forward()`
    - `LogTwo`
      - `LogTwo.forward()`
    - `PowerOfTwo`
      - `PowerOfTwo.forward()`
  - brevitas.core.function_wrapper.ops_ste module
    - `CeilSte`
      - `CeilSte.forward()`
    - `DPURoundSte`
      - `DPURoundSte.forward()`
    - `FloorSte`
      - `FloorSte.forward()`
    - `InplaceTensorClampSte`
      - `InplaceTensorClampSte.forward()`
    - `RoundSte`
      - `RoundSte.forward()`
    - `RoundToZeroSte`
      - `RoundToZeroSte.forward()`
    - `ScalarClampMinSte`
      - `ScalarClampMinSte.forward()`
    - `TensorClampSte`
      - `TensorClampSte.forward()`
  - brevitas.core.function_wrapper.shape module
    - `DynamicOverSubChannelBlockView`
      - `DynamicOverSubChannelBlockView.forward()`
    - `OverBatchOverOutputChannelView`
      - `OverBatchOverOutputChannelView.forward()`
    - `OverBatchOverTensorView`
      - `OverBatchOverTensorView.forward()`
    - `OverOutputChannelView`
      - `OverOutputChannelView.forward()`
    - `OverOutputFeaturesView`
      - `OverOutputFeaturesView.forward()`
    - `OverSubChannelBlockView`
      - `OverSubChannelBlockView.forward()`
    - `OverTensorView`
      - `OverTensorView.forward()`
    - `PermuteDims`
      - `PermuteDims.forward()`
    - `StatsInputViewShapeImpl`
      - `StatsInputViewShapeImpl.DYNAMIC_OVER_SUBCHANNEL_BLOCK`
      - `StatsInputViewShapeImpl.OVER_BATCH_OVER_OUTPUT_CHANNELS`
      - `StatsInputViewShapeImpl.OVER_BATCH_OVER_TENSOR`
      - `StatsInputViewShapeImpl.OVER_OUTPUT_CHANNELS`
      - `StatsInputViewShapeImpl.OVER_OUTPUT_FEATURES`
      - `StatsInputViewShapeImpl.OVER_SUBCHANNEL_BLOCK`
      - `StatsInputViewShapeImpl.OVER_TENSOR`
  - Module contents
- brevitas.core.quant package
  - Submodules
  - brevitas.core.quant.binary module
    - `BinaryQuant`
      - `BinaryQuant.forward()`
    - `ClampedBinaryQuant`
      - `ClampedBinaryQuant.forward()`
  - brevitas.core.quant.delay module
    - `DelayWrapper`
      - `DelayWrapper.forward()`
  - brevitas.core.quant.int module
    - `DecoupledRescalingIntQuant`
      - `DecoupledRescalingIntQuant.forward()`
    - `DecoupledRescalingIntQuantWithInput`
      - `DecoupledRescalingIntQuantWithInput.forward()`
    - `PrescaledRestrictIntQuant`
      - `PrescaledRestrictIntQuant.forward()`
    - `PrescaledRestrictIntQuantWithInputBitWidth`
      - `PrescaledRestrictIntQuantWithInputBitWidth.forward()`
    - `RescalingIntQuant`
      - `RescalingIntQuant.forward()`
    - `TruncIntQuant`
      - `TruncIntQuant.forward()`
  - brevitas.core.quant.int_base module
    - `DecoupledIntQuant`
      - `DecoupledIntQuant.forward()`
      - `DecoupledIntQuant.max_int()`
      - `DecoupledIntQuant.min_int()`
      - `DecoupledIntQuant.to_int()`
    - `IntQuant`
      - `IntQuant.forward()`
      - `IntQuant.max_int()`
      - `IntQuant.min_int()`
      - `IntQuant.to_int()`
  - brevitas.core.quant.ternary module
    - `TernaryQuant`
      - `TernaryQuant.forward()`
  - Module contents
- brevitas.core.scaling package
  - Submodules
  - brevitas.core.scaling.int_scaling module
    - `IntScaling`
      - `IntScaling.forward()`
    - `PowerOfTwoIntScaling`
      - `PowerOfTwoIntScaling.forward()`
  - brevitas.core.scaling.runtime module
    - `RuntimeDynamicGroupStatsScaling`
      - `RuntimeDynamicGroupStatsScaling.forward()`
    - `RuntimeStatsScaling`
      - `RuntimeStatsScaling.forward()`
    - `StatsFromParameterScaling`
      - `StatsFromParameterScaling.forward()`
  - brevitas.core.scaling.standalone module
    - `ConstScaling`
      - `ConstScaling.forward()`
    - `ParameterFromRuntimeStatsScaling`
      - `ParameterFromRuntimeStatsScaling.forward()`
      - `ParameterFromRuntimeStatsScaling.state_dict()`
      - `ParameterFromRuntimeStatsScaling.training_forward()`
    - `ParameterFromStatsFromParameterScaling`
      - `ParameterFromStatsFromParameterScaling.forward()`
      - `ParameterFromStatsFromParameterScaling.state_dict()`
    - `ParameterScaling`
      - `ParameterScaling.forward()`
  - Module contents
- brevitas.core.stats package
  - Submodules
  - brevitas.core.stats.stats_op module
    - `AbsAve`
      - `AbsAve.forward()`
    - `AbsMax`
      - `AbsMax.forward()`
    - `AbsMaxAve`
      - `AbsMaxAve.forward()`
    - `AbsMaxL2`
      - `AbsMaxL2.forward()`
    - `AbsMinMax`
      - `AbsMinMax.forward()`
    - `AbsPercentile`
      - `AbsPercentile.forward()`
    - `HalfQuadraticOptimizerScale`
      - `HalfQuadraticOptimizerScale.forward()`
      - `HalfQuadraticOptimizerScale.optimize()`
      - `HalfQuadraticOptimizerScale.parameter_search()`
    - `HalfQuadraticOptimizerZeroPoint`
      - `HalfQuadraticOptimizerZeroPoint.forward()`
      - `HalfQuadraticOptimizerZeroPoint.optimize()`
      - `HalfQuadraticOptimizerZeroPoint.parameter_search()`
    - `KLMinimizerThreshold`
      - `KLMinimizerThreshold.forward()`
      - `KLMinimizerThreshold.smooth_normalize_distribution()`
    - `L1Norm`
      - `L1Norm.forward()`
    - `L2Norm`
      - `L2Norm.forward()`
    - `MSE`
      - `MSE.evaluate_loss()`
      - `MSE.forward()`
      - `MSE.mse_fib_search()`
      - `MSE.mse_grid_search()`
      - `MSE.mse_loss_fn()`
      - `MSE.mse_search()`
    - `MeanLearnedSigmaStd`
      - `MeanLearnedSigmaStd.forward()`
    - `MeanSigmaStd`
      - `MeanSigmaStd.forward()`
    - `NegativeMinOrZero`
      - `NegativeMinOrZero.forward()`
    - `NegativePercentileOrZero`
      - `NegativePercentileOrZero.forward()`
    - `PercentileInterval`
      - `PercentileInterval.forward()`
    - `masked_median()`
    - `shrink_lp_op()`
  - brevitas.core.stats.stats_wrapper module
  - brevitas.core.stats.view_wrapper module
  - Module contents

## Submodules

## brevitas.core.restrict_val module

class brevitas.core.restrict_val.FloatRestrictValue

  Bases: `Module`

  combine_scale_threshold(x, threshold)
    Return type:

      `Tensor`

  forward(x)

    Define the computation performed at every call.

    Should be overridden by all subclasses. :rtype: `Tensor`

    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.

  restrict_init_float(x)
    Return type:

      `float`

  restrict_init_inplace_module()
  restrict_init_module()
  restrict_init_tensor(x)
    Return type:

      `Tensor`

class brevitas.core.restrict_val.IntRestrictValue(restrict_value_float_to_int_impl=RoundSte())

  Bases: `Module`

  combine_scale_threshold(x, threshold)
    Return type:

      `Tensor`

  forward(x)

    Define 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.

  restrict_init_float(x)
  restrict_init_inplace_module()
  restrict_init_module()
  restrict_init_tensor(x)

class brevitas.core.restrict_val.LogFloatRestrictValue

  Bases: `Module`

  combine_scale_threshold(x, threshold)
    Return type:

      `Tensor`

  forward(x)

    Define 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.

  restrict_init_float(x)
  restrict_init_inplace_module()
  restrict_init_module()
  restrict_init_tensor(x)

class brevitas.core.restrict_val.PowerOfTwoRestrictValue(restrict_value_float_to_int_impl=RoundSte())

  Bases: `Module`

  combine_scale_threshold(x, threshold)
    Return type:

      `Tensor`

  forward(x)

    Define 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.

  restrict_init_float(x)
  restrict_init_inplace_module()
  restrict_init_module()
  restrict_init_tensor(x)

## brevitas.core.utils module

class brevitas.core.utils.ParameterWrapper(value)

  Bases: `Module`

  forward()

    Define 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.

class brevitas.core.utils.SingleArgStatelessBuffer(value)

  Bases: `Module`

  forward(placeholder)

    Define 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.

class brevitas.core.utils.SliceTensor

  Bases: `Module`

  eager_forward(x)
    Return type:

      `Tensor`

  forward(x)

    Define the computation performed at every call.

    Should be overridden by all subclasses. :rtype: `Tensor`

    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.

class brevitas.core.utils.StatelessBuffer(value)

  Bases: `Module`

  forward()

    Define 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.

  state_dict(destination=None, prefix='', keep_vars=False)

    Return a dictionary containing references to the whole state of the module.

    Both parameters and persistent buffers (e.g. running averages) are included. Keys are corresponding parameter and buffer names. Parameters and buffers set to `None` are not included.

    Note

    The returned object is a shallow copy. It contains references to the module’s parameters and buffers.

    Warning

    Currently `state_dict()` also accepts positional arguments for `destination`, `prefix` and `keep_vars` in order. However, this is being deprecated and keyword arguments will be enforced in future releases.

    Warning

    Please avoid the use of argument `destination` as it is not designed for end-users.

    Parameters:

      - destination (dict, optional) – If provided, the state of module will be updated into the dict and the same object is returned. Otherwise, an `OrderedDict` will be created and returned. Default: `None`.

      - prefix (str, optional) – a prefix added to parameter and buffer names to compose the keys in state_dict. Default: `''`.

      - keep_vars (bool, optional) – by default the `Tensor` s returned in the state dict are detached from autograd. If it’s set to `True`, detaching will not be performed. Default: `False`.

    Returns:

      a dictionary containing a whole state of the module

    Return type:

      dict

    Example:

        >>> # xdoctest: +SKIP("undefined vars")
        >>> module.state_dict().keys()
        ['bias', 'weight']

brevitas.core.utils.inplace_momentum_update(tensor, update, momentum, counter, new_counter)
  Return type:

    `Tensor`

brevitas.core.utils.inplace_tensor_add(tensor, value)
  Return type:

    `Tensor`

brevitas.core.utils.inplace_tensor_mul(tensor, value)
  Return type:

    `Tensor`

## brevitas.core.zero_point module

class brevitas.core.zero_point.ParameterFromRuntimeZeroPoint(collect_stats_steps, int_quant, quantize_zero_point, zero_point_stats_impl, zero_point_shape, zero_point_stats_input_view_shape_impl, zero_point_stats_momentum=0.1, dtype=None, device=None)

  Bases: `Module`

  forward(x, scale, bit_width)

    Define the computation performed at every call.

    Should be overridden by all subclasses. :rtype: `Tensor`

    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.

  state_dict(destination=None, prefix='', keep_vars=False)

    Return a dictionary containing references to the whole state of the module.

    Both parameters and persistent buffers (e.g. running averages) are included. Keys are corresponding parameter and buffer names. Parameters and buffers set to `None` are not included.

    Note

    The returned object is a shallow copy. It contains references to the module’s parameters and buffers.

    Warning

    Currently `state_dict()` also accepts positional arguments for `destination`, `prefix` and `keep_vars` in order. However, this is being deprecated and keyword arguments will be enforced in future releases.

    Warning

    Please avoid the use of argument `destination` as it is not designed for end-users.

    Parameters:

      - destination (dict, optional) – If provided, the state of module will be updated into the dict and the same object is returned. Otherwise, an `OrderedDict` will be created and returned. Default: `None`.

      - prefix (str, optional) – a prefix added to parameter and buffer names to compose the keys in state_dict. Default: `''`.

      - keep_vars (bool, optional) – by default the `Tensor` s returned in the state dict are detached from autograd. If it’s set to `True`, detaching will not be performed. Default: `False`.

    Returns:

      a dictionary containing a whole state of the module

    Return type:

      dict

    Example:

        >>> # xdoctest: +SKIP("undefined vars")
        >>> module.state_dict().keys()
        ['bias', 'weight']

  training_forward(x)
    Return type:

      `Tensor`

class brevitas.core.zero_point.ParameterFromStatsFromParameterZeroPoint(int_quant, quantize_zero_point, zero_point_stats_input_view_shape_impl, zero_point_stats_input_concat_dim, zero_point_stats_impl, zero_point_shape, tracked_parameter_list, dtype=None, device=None)

  Bases: `Module`

  ScriptModule implementation of a learned scale factor initialized from statistics of a parameter, e.g. weights MSE or AbsMax.

  forward(x, scale, bit_width)

    Define the computation performed at every call.

    Should be overridden by all subclasses. :rtype: `Tensor`

    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.

  state_dict(destination=None, prefix='', keep_vars=False)

    Return a dictionary containing references to the whole state of the module.

    Both parameters and persistent buffers (e.g. running averages) are included. Keys are corresponding parameter and buffer names. Parameters and buffers set to `None` are not included.

    Note

    The returned object is a shallow copy. It contains references to the module’s parameters and buffers.

    Warning

    Currently `state_dict()` also accepts positional arguments for `destination`, `prefix` and `keep_vars` in order. However, this is being deprecated and keyword arguments will be enforced in future releases.

    Warning

    Please avoid the use of argument `destination` as it is not designed for end-users.

    Parameters:

      - destination (dict, optional) – If provided, the state of module will be updated into the dict and the same object is returned. Otherwise, an `OrderedDict` will be created and returned. Default: `None`.

      - prefix (str, optional) – a prefix added to parameter and buffer names to compose the keys in state_dict. Default: `''`.

      - keep_vars (bool, optional) – by default the `Tensor` s returned in the state dict are detached from autograd. If it’s set to `True`, detaching will not be performed. Default: `False`.

    Returns:

      a dictionary containing a whole state of the module

    Return type:

      dict

    Example:

        >>> # xdoctest: +SKIP("undefined vars")
        >>> module.state_dict().keys()
        ['bias', 'weight']

class brevitas.core.zero_point.ParameterZeroPoint(zero_point_init, int_quant, quantize_zero_point, zero_point_shape=None, dtype=None, device=None)

  Bases: `Module`

  forward(x, scale, bit_width)

    Define the computation performed at every call.

    Should be overridden by all subclasses. :rtype: `Tensor`

    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.

class brevitas.core.zero_point.PreZeroCenterZeroPoint(stats_reduce_dim, pre_zero_point_stats_input_view_shape_impl, pre_zero_point_shape=None)

  Bases: `Module`

  Experimental ScriptModule implementation of a pre-scaling zero-point that zero-centers the incoming tensors. This is intended to be used with DecoupledIntQuant.

  forward(x, scale, bit_width)

    Define the computation performed at every call.

    Should be overridden by all subclasses. :rtype: `Tensor`

    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.

  get_zero_center(x)
    Return type:

      `Tensor`

class brevitas.core.zero_point.StatsFromParameterZeroPoint(int_quant, quantize_zero_point, zero_point_stats_input_view_shape_impl, zero_point_stats_input_concat_dim, zero_point_stats_impl, zero_point_shape, tracked_parameter_list)

  Bases: `Module`

  forward(x, scale, bit_width)

    Define the computation performed at every call.

    Should be overridden by all subclasses. :rtype: `Tensor`

    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.

class brevitas.core.zero_point.ZeroZeroPoint(dtype=None, device=None)

  Bases: `Module`

  forward(x, scale, bit_width)

    Define the computation performed at every call.

    Should be overridden by all subclasses. :rtype: `Tensor`

    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.

## Module contents