Repository navigation
fix: compare FP8 checkpoints as dequantized in the tensor check - #39
Merged
Merged
Conversation
Since FP8 checkpoints such as tencent/Hy3-FP8 are loaded dequantized and exported unquantized (#38), the tensor check (#37) reported every FP8 weight "with another dtype" (F8_E4M3 -> BF16) and every scale as missing. For a tiny Hy3-FP8, that buried the one real difference, the 593 tensors of the MTP layer that Transformers doesn't load, under 5271 missing and 1756 dtype changes. When the source checkpoint's config.json says that its weights are stored in FP8 (read like the model loader does, at the same revision), the check now leaves out the scale tensors (weight_scale, weight_scale_inv, input_scale, activation_scale) and the dtype change of F8_* weights, and prints one line saying that the FP8 weights were compared as dequantized. Every other difference is still reported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Follow-up to #37 (tensor check) and #38 (FP8 loading).
Problem
Since #38, checkpoints whose
config.jsonhasquantization_config.quant_method == "fp8"(such astencent/Hy3-FP8) are loaded with their weights dequantized to the model's dtype and exported unquantized. The tensor check from #37 then compares the export with the FP8 source checkpoint and warns about every FP8 weight (F8_E4M3 -> BF16) and every scale tensor (missing). #38 intends both.On a tiny Hy3-FP8, built like
tencent/Hy3-FP8fromtiny-random/hy31ea1658 (with the builder from the #38 work), the merged export got:The one real difference is the 593 tensors of the MTP layer, which Transformers doesn't load. It was buried in those 5271 missing tensors, and even the example shown was a scale.
Change
check_tensors()reads the source'sconfig.jsonwithget_fp8_quantization_config(source_model, source_revision). That is the function and revision the model loader uses (Model._read_fp8_quantization_config).For an FP8 source, the new
dequantize_tensors()turns its tensor list into what the export should contain:weight_scale,weight_scale_inv,input_scale,activation_scale) are dropped;F8_*weight takes the dtype it was saved in.Then the regular comparison runs, so missing and added tensors, shape changes and other dtype changes are still reported.
One line says so:
* The FP8 weights of the source checkpoint are compared as dequantized, without their scales.docs/configuration.md: FP8 checkpoints are added to the causes in "Checking that the model is saved faithfully", together with the line Heretic prints for them. Hy3 is added to the models whose MTP layer isn't loaded, since that is what a Hy3-FP8 export still reports.The same export now gets:
That is exactly the report for the BF16
tiny-random/hy3export. The two exports have identical tensor headers (1781 tensors).Decisions
quant_method: "fp8", the format fix: load FP8 checkpoints such as Hy3-FP8 by dequantizing them #38 dequantizes. FP8 tensors in other formats (for examplecompressed-tensors) are not dequantized by Heretic, so they are still compared as stored. A test covers this.key_mappingalso renames them by name. If the export does contain a scale, it is reported as added.config.jsoncounts as not FP8, because Transformers returns an empty config for it. Every other failure to read the config is reported like a failure to read the tensors ("Could not compare ..."), and the save is never blocked.tiny-random/deepseek-v4names its scales.scale(F8_E8M0) and packs its FP4 experts as I8. Its merged save fails in Transformers 5.18 anyway (its tests export adapters), so the check never runs on it.Tests
Four new tests in
tests/test_tensor_check.py. The FP8 fixture has F8_E4M3 weights, scales under both naming schemes and aconfig.json:compressed-tensorssource is compared as stored;On master's
tensor_check.py, 3 of the 4 fail. The fourth checks the unchanged behavior.Verification
ruff format --check,ruff check --extend-select I,ty check --error-on-warning, the unit tests (206, 4 new) anduv buildpass locally.get_fp8_loading_kwargs,_weight_conversions = None), saved and checked. The before and after output is shown above.hereticitself on the tiny Hy3-FP8 (Abliteration, 2 trials,preflight_check = true, merged save). The preflight check and the check after saving both print the FP8 line and then593 missing (such as model.layers.4.eh_proj.weight). The run exits with code 0.404bcb7, both on this Windows PC. Both have the same 5 known local failures: deepseek-v4, deepseek-v4-ara, gemma-3, gemma-4e and qwen3.5-moe. 66 of the 69tests/*/model/*files are byte-identical between the two runs. The other 3 areadapter_config.jsonfiles that differ only in the order oftarget_modules. No test merges an FP8 model (the DeepSeek V4 tests export adapters), so none of them prints the new line.SHA256SUMSfile changed.🤖 Generated with Claude Code