Fix TypeError when loading float8 models by falling back to bfloat16 in local_torch_dtype#44596
Closed
Desel72 wants to merge 1 commit into
Closed
Fix TypeError when loading float8 models by falling back to bfloat16 in local_torch_dtype#44596Desel72 wants to merge 1 commit into
Desel72 wants to merge 1 commit into
Conversation
…in local_torch_dtype
Author
|
Hi @Rocketknight1 |
Member
|
We're trying to avoid pure code agent PRs right now and working on formalizing a policy against them. The main reason is simply that we're able to run our own code agents if we need to - users running them on random issues just adds a useless middleman. |
Author
|
Thanks for your reply. Is there a any way to become a merged PR? |
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.
Fix TypeError when loading float8 models by falling back to bfloat16 in local_torch_dtype
What does this PR do?
When loading FP8 models (e.g.
Qwen/Qwen3.5-35B-A3B-FP8) withdtype="auto", the auto-detected dtype from checkpoint weights can betorch.float8_e4m3fn. This dtype flows tolocal_torch_dtype()which callstorch.set_default_dtype(), but PyTorch does not support float8 types as default dtype, causing:TypeError: couldn't find storage object Float8_e4m3fnStorage
This happens when:
dtypeset (common with composite models wheredtypeis only in a sub-config)_get_dtype()auto-detectstorch.float8_e4m3fnfrom the checkpoint weightsFineGrainedFP8HfQuantizerdoesn't overrideupdate_dtype(), so it can't intercept thisThis PR adds a check in
local_torch_dtype()to fall back totorch.bfloat16when a float8 dtype is encountered. This only affects model skeleton initialization (set_default_dtype); actual float8 weights are still loaded correctly downstream via_load_pretrained_model.Also adds a unit test to verify the fallback behavior for both
float8_e4m3fnandfloat8_e5m2.Fixes #44589
Before submitting
Pull Request section?
to it if that's the case. TypeError: couldn't find storage object Float8_e4m3fnStorage #44589
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@Cyrilvallez (model loading / from_pretrained)
@SunMarc (quantization)