Skip to content

Commit 5f6d1aa

Browse files
authored
Enable 5-bit support on MLX (pytorch#20811)
1 parent 804f709 commit 5f6d1aa

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

backends/mlx/builder/op_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,10 @@ def parse_dequant_node(
669669
return None
670670

671671
# MLX supports 2,3,4,5,6,8-bit affine quantization. to_mlx_qparams packs
672-
# 2/4/8 via fast paths and other widths (e.g. 6) via a general contiguous
673-
# bit-packer, so enable 6 here too.
672+
# 2/4/8 via fast paths and other widths (e.g. 5, 6) via a general
673+
# contiguous bit-packer, so enable 5 and 6 here too.
674674
bits = (qmax - qmin + 1).bit_length() - 1
675-
if bits not in [2, 4, 6, 8]:
675+
if bits not in [2, 4, 5, 6, 8]:
676676
return None
677677
return qdata, scale, zero_point, group_size, bits, out_dtype, quantized_dim
678678

examples/models/gemma4_31b/quant/quantize.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"""Quantize weights to torchao tensor subclasses.
88
99
``quantize_weight`` quantizes a single tensor given a ``QuantConfig``,
10-
returning an ``Int4Tensor`` (4-bit) or ``IntxUnpackedToInt8Tensor`` (6- or
11-
8-bit).
10+
returning an ``Int4Tensor`` (4-bit) or ``IntxUnpackedToInt8Tensor`` (5-, 6-,
11+
or 8-bit).
1212
1313
``quantize_model`` walks a model's parameters, applies a ``QuantRecipe``,
1414
and returns a single state dict containing both quantized subclass tensors
@@ -152,7 +152,7 @@ def _to_intx_tensor(
152152
weight: torch.Tensor,
153153
config: QuantConfig,
154154
) -> torch.Tensor:
155-
"""Quantize to 6- or 8-bit and wrap in IntxUnpackedToInt8Tensor.
155+
"""Quantize to 5-, 6-, or 8-bit and wrap in IntxUnpackedToInt8Tensor.
156156
157157
Quantizes in float32 for numerical precision, then constructs the
158158
subclass directly. We avoid ``from_hp`` because it quantizes in the
@@ -229,10 +229,10 @@ def _to_intx_tensor(
229229
def quantize_weight(weight: torch.Tensor, config: QuantConfig) -> torch.Tensor:
230230
"""Quantize ``weight`` to a torchao tensor subclass.
231231
232-
Returns ``Int4Tensor`` for 4-bit or ``IntxUnpackedToInt8Tensor`` for 6-
233-
and 8-bit.
232+
Returns ``Int4Tensor`` for 4-bit or ``IntxUnpackedToInt8Tensor`` for 5-,
233+
6-, and 8-bit.
234234
"""
235-
if config.bits in (6, 8):
235+
if config.bits in (5, 6, 8):
236236
return _to_intx_tensor(weight, config)
237237

238238
if config.bits != 4:

0 commit comments

Comments
 (0)