Skip to content

[BUG] GPTQ_TORCH eval decode bypasses the range-safe base decoder: BF16 linear returns NaN and embedding returns inf #5606

Closed

Description

@devin-ai-integration

At a54f05d, CPU, torch 2.15. Unlike #5577 (TorchFused/TorchAten), this is the ordinary TorchLinear eval path. No int4pack, warm-up, gradients or native extensions required.

import torch
from gptqmodel.nn_modules.qlinear.torch import TorchLinear, TorchQuantEmbeddings
from gptqmodel.quantization import FORMAT

for cls in [TorchLinear, TorchQuantEmbeddings]:
    m = cls(bits=4, group_size=32, sym=False, desc_act=False,
            in_features=32, out_features=32, bias=False, format=FORMAT.GPTQ_V2, compile=False)
    m.qweight.fill_(-1); m.qzeros.zero_(); m.scales.fill_(8192)
    m.post_init(); m.eval()
    if cls is TorchLinear:
        x = torch.zeros(1,32,dtype=torch.bfloat16); x[:,0] = .25
        print(m(x)[0,0]); m.train(); print(m(x)[0,0])
    else:
        m.set_embedding_output_dtype(torch.bfloat16)
        print(m(torch.tensor([0]))[0,0])

Expected: every decoded weight is (15-0)*8192 = 122880, exactly representable in BF16, so the linear output is 30720 and the embedding value is 122880. Actual: linear NaN in eval, 30720 in train; embedding inf. All inputs, codes, scales and expected outputs are finite. The train-mode result is a control using the same packed tensors.

_dequantize_weight_cached_248 multiplies in the stored FP16 scale dtype. Converting the resulting inf to BF16 is too late. The embedding row-gather also multiplies directly in the scale dtype. Use the base decoder's range-safe multiply in these paths and keep operands wide through reduction if decoded weights do not fit the activation dtype. Check the separate streaming/Triton paths before claiming parity there. Test train/eval against the independently computed BF16 result, plus both embedding lookup routes.

Activity

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

    @Qubitium
    Collaborator

    Agent claim: working on this — routing the GPTQ_TORCH eval decode through the range-safe base decoder so BF16 stays finite, with a NaN regression.

  3. Qubitium commented on Nov 20, 2026

    @Qubitium
    Collaborator

    Agent claim: released as done — the GPTQ_TORCH eval decode now uses the range-safe decoder, the embedding row gather is widened, and the regression covers BF16/FP16 linear plus both embedding routes.

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