Repository navigation
fix(fp8): keep the in-session bias FP32 so it matches a reload (#4575) - #4613
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4575
Root cause
TorchFP8Linear.__init__(the reload path) allocates the bias as FP32, and the loader keeps FP8 biases inkeep_in_fp32_modules/fp32_bf16_buffer_names, so every reloaded model has an FP32 bias for both fp16 and bf16 loads. The pack path used byquantize()kept the source model dtype (bias = linear.bias.detach().to("cpu"))._forward_dequant_matmulthen chooses its GEMM path frombias.dtype != x_flat.dtype: a model-dtype bias takes the narrow dequant +matmul_fp32_reducepath, an FP32 bias takes the full-FP32 dequant/matmul path. Same weights, different arithmetic, so in-session logits did not reproduce the checkpoint.Fix
Both
TorchFP8Linear.pack_originalandpack_calibratednow cast the bias to FP32. This preserves the documented reload behaviour (FP32 bias buffers, full checkpoint bias range) and makes the in-session module the same module a reload builds. No forward-path branch was changed, so the range-safety bound from #4533/#4545 is untouched.Before / after (tiny Qwen2, bf16,
TorchFP8Linear, accelerator)bf16, reload biasfloat32; in-session vs reloaded logits max |ΔL| = 0.00537109375 (mean 1.03e-3). Narrowing the reloaded biases to bf16 reproduces the in-session logits exactly (Δ = 0.0), confirming the dtype is the whole difference.*.biasasfloat32, and narrowing only the reloaded bias to bf16 reintroduces Δ = 0.00537109375.Tests
Thread caps on every run:
OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 OPENBLAS_NUM_THREADS=4 NUMEXPR_NUM_THREADS=4.RTX 4090 (
CUDA_VISIBLE_DEVICES=GPU-50a20676-a7a4-8bb3-eb3d-f191fdc9fa42), CUDA venv/opt/venvs/cu130t:pytest tests/test_fp8_bias_dtype_4575.py -q-> 3 failed (assert torch.bfloat16 == torch.float32,assert torch.float16 == torch.float32, and the end-to-end bias-dtype/logits check)pytest tests/test_fp8_bias_range.py tests/test_portable_wide_epilogues_4471.py -q-> 28 passed (required range-safety coverage from fix(numerics): keep portable Torch reductions and bias epilogues wide (#4471) #4533/[PERF] FP8 bias-free forward now always dequantizes to FP32 and runs an FP32 GEMM on CUDA (#4533 regression): 2.1x prefill, -15% decode #4545)pytest tests/test_fp8_bias_dtype_4575.py tests/test_fp8_bias_range.py tests/test_portable_wide_epilogues_4471.py tests/test_offload_quantized_modules_restored_4450.py tests/test_fp8.py tests/test_fp8_bf16_scale_reload.py -q-> 56 passedAMD R9700 (
HIP_VISIBLE_DEVICES=3only), ROCm venv/opt/venvs/rocm101t:pytest tests/test_fp8_bias_dtype_4575.py tests/test_fp8_bias_range.py tests/test_portable_wide_epilogues_4471.py -q-> 29 passed, 2 skippedThe regression test includes an independent FP64 oracle for the packed module output (
rtol=atol=2e-3); the in-session vs reload assertion is exact (rtol=0, atol=0).Lint gate:
ruff check gptqmodel docs/eora tests setup.py->All checks passed!Limitations
TorchFP8Linearpack/save/load path on an accelerator.