Skip to content

[BUG] MLX QQQ still narrows FP32 activations to FP16 before dynamic quantization (|x|>65504 -> NaN row; residual of #4221) #4537

Closed

Description

@devin-ai-integration

Residual of #4221 (fixed in #4264 / c45c1b0). That fix kept BF16 activations wide in MlxQQQLinear, but deliberately kept narrowing FP32 activations to FP16 before the dynamic quantizer. FP32 hits the same overflow #4221 described for BF16.

Where

gptqmodel/nn_modules/qlinear/mlx_qqq.py

  • _quantization_dtype() returns dtype if dtype == mx.bfloat16 else mx.float16, so an mx.float32 input becomes mx.float16.
  • MlxQQQLinear.__call__ runs x = x.astype(_quantization_dtype(x.dtype)) before _dynamic_quant(x).
  • _finalize_kernel explicitly supports an mx.float32 output (("fp32", "float")), so FP32 activations are a supported input.

The function's own docstring says the Metal quantizer reads every element as FP32 (float(x[...])) and does not need an FP16 operand. Narrowing an FP32 input to FP16 only loses range and precision.

Failure

With an FP32 activation where |x| > 65504, astype(float16) produces inf. The kernel then computes row max = inf, scale = inf/127 = inf and x/scale = inf/inf = NaN, so the whole output row is NaN. This is the failure #4221 fixed for BF16. Finite FP32 inputs below that range also lose 13 mantissa bits before the per-token scale is computed.

tests/test_mlx_qqq_dtype_decision_4221.py pins this behaviour (assert module._quantization_dtype(mx.float32) is mx.float16, commented as "historical"). Passing tests therefore do not show the path is correct.

Expected

The quantizer operand keeps the activation's range: FP32 and BF16 stay as they are, and only FP16 inputs use FP16. In practice, return dtype for mx.float32 too (or always pass the input unchanged, since the kernel reads elements as float). Update the dtype-decision test to assert FP32 stays FP32 and add an FP32 |x| > 65504 case to the Apple-device checks.

Related

#4534 covers the separate FP16 narrowing in the output epilogue (half value = ... in _finalize_kernel and the M>=2 Python epilogue). This issue covers only the input operand cast. The two need separate fixes.

Validation note

Found by static audit of the source. There is no MLX/Metal runtime on the Linux audit host, so this was not run on Apple hardware. The inf -> NaN chain follows from the IEEE FP16 range and the kernel source shown above.

Activity

  1. added
    bug
    on Nov 17, 2026
  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    Collaborator

    Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions