compressed_tensors.quantization.quant_args
Classes:
-
ActivationOrdering–Enum storing strategies for activation ordering during GPTQ calibration
-
DynamicType–Enum storing potential dynamic types.
-
FP4_E2M1_DATA– -
QuantizationArgs–User facing arguments used to define a quantization config for weights or
-
QuantizationStrategy–Enum storing quantization strategy options
-
QuantizationType–Enum storing quantization type options
Functions:
-
round_to_quantized_type_args–Rounds an input tensor to the nearest quantized representation given
-
round_to_quantized_type_dtype–Rounds an input tensor to the nearest quantized representation given a dtype.
ActivationOrdering
Bases: Aliasable, str, Enum
Enum storing strategies for activation ordering during GPTQ calibration
Weight: Changes the way calibration occurs but doesn't change the quantization format compared to no activation ordering (normal latency). Compared to Group, it has lower latency and slightly worse accuracy. Compared to no activation ordering during calibration it has slightly better accuracy.
Static: alias for Weight
DynamicType
Bases: str, Enum
Enum storing potential dynamic types.
- If dynamic is True, all quantization parameters are generated on the fly.
- If dynamic is False, all quantization parameters generated are static.
- If "local" is provided, only local quantization parameters are dynamic.
Note: "local" requires the TENSOR_GROUP strategy, which currently only applies to NVFP4.
FP4_E2M1_DATA
Bases: FloatArgs
Methods:
-
cast_to_fp4–Round float values to the nearest E2M1 representable value.
cast_to_fp4
staticmethod
Round float values to the nearest E2M1 representable value.
Uses Triton for CUDA/XPU tensors when available, falls back to torch.compile for CPU tensors.
Parameters:
-
x(Tensor) –input tensor to quantize
Returns:
-
Tensor–input tensor after rounding to fp4 (maintains same dtype)
Source code in src/compressed_tensors/quantization/quant_args.py
QuantizationArgs
Bases: BaseModel
User facing arguments used to define a quantization config for weights or activations
Parameters:
-
num_bits–quantization bit depth
-
type–dtype to quantize to, either int or float
-
symmetric–whether or not quantization scale is symmetric about zero-point
-
strategy–string id determining the scope of scale/zero-point to apply
-
group_size–group length to use for the group strategy
-
block_structure–2d block structure to use for the block strategy; must be a list of two ints [rows, cols] like [128, 128].
-
dynamic–set True to perform dynamic quantization - values will not be calibrated during calibration phase, instead during inference new quantization ranges will be observed with every sample. Defaults to False for static quantization. Note that enabling dynamic quantization will change the default observer to a memoryless one
-
actorder–activation ordering strategy for GPTQ calibration. Options are GROUP (reorder by activation with g_idx mapping, higher accuracy but higher latency -- removed 2026/08/27), WEIGHT (reorder columns by activation magnitude during calibration only, normal latency with slight accuracy improvement) or None (no activation ordering).
QuantizationStrategy
Bases: str, Enum
Enum storing quantization strategy options
QuantizationType
Bases: str, Enum
Enum storing quantization type options
round_to_quantized_type_args
round_to_quantized_type_args(tensor: Tensor, args: QuantizationArgs, min: Tensor, max: Tensor, cast_to_original_dtype: bool = True) -> torch.Tensor
Rounds an input tensor to the nearest quantized representation given quantization args. The original dtype is kept post-rounding.
Parameters:
-
tensor(Tensor) –tensor to round
-
args(QuantizationArgs) –quantization args to use for rounding
-
min(Tensor) –min value to use for clamping
-
max(Tensor) –max value to use for clamping
-
cast_to_original_dtype(bool, default:True) –whether or not we cast the rounded tensor to the original dtype
Returns:
-
Tensor–rounded tensor
Source code in src/compressed_tensors/quantization/quant_args.py
round_to_quantized_type_dtype
round_to_quantized_type_dtype(tensor: Tensor, dtype: dtype, cast_to_original_dtype: bool = True) -> torch.Tensor
Rounds an input tensor to the nearest quantized representation given a dtype. The original dtype is kept post-rounding.
Parameters:
-
tensor(Tensor) –tensor to round
-
dtype(dtype) –dtype to use for rounding
-
cast_to_original_dtype(bool, default:True) –whether or not we cast the rounded tensor to the original dtype
Returns:
-
Tensor–rounded tensor