Skip to content

[BUG] MACaQ W4A16 Torch narrows finite MXFP4 weights before the dot: a bias-free FP16 output is NaN instead of 16384 #5631

Closed

Description

@devin-ai-integration

Reproduced with Torch 2.15 CPU at 751f33fd; no accelerated kernel was tested.

import torch
from gptqmodel.quantization.macaq import macaq_quantize_weight
from gptqmodel.nn_modules.qlinear.macaq import MacaqLinear
def pack(w, bias, dtype):
    l = torch.nn.Linear(32,1,bias=bias is not None)
    l.weight.data.fill_(w)
    if bias is not None: l.bias.data.fill_(bias)
    r = macaq_quantize_weight(l.weight.detach(),torch.eye(32),32,rotation="none",
                             pre_mode="none",do_flip=False,exp_screen=False)
    m = MacaqLinear(bits=4,group_size=32,in_features=32,out_features=1,rotation="none",
                    pre_mode="none",activation_precision="w4a16",dtype=dtype,bias=bias is not None)
    m.pack(l,macaq_result=r)
    return m,l
m,l = pack(65536.,None,torch.float16)
x = torch.zeros(1,32,dtype=torch.float16); x[0,0]=0.25
print(m.dequantize(dtype=torch.float32)[0,0], m(x), l(x.float()))

Stored MXFP4 decodes exactly to 65536 in FP32. Expected output is 16384, exactly representable in FP16. Torch forward produces NaN: narrowing the weights makes them infinite, so the zero lanes contribute 0*inf. No bias, rotation, activation quantization or out-of-range output is involved.

_forward_torch asks for dequantize(dtype=x.dtype) before the wide reduction. Decode temporary operands in FP32 when activation precision cannot cover the packed range, widen the input for the dot, then round once. A range check should also consider underflow. No persistent dense cache is needed.

Activity

  1. added
    scanned
    safe
    on Nov 20, 2026
  2. Qubitium commented on Nov 20, 2026

    @Qubitium
    Collaborator

    Agent claim: working on this — keeping finite MXFP4 weights wide through the W4A16 Torch dot, with a finite-output regression.

  3. Qubitium commented on Nov 20, 2026

    @Qubitium
    Collaborator

    Agent claim: released as done. Fixed in #5667: the MACaQ W4A16 Torch fallback now decodes the packed weight in FP32 when the E8M0 scale range cannot be represented in the activation dtype, widens the dot's activation operand, and rounds once; the narrow path is unchanged when the range fits. The new regression covers the FP16 overflow (NaN before the fix), the underflow direction, the unchanged narrow path, BF16, and a state-dict reload.

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

    safescanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions