Repository navigation
loader: do not restore an fp8 quantization_config over dequantized weights - #15364
Merged
Merged
Conversation
…ights With FineGrainedFP8Config(dequantize = True) and load_in_4bit left at its default, transformers drops the fp8 config and loads 16bit weights, but FastLanguageModel and FastModel then wrote the caller's config back. save_pretrained produced bf16 weights under quant_method fp8 with no scales, which transformers 4.57.6 cannot reload. Skip the restore when the load was dequantized.
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Problem
Loading a block FP8 checkpoint with
quantization_config = FineGrainedFP8Config(dequantize = True)and leavingload_in_4bitat its default goes through this sequence in bothFastLanguageModel.from_pretrainedandFastModel.from_pretrained:quantization_configfrom the model config._drop_fp8_dequantize_conversionsforgets the save time conversions and marks the model_unsloth_fp8_dequantized.load_in_4bitblock then writes the caller's config back withmodel.config.update({"quantization_config": quantization_config.to_dict()}).save_pretrainedtherefore writes only bf16 tensors, with noweight_scale_inv, underquant_method: fp8. transformers 4.57.6 ignoresdequantize, builds FP8 layers that expect scales, and the reload fails withNotImplementedError: Cannot copy out of meta tensor; no data!. A default config load is not affected, since #14803 already skips the bitsandbytes stamp for a dequantized load.Fix
Skip the explicit config restore when the model was marked
_unsloth_fp8_dequantized, in both loaders. The flag is only set when transformers dropped the fp8 config, so a kept FP8 load (sm89+ withoutdequantize) and every other user config are restored as before.Tests
tests/test_fp8_dequant_save_policy.py::test_caller_fp8_config_is_not_restored_over_dequantized_weights(CPU, both loaders): everymodel.config.update({"quantization_config": quantization_config...})infrom_pretrainedsits behind the dequantized guard. Fails on main, passes here.tests/test_fp8_16bit_text_loader_dequant.py::test_explicit_dequantize_config_saves_without_fp8_config(CUDA, both loaders): loads a tiny block FP8 Llama withFineGrainedFP8Config(dequantize = True), saves, and checks the saved config has noquantization_config, every tensor is 16bit (float16 on a T4, which has no bf16) with no scales, and a reload gives identical weights. On a Kaggle T4 (torch 2.11, transformers 5.17.0) it fails on main for both loaders, with the saved config stillquant_method: fp8, and passes here.quantization_configentry removed (the one difference this change makes), reloads bit identical under 4.57.6.The rest of both test files passes locally on transformers 5.17.0.
Not covered
The 4.57.6 reload was checked on CPU from a saved checkpoint, not by running the full Unsloth loader under 4.57.6 (whose
FineGrainedFP8Confighas nodequantize, so the explicit path does not arise there). The vision loader (FastBaseModel) does not restore a caller config at this point and is unchanged.