Skip to content

[BUG] Follow-up on #3999/#4001: stale uniform-group flag after load_state_dict (M=2..64 wrong), TorchFused GPTQ still overflows, bias forces 7x (ExLlamaV2) and 2.6-21x (CPU) slower paths, AwqExLlamaV2+LoRA returns fp32 #4028

Closed

Description

@Qubitium

Follow-up review of the merged PRs #3999 (TritonV2 dispatch + pack-load small-M GEMM, for #3982), #4000 (per-call dispatch caching, for #3983) and #4001 (wide FP16 reductions, for #3977), at main @ 5f5eaad on an RTX 4090. Before/after trees were extracted with git archive (105602e, 2dc639e).

#4000: no defects found. The ExLlamaV2 handle fast path behaves identically before and after the PR for mul_, .data swap (including allocator pointer reuse), in-place writes to inference tensors, deepcopy, load_state_dict, .half() and .to(same). loaded_op, the identity guard and the _runtime_ok memo are correct. The AWQ GEMV fp16 bias add is equivalent to the wide add.

#3999: kernel numerics are clean. 14,400 checks against fp64 gave 0 failures, covering:

  • bits 2/3/4/8; gs 32/64/128/256/−1; sym/asym
  • permuted, cross-group, finer-than-group and negative-wrap g_idx
  • K tails 2080/4160, N 96/1056; M 1..64, 65, 128
  • fp16/bf16, bias, 3-D, non-contiguous and M=0 inputs

The autograd fallback in training / requires_grad works, LoRA is applied exactly once, and split-K is bitwise deterministic and equal to split_k=1.

1. #3999: _gptq_gemm_uniform_group goes stale after load_state_dict, so M=2..64 is silently wrong (medium-high)

gptqmodel/nn_modules/qlinear/torch.py:328-338 computes the flag once in post_init, and the gate at :474-478 uses it. Nothing recomputes it when g_idx changes. If a module whose g_idx was the identity mapping loads an act-order state_dict, the fused small-M GEMM keeps loading one scale/zero row per K-tile:

TorchLinear  after load_state_dict: g_idx equal to source: True, uniform flag still True
  M=1 rel err 2.66e-04 (GEMV gathers by g_idx, fine)   M=8 rel err 5.93e-01 vs fresh module 2.51e-04
TritonV2Linear
  M=1 rel err 3.27e-04                                  M=8 rel err 7.02e-01 vs fresh module 2.95e-04

Fix: recompute the flag in _load_from_state_dict / clear_weight_cache, or key it on tensor_cache_key(g_idx) and evaluate it lazily in the gate.

2. #4001: incomplete fix, GPTQ TorchFusedLinear (CPU/XPU) still overflows to inf before a cancelling bias (medium)

#3977 item 3 listed CPU TorchAten / TorchFused / TorchCpuAvx512 for both GPTQ and AWQ. #4001 fixed TorchAten, TorchAtenAwq and TorchFusedAwq, but nn_modules/qlinear/torch_fused.py:355-357 still does out.add_(self.bias) after the fp16 fused or dense product:

CPU, the #3977 repro (W=42, x=12.5, bias=-2000, fp16): TorchFusedLinear rows 1/4 (inference) and train mode -> [inf, inf, inf]; expected 65216 (TorchAten: 65216)

tests/test_inference_fp16_overflow.py has no TorchFused GPTQ case. Fix: use the same matmul_fp32_reduce(x, w, bias) for the dense branch, plus an fp32-bias epilogue (or the fp16-only gating from item 3) for the fused op.

3. #4001: CPU biased layers are forced off the fused int4 kernel, 2.6×–21× slower at M=1, BF16 included (high, perf)

These gates now send every biased layer, such as Qwen-style q/k/v, to full-weight dequant on every forward, even for BF16, which can't overflow there:

  • torch_aten_kernel.py:352-356 (and (self.bias is None or self._fused_op_handles_bias))
  • torch_aten_kernel_awq.py:264-266
  • torch_fused_awq.py:343-345

The linear_mode stays train permanently. Measured at K=N=4096, M=1, 4 threads (pre-#4001 → main, ms):

kernel BF16 FP16
TorchAten 20.8 → 55.0 18.9 → 194.6
TorchAtenAwq 7.1 → 48.0 12.3 → 152.3
TorchFusedAwq 7.3 → 30.1 9.6 → 204.0

Fix: gate only fp16 activations, or have the fused op return fp32 and add the bias before a single cast.

4. #4001: ExLlamaV2 and AwqExLlamaV2 with bias are ~7× slower at decode (high, perf)

exllamav2.py:299-310 and exllamav2_awq.py:245-251 upcast the activations to fp32 whenever a bias exists, so the extension's fp32 path runs. Measured at K=N=4096, fp16, best of 7 (pre-#4001 → main, µs; I re-ran the GPTQ rows):

kernel, bias M=1 M=16
ExLlamaV2 21.0 → 160.2 26.4 → 184.3
AwqExLlamaV2 23.3 → 162.6 26.3 → 183.1
either, no bias unchanged (~17–19) unchanged (~22–24)

The output is accurate. Fix: keep the fp16 kernel and request an fp32-output epilogue (bias added before rounding), or take the wide path only when the output can actually overflow.

5. #4001: AwqExLlamaV2 with bias plus LoRA returns float32 and permanently upcasts the LoRA weights (medium)

exllamav2_awq.py:250-276 passes the upcast fp32 x to self.adapter.apply(x=x, ...) after the output has been cast back. Lora.apply then converts lora_A / lora_B to fp32 in place, and out + update comes back as fp32:

LORA exl_awq out.dtype=torch.float32 ... lora_A.dtype=torch.float32   (every other kernel returns fp16)

Fix: pass the original-dtype x to the adapter, and apply the adapter before the final cast (or cast after it).

6. #4001: BitsAndBytes INT8 BF16 path ~2× slower at M=1 (medium, perf)

bitsandbytes.py:997-1021 now runs a Python fp32 row quantizer plus four fp32 elementwise ops instead of the fused int8_mm_dequant. At K=N=4096, BF16 M=1 went from 47.8 / 54.0 µs to 104.7 / 100.5 µs (two runs, noisy host), and FP16 M=16 from 37.6 to 57.6 µs. The new weight quantizer differs from native bnb on 1,378 of 16.7M codes (rounding); accuracy is unchanged. Fix: a fused Triton / compiled quant-plus-epilogue kernel, or keep the native path where it is provably safe (fp16 activations within range).

Tests

The PRs' own tests and related kernel suites: 356 passed, 150 skipped; test_inference_fp16_overflow.py 13 passed. Two more checks:

Plausible, not verified

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 14, 2026
  2. Qubitium commented on Nov 14, 2026

    @Qubitium
    CollaboratorAuthor

    Follow-up on #4032: TorchFused GPTQ with fp16 and a bias now always takes the dense path (7–17× slower at M=1). TorchAten fp16+bias and BnB INT8 bf16 are still on the slow paths. See #4051 item 3.

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

    bugperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions