Repository navigation
Description
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-266torch_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:
test_awq_gemv/test_awq_gemv_fastmodel tests fail because a bf16 model is loaded into the fp16-only GEMV kernel. Neither PR touches this.test_q4_torch_fusedalso times out on the pre-fix(qlinear): keep FP16 reductions wide and stop BF16-through-FP16 quantization (#3977) #4001 tree, so it isn't a regression.
Plausible, not verified
- perf(triton): fuse TritonV2 dispatch and pack-load small-M GEMM (#3982) #3999 small shapes: TritonV2 at M ≥ 2 may have gained launch overhead on small shapes (K2048×N512 and K8192×N128: ~44 → 62 µs, loaded host). Big shapes are much faster (K4096×N14336, M=2: 280 → 62 µs).
- perf(triton): fuse TritonV2 dispatch and pack-load small-M GEMM (#3982) #3999 Blackwell:
is_cuda_fusedenables the fused path for all of sm_100–sm_121 without a measurement there. - fix(qlinear): keep FP16 reductions wide and stop BF16-through-FP16 quantization (#3977) #4001 AwqGEMM: with bias it now always takes the fp32-reduce path, maybe ~30% slower at M=1 (23 → 30 µs, noisy).
- fix(qlinear): keep FP16 reductions wide and stop BF16-through-FP16 quantization (#3977) #4001 Marlin NVFP4: the global scale (kFE2M1f) was dead code and is now applied. No Python caller reaches it today.
🤖 Generated with Claude Code
Activity
fix(qlinear): refresh fused dispatch and bias epilogues (#4028) (#4032)
Qubitium commentedon Nov 14, 2026
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.