quant_backends ¶
MLX block-scaled quantization backends (affine INT8, MXFP8/4, NVFP4).
Isolated experiment module: probes which mx.quantize modes the installed MLX build supports and exposes a thin wrapper around native quantized matmul. Depends only on mlx.core and the standard library — do not import the rest of FastVideo from here.
Classes¶
fastvideo.mlx_runtime.quant_backends.QuantBackend ¶
fastvideo.mlx_runtime.quant_backends.QuantizedWeight dataclass ¶
QuantizedWeight(weight: array, scales: array, biases: array | None, backend: str, mode: str, bits: int | None, group_size: int | None, orig_shape: tuple[int, int])
Packed quantized weight plus scales/biases for one backend.
Functions:¶
fastvideo.mlx_runtime.quant_backends.bytes_per_weight ¶
Measure the effective storage cost of a quantized weight.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend | str | Quantization backend to measure. | required |
Returns:
| Name | Type | Description |
|---|---|---|
float | float | Stored bytes per original weight element, including packed weights, scales, and optional biases. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the backend is unsupported. |
Source code in fastvideo/mlx_runtime/quant_backends.py
fastvideo.mlx_runtime.quant_backends.is_supported ¶
Return True if the installed MLX build can quantize/matmul with backend.
Source code in fastvideo/mlx_runtime/quant_backends.py
fastvideo.mlx_runtime.quant_backends.quantize_weight ¶
quantize_weight(w: array, backend: str) -> QuantizedWeight
Quantize a two-dimensional weight matrix using the specified native MLX backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w | array | The two-dimensional weight matrix to quantize. | required |
backend | str | The quantization backend to use. | required |
Returns:
| Name | Type | Description |
|---|---|---|
QuantizedWeight | QuantizedWeight | The quantized weights and associated quantization metadata. |
Raises:
| Type | Description |
|---|---|
ValueError | If the backend is unknown, the weight is not two-dimensional, or its last dimension is not divisible by the backend's group size. |
RuntimeError | If the backend is unsupported by the installed MLX build. |
Source code in fastvideo/mlx_runtime/quant_backends.py
fastvideo.mlx_runtime.quant_backends.quantized_matmul ¶
quantized_matmul(x: array, qw: QuantizedWeight) -> array
Compute x @ w.T in the quantized domain via mx.quantized_matmul.
Source code in fastvideo/mlx_runtime/quant_backends.py
fastvideo.mlx_runtime.quant_backends.support_error ¶
Check whether a quantization backend is supported by the current MLX runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend | str | Quantization backend name. | required |
Returns:
| Type | Description |
|---|---|
str | None | str | None: An error description when the backend is unsupported, or |