-
Notifications
You must be signed in to change notification settings - Fork 474
Fix HF PTQ empty-init dtype kwargs #1857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+104
−3
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
72ee53f
Fix HF PTQ empty-init dtype fallback
realAsma 7d0bebd
Simplify HF PTQ empty init dtype fix
realAsma 6cb2243
Fix HF PTQ real-load dtype kwarg
realAsma 2641497
Drop dtype from HF PTQ final load
realAsma 97bb15c
Scope HF PTQ dtype workaround to DeciLM
realAsma acb6e70
Fold HF PTQ dtype test cases
realAsma d768850
Reuse HF PTQ fake model config assertions
realAsma 22b37ac
Force DeciLM dtype fallback in HF PTQ test
realAsma 11bae59
Resolve HF PTQ PR merge conflict
realAsma 7462b8f
Merge remote-tracking branch 'origin/main' into beebot/pr1857-conflic…
realAsma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -731,14 +731,25 @@ def has_pack_quantized_config(config): | |
| auto_model_module = getattr(transformers, architecture) | ||
| from_config = auto_model_module._from_config | ||
|
|
||
| is_decilm = "DeciLM" in architecture | ||
| with init_empty_weights(include_buffers=True): | ||
| # When computing the device_map, assuming bfloat16 precision by default, | ||
| # unless specified by the hf_config. | ||
| torch_dtype = getattr(hf_config, "torch_dtype", torch.bfloat16) | ||
| config_dtype = ( | ||
| getattr(hf_config, "dtype", None) | ||
| or getattr(hf_config, "torch_dtype", None) | ||
| or torch.bfloat16 | ||
| ) | ||
| if isinstance(config_dtype, str): | ||
| config_dtype = getattr(torch, config_dtype) | ||
| model_kwargs2 = model_kwargs.copy() | ||
| if auto_model_module not in [AutoModelForCausalLM, AutoModel]: | ||
| model_kwargs2.pop("trust_remote_code", None) | ||
| model_kwargs2["dtype"] = torch_dtype | ||
| if is_decilm: | ||
| model_kwargs2["torch_dtype"] = config_dtype | ||
| model_kwargs2.pop("dtype", None) | ||
| else: | ||
| model_kwargs2["dtype"] = config_dtype | ||
| model_kwargs2.pop("max_memory", None) | ||
| model = from_config(hf_config, **model_kwargs2) | ||
|
|
||
|
|
@@ -760,10 +771,13 @@ def has_pack_quantized_config(config): | |
| ) | ||
| model_kwargs["max_memory"] = max_memory | ||
|
|
||
| model_kwargs2 = model_kwargs.copy() | ||
| if is_decilm: | ||
| model_kwargs2.pop("dtype", None) | ||
|
Comment on lines
+797
to
+799
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BB: can we use the same |
||
| model = auto_model_module.from_pretrained( | ||
| ckpt_path, | ||
| device_map=device_map, | ||
| **model_kwargs, | ||
| **model_kwargs2, | ||
| ) | ||
| model.eval() | ||
| if has_pack_quantized_config(hf_config): | ||
|
|
||
|
realAsma marked this conversation as resolved.
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make this a general WAR instead of DiciLM specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Wei-Ming. I agree this may be generalizable to other older remote-code models with the same Transformers 5+ incompatibility, but finding and validating those models would be a broader follow-up. For this PR, I would like to keep the fix scoped to the observed Llama Nemotron / DeciLM failure since broader remote-code fallback support is lower value and would need dedicated coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Wei-Ming. I agree this could probably be generalized to older remote-code models with the same constructor mismatch, but that would require identifying and validating the affected model set.
For this RC bug, I would keep the fix scoped to Llama Nemotron / DeciLM because that is the reported failure and the broader remote-code support case is lower value without dedicated coverage. I can follow up separately if we find more models with the same failure.