Skip to content

[BUG] #5495 (fix of #5367) incomplete: FP16 grad forward still NaN after the CPU int4pack warm-up (runtime decode has no range-safe dtype) and on the GPTQ TorchFused/TorchAten fallbacks #5577

Closed

Description

@Qubitium

Found on main @ 8c71625, CPU only (torch 2.15.0).

What is wrong

#5495 (fix of #5367) made the AWQ CPU dense fallback decode in a range-safe dtype (AwqDecodeRangeMixin._decode_dtype_for_activation). That covers only the checkpoint-layout decode (awq_weight_dequantize). Two decodes with the same overflow are left:

  1. AWQ after the inference warm-up. Since fix(cpu): keep activation gradients in compiled fused forwards (#5369) #5499/fix(cpu): keep the int4pack runtime layout during eval-mode grad forwards (#5509) #5549, an eval-mode grad forward on a transformed layer decodes the live runtime layout with runtime_int4pack_dense_weight() (_cpu_int4pack_layout.py). That function computes scale * (code - 8) + offset in the FP16 runtime operands, with no range check. So the same layer that fix(awq): decode CPU dense fallbacks in a range-safe dtype #5495's test checks returns NaN once a no-grad forward has run first.
  2. GPTQ TorchFusedLinear / TorchAtenLinear. Their dense fallback (dequantize_weight() in the FP16 scale dtype) and the runtime decode overflow the same way, cold or warm. [BUG] TorchFusedAwqLinear's dequantization fallback returns NaN for a finite result #5367 was reported for AWQ only.

Repro

AWQ, the fixture from tests/test_inference_fp16_overflow.py (qweight=-1, qzeros=0, scales=8192; expected 0.25*15*8192 = 30720, finite in FP16):

import torch
from tests import test_inference_fp16_overflow as T
for name in ("TorchFusedAwqLinear", "TorchAtenAwqLinear"):
    m = T._awq_overflow_fixture(T._cpu_awq_class(name))
    x = torch.zeros(1, 32, dtype=torch.float16); x[0, 0] = 0.25
    with torch.no_grad(): print(name, "no-grad", m(x)[0, 0].item())      # warm-up
    xx = x.clone().requires_grad_(); print(name, "grad", m(xx)[0, 0].item())
TorchFusedAwqLinear no-grad 30720.0  grad nan
TorchAtenAwqLinear  no-grad 30720.0  grad nan

Without the warm-up, the grad forward returns 30720 (what the #5495 test checks). After the warm-up, an FP32 grad activation also returns 30720; only the FP16 runtime decode overflows.

GPTQ, the same numbers (qweight=-1, zero code 0, FP16 scales 8192, asym, g32, 32x16):

TorchFusedLinear {'cold_grad': nan, 'nograd': 30720.0, 'warm_grad': nan}
TorchAtenLinear  {'cold_grad': nan, 'nograd': 30720.0, 'warm_grad': nan}

Suggested fix

Have runtime_int4pack_dense_weight() decode in the dtype _decode_dtype_for_activation() returns: FP32 when the FP16 range does not fit, then the product accumulates wide as the #5495 path does. Apply the same mixin or decode-dtype check to the GPTQ int4pack kernels' dequantize_weight fallback.

Test that should have caught it

test_cpu_awq_fallback_decodes_overflowing_fp16_scale calls the grad forward on a fresh layer only. Add a no-grad warm-up before it, and parametrize over the GPTQ int4pack kernels.

Severity

Low. It needs a decoded weight above the FP16 range, the same contrived range as #5367. But the output is NaN, and the no-grad and grad forwards of the same layer disagree.

🤖 Generated with Claude Code

Activity

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

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-5577-int4pack-decode-dtype is working on this issue now.

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