Repository navigation
Description
Found on main @ 4b65923, RTX 5090 (sm_120), torch 2.15.
What is wrong
For FP8 modules that have a bias (for example every Qwen2 q/k/v projection), the in-session model returned by quantize() and the same checkpoint reloaded from disk run different arithmetic. The difference is fully explained by the dtype of the bias buffer:
TorchFP8Linear.__init__(gptqmodel/nn_modules/qlinear/fp8.py:~338-345, used on load) allocates the bias as FP32 ("Preserve the full checkpoint bias range"). The loader also lists FP8 biases inkeep_in_fp32_modules/fp32_bf16_buffer_names(gptqmodel/models/loader.py:3349-3362). A reloaded model therefore has an FP32 bias, for both fp16 and bf16 loads.- The pack path that builds the in-session module (
fp8.py:463-468) doesbias = linear.bias.detach().to("cpu")and keeps the model dtype (fp16/bf16). The checkpoint is then written with a BF16/FP16 bias (72biastensors stored asBF16in a bf16 run). _forward_dequant_matmul(fp8.py:694-717) chooses its path frombias.dtype != x_flat.dtype. With an FP32 bias (reload), it takes the full-FP32 dequant and matmul path. With a model-dtype bias (in-session), it dequantizes to fp16/bf16 and callsmatmul_fp32_reduce.
Result: evaluating right after quantize() reports different logits and PPL than the published checkpoint gives.
Repro (Qwen2.5-0.5B-Instruct, FP8Config(), 8 C4 samples, 256-token wikitext-2 window; both sides use TorchFP8Linear)
m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", FP8Config(), dtype=torch.bfloat16)
m.quantize(calib); m.model.to("cuda:0")
L0 = m.model(ids).logits # in-session
m.save(out); q = GPTQModel.load(out, dtype=torch.bfloat16)
L1 = q.model(ids).logits # reloaded
# compare all params/buffers, then narrow the reloaded biases back to the model dtype:
for mod in q.model.modules():
if hasattr(mod, "QUANT_TYPE") and mod.bias is not None: mod._buffers["bias"] = mod.bias.to(torch.bfloat16)
L2 = q.model(ids).logits| dtype | state_dict differences in-session vs reload | NLL in-session | NLL reload | max |ΔL| | max |ΔL| after narrowing reload bias |
|---|---|---|---|---|---|
| bf16 (offload on) | 72, all *.bias: bf16 vs float32 |
2.890619 | 2.892311 | 0.703 | 0.0 |
| bf16 (offload off) | same 72 | 2.890619 | 2.892311 | 0.703 | 0.0 |
| fp16 | same 72 (fp16 vs float32) | 2.890066 | 2.889560 | 0.0786 | 0.0 |
Every other buffer, including the FP8 codes and weight_scale_inv, is bit-identical. GGUF has the same bias dtype split, but GGUFTorchLinear adds the bias in FP32 either way, so its logits are identical (checked with BACKEND.GGUF_TORCH).
Suggested fix
Make the pack path produce the same module the loader builds. One option is to store the in-session bias as FP32 in TorchFP8Linear.pack*, which matches __init__ and the loader's keep_in_fp32_modules and needs the writer to keep the checkpoint dtype. Another is to make _forward_dequant_matmul choose its path independently of the bias buffer's dtype. The dtype of a buffer should not silently select a different GEMM precision; #4545 is about the same branch.
Test that should have caught it
tests/test_offload_quantized_modules_restored_4450.py compares in-session vs reload only on bias-free models. Its FP8 CPU NLL rows match because the CPU branch always takes the FP32 path. An FP8 Qwen2 (biased q/k/v) case on CUDA comparing in-session vs reloaded logits with TorchFP8Linear on both sides would catch it.
Severity
Low. The accuracy impact is about 0.06% NLL, but in-session evaluation of FP8 models with biases does not reproduce the shipped checkpoint, and the two disagree on argmax for some tokens (16/17 agree on a short prompt).
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow.
fix(fp8): keep the in-session bias FP32 so it matches a reload (#4575) (