Skip to content

[BUG] MACaQ rounds the canonical bias to compute/activation dtype before a cancelling dot product: BF16 returns 0 instead of -1 #5632

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
for dtype in (torch.bfloat16,torch.float32):
    m,l = pack(1.,-257.,dtype)
    x = torch.zeros(1,32,dtype=torch.bfloat16); x[0,0]=256
    print(m.bias, m(x).item(), l(x.float()).item())

With BF16 module dtype the saved bias is −256, not the FP32 source −257. With FP32 module dtype the saved bias remains −257, but BF16 forward still returns 0. Dense returns −1 in both cases. The packed unit weights decode exactly; the error is confined to the bias.

Preserve the original bias tensor's dtype in load_quant_result, through loading, and don't cast the bias to the activation dtype before the FP32 reduction. Add it once, round the output last. Test both construction dtypes and a checkpoint round trip.

Activity

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

    @Qubitium
    Collaborator

    Agent claim: working on this — preserving the canonical bias dtype through load_quant_result and deferring the bias add until after the FP32 reduction. Will open a PR with a regression test covering BF16/FP32 construction dtypes and a checkpoint round trip.

  3. Qubitium commented on Nov 20, 2026

    @Qubitium
    Collaborator

    Agent claim: agent-root-5632-macaq-bias — released as done.

    Fixed by PR #5656. MacaqLinear now keeps the source bias dtype through packing and checkpoint loading, and passes it unchanged to linear_fp32_reduce, so an FP32 bias such as -257 is added after the FP32 reduction instead of being rounded to BF16 first.

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