Skip to main content

QuantizationGridScenario

Optimization scenarios · Implementation: mlsysim/engine/scenario_definitions/optimization.py.

Construct this scenario with keyword inputs. The fields below show the types and defaults declared by this class.

Values stored on a bits-bit integer grid over a clipping range.

Affine (symmetric=False): s = (beta - alpha) / (2^b - 1) and a zero-point z = qmin + round(-alpha / s); codes run 0 to 2^b - 1, or -2^(b-1) to 2^(b-1) - 1 when signed. Symmetric: s = max(|alpha|, |beta|) / (2^(b-1) - 1), z = 0, codes +-(2^(b-1) - 1). alpha and beta default to the values’ minimum and maximum (min-max calibration). Rounding is to nearest, ties to even.

Notes

Equation: The calculation members below define lo, hi, steps, qmin, qmax, scale, zero_point_exact, zero_point, codes, readback, errors, max_rounding_error.

Assumptions: All input values share a finite clipping range and one integer grid; the scale is positive.

Excludes: Learned per-channel scales and accuracy effects beyond reconstruction error.

References

Derivation: Values stored on a bits-bit integer grid over a clipping range. Each member records the corresponding algebra or named physics function.

Examples

Evaluate the named configuration and display a modeled result.

>>> from mlsysim import Scenarios
>>> case = Scenarios.Uint8RangeMinusOneToThree
>>> value = case.max_rounding_error
>>> print(f"{value:.3g}")
0.00784

Attributes

Name Description
alpha
beta
bits
codes Quantized integer codes, clipped to the chosen code range by calc_quantize.
errors Absolute reconstruction error per input, in the same units as the input values.
hi Upper clipping endpoint, explicit beta or the maximum input value.
lo Lower clipping endpoint, explicit alpha or the minimum input value.
max_rounding_error Half a grid step in input units; excludes clipping error outside the supported range.
qmax Maximum integer code under signed, unsigned, or symmetric mode.
qmin Minimum integer code under signed, unsigned, or symmetric mode.
readback Reconstructed input-unit values from codes via calc_dequantize.
scale Value-space step per integer code, via affine or symmetric scale helpers.
signed
steps Number of affine intervals, one fewer than the number of integer codes.
symmetric
values
zero_point Integer code offset used to represent zero, via calc_zero_point.
zero_point_exact Unrounded zero-point displacement, or zero for a symmetric grid.

values

Type: List[float].

Declared default: [].

bits

Type: int.

Declared default: required.

alpha

Type: Optional[float].

Declared default: None.

beta

Type: Optional[float].

Declared default: None.

symmetric

Type: bool.

Declared default: False.

signed

Type: bool.

Declared default: False.

lo

engine.scenario_types.QuantizationGridScenario.lo

Lower clipping endpoint, explicit alpha or the minimum input value.

Equation: min(values) if alpha is None else alpha.

hi

engine.scenario_types.QuantizationGridScenario.hi

Upper clipping endpoint, explicit beta or the maximum input value.

Equation: max(values) if beta is None else beta.

steps

engine.scenario_types.QuantizationGridScenario.steps

Number of affine intervals, one fewer than the number of integer codes.

Steps across the range of an affine grid, 2^b - 1.

Calculation: mlsysim.physics.numerics.calc_int_levels.

qmin

engine.scenario_types.QuantizationGridScenario.qmin

Minimum integer code under signed, unsigned, or symmetric mode.

Calculation: mlsysim.physics.numerics.calc_int_max.

qmax

engine.scenario_types.QuantizationGridScenario.qmax

Maximum integer code under signed, unsigned, or symmetric mode.

Calculation: mlsysim.physics.numerics.calc_int_max.

scale

engine.scenario_types.QuantizationGridScenario.scale

Value-space step per integer code, via affine or symmetric scale helpers.

Calculation: mlsysim.physics.numerics.calc_affine_scale, mlsysim.physics.numerics.calc_symmetric_scale.

zero_point_exact

engine.scenario_types.QuantizationGridScenario.zero_point_exact

Unrounded zero-point displacement, or zero for a symmetric grid.

-alpha / s, before rounding (0 for a symmetric grid).

Calculation: mlsysim.physics.numerics.calc_zero_point.

zero_point

engine.scenario_types.QuantizationGridScenario.zero_point

Integer code offset used to represent zero, via calc_zero_point.

Calculation: mlsysim.physics.numerics.calc_zero_point.

codes

engine.scenario_types.QuantizationGridScenario.codes

Quantized integer codes, clipped to the chosen code range by calc_quantize.

Calculation: mlsysim.physics.numerics.calc_quantize.

readback

engine.scenario_types.QuantizationGridScenario.readback

Reconstructed input-unit values from codes via calc_dequantize.

Calculation: mlsysim.physics.numerics.calc_dequantize.

errors

engine.scenario_types.QuantizationGridScenario.errors

Absolute reconstruction error per input, in the same units as the input values.

Absolute error of each value after the round trip.

Equation: [abs(r - x) for r, x in zip(readback, values)].

max_rounding_error

engine.scenario_types.QuantizationGridScenario.max_rounding_error

Half a grid step in input units; excludes clipping error outside the supported range.

Largest error inside the range: half a step.

Equation: scale / 2.

Back to top