Skip to content

[BUG] MacaqLinear Torch path crashes after module.to(dtype) when it has a bias, and silently computes in the old dtype without one #4217

Closed

Description

@Qubitium

Severity: medium
Version: 7.11.0 @ 9dad249 (pre-dates #4163)

Summary

In nn_modules/qlinear/macaq.py, compute_dtype is fixed in __init__ (~L136). _forward_torch (~L295-309) casts the activation to it and calls F.linear(xb, weight, self.bias), while the bias buffer has already been moved to the new dtype by .to(). The Triton paths cast correctly.

Reproduce (CPU; CUDA uses the same code)

import torch
from gptqmodel.nn_modules.qlinear.macaq import MacaqLinear
m = MacaqLinear(bits=4, group_size=32, in_features=128, out_features=64, bias=True,
                activation_precision="w4a16", rotation="none", pre_mode="none", dtype=torch.bfloat16)
m.W_packed.random_(0, 255); m.W_scales.fill_(122); m.post_init(); m.eval()
m.to(torch.float16); m(torch.randn(3, 128).half())
# RuntimeError: self and mat2 must have the same dtype, but got Half and BFloat16
  • With bias: fails for all 8 combinations of precision × rotation × pre_mode.
  • Without bias: fp16 inputs are computed in bf16 (1.6e-2 absolute drift) and returned in the wrong precision.

Expected

Derive the compute dtype from the input (or from the module's current dtype at forward time), and return the input activation dtype.


Found during an AI-assisted review (Claude Code) of 9dad249; repros were run on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions