onnx_light.onnx_core.quantization#
See the quantization guide for the profile catalogue, parameter reference and numerical contracts, and the runnable Python tutorial for examples covering every profile.
The usual NumPy path is numpy_helper.from_array ->
quantize_tensor_proto -> EncodedValueProto ->
dequantize_tensor_proto -> numpy_helper.to_array.
Profiles define portable storage defaults, not calibration algorithms or
vendor-compatible binary formats.
The explicit ORT_MATMULNBITS_INT2/INT4/INT8 profiles are the exception:
make_matmul_nbits_plan and export_matmul_nbits_inputs produce the
standard ONNX Runtime operator inputs, not internal kernel prepacking.
The separate quantize_nvfp4_weights, export_nvfp4_weights and
import_nvfp4_weights APIs preserve a complete fixed-weight NVFP4 hierarchy
(FP8 local scales and a FLOAT32 global scale), unlike the portable nvfp4
profile. They do not implement activation-local dynamic scaling.
The MXFP6_E2M3 profile and quantize_mxfp6_e2m3_weights implement the
E2M3/group-32/E8M0 contract. The export/import
functions preserve packed weight and scale bytes. Legacy MXFP6 and
FP6_LLM remain E3M2 profiles.
The MXFP8 profile and quantize_mxfp8_weights implement the
complete E4M3FN/group-32/E8M0 contract with automatic
scales. export_mxfp8_weights and import_mxfp8_weights preserve the
native FP8 and E8M0 bytes; they do not provide accelerated matrix multiplication.
For model-level shared parameters,
add_quantization_parameters declares a fixed set and
quantize_tensor_shared returns a resource-retaining SharedQuantizedValue.
materialize_quantized_value exports a self-contained message when the
declaring model will not accompany the encoded value.
For explicitly pinned compressed-tensors checkpoint interoperability, see the support matrix and adapter boundary.
Exposes the unified quantization catalogue and self-describing quantized values.
Portable profiles describe onnx-light representations, not vendor binary layouts. Separate MXFP4 and NVFP4 weight codecs implement E8M0 and FP8 scale contracts. The MXFP8 profile implements E4M3FN values with automatic group-32 E8M0 scales. MXFP6_E2M3 implements compressed-tensors E2M3/group-32/E8M0; MXFP6 remains E3M2. NVFP4 also preserves its FLOAT32 global scale. Q4_0, Q8_0, Q4_K, Q5_K and Q6_K use exact native GGML blocks, imported through onnx_light.onnx_core.gguf and decoded by the standard dequantization APIs. Q2_K, Q3_K, IQ4_NL, IQ1_S, TQ1_0 and TQ2_0 also use their native GGML layouts. Native GPTQModel EXL3 checkpoints use onnx_light.onnx_core.exl3, not the affine EXL3 profile. Native bitsandbytes checkpoints use onnx_light.onnx_core.bitsandbytes, not portable NF4. Codecs without a GGUF counterpart keep their existing representations. ORT_MATMULNBITS_INT2/INT4/INT8 produce ONNX Runtime operator inputs, not internal kernel prepacking. No profile performs calibration. See Quantizes tensors into encoded values.
- class onnx_light.onnx_core.quantization.QuantizationFormat(*values)#
- class onnx_light.onnx_core.quantization.QuantizationMethod(*values)#
- class onnx_light.onnx_core.quantization.Shape(*args, **kwargs)#
A concrete runtime shape with at most 16 integer dimensions. An empty shape represents a scalar.
- onnx_light.onnx_core.quantization.add_quantization_parameters(model, name, storage_type, logical_type, *, scales, zero_points=None, offsets=None, codebooks=None, permutation=None, forward=None, inverse=None, outliers=None)#
Adds a fixed numerical parameter set backed by root graph initializers.
Numerical arguments accept TensorProto or NumPy arrays. Descriptors and tensors are copied; the model is changed only after successful validation. :returns: The compact StructTypeProto used by encoded values referring to this set.