Skip to content

[BUG] TorchFusedAwqLinear's dequantization fallback returns NaN for a finite result #5367

Closed

Description

@Qubitium

Describe the bug

On CPU, the AWQ fused kernel's differentiable fallback dequantizes packed weights using FP16 scales before casting them to the activation dtype. A finite decoded coefficient can overflow at that step, causing a NaN even when the expected output is representable in FP16.

To reproduce

Reproduced at 72cef9bac on CPU with PyTorch 2.15.0+cu132.

import torch
from gptqmodel.nn_modules.qlinear.torch_fused_awq import TorchFusedAwqLinear

layer = TorchFusedAwqLinear(
    bits=4, group_size=32, in_features=32, out_features=16,
    sym=False, desc_act=False, register_buffers=True,
).eval()
with torch.no_grad():
    layer.qweight.fill_(-1)
    layer.qzeros.zero_()
    layer.scales.fill_(8192)
x = torch.zeros(1, 32, dtype=torch.float32)
x[0, 0] = 0.25
x.requires_grad_()
print(layer(x)[0, 0].item())

The result is NaN. The scalar reference is 0.25 * (15 - 0) * 8192 == 30720, which the portable AwqTorchLinear gives for the same data. The fallback also returns NaN with an FP16 input.

Additional context

awq_weight_dequantize() decodes using self.scales and casts the result afterwards. Decode, fallback matmul.

Suggested mitigation

The fallback in gptqmodel/nn_modules/qlinear/torch_fused_awq.py could reuse the portable AWQ range-aware multiplication, or decode and accumulate in a wider dtype before the final output cast. A dense weight used for fallback can stay local to that forward.

The existing fixture can compare FP16 and FP32 activation outputs against the independent result 30720 and check an input gradient. When the portable backend is available, AWQ_TORCH avoids the observed fused fallback.

Activity

  1. added
    bug
    on Nov 19, 2026
  2. ZX-ModelCloud commented on Nov 19, 2026

    @ZX-ModelCloud
    Collaborator

    Agent claim released: agent-d5b6d2ed133a finished this issue.

    Pull request: #5495

    Reproducing the TorchFusedAwqLinear FP16 fallback NaN on current main

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