Repository navigation
Fix keep_in_fp32_modules not working for tied weights in load_and_quantize_model - #4043
Merged
Merged
Conversation
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Contributor
Author
|
Hi @SunMarc . Would you please review this PR? Thanks! |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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
MixedInt8LoaddedModelTest::test_fp32_8bit_conversionandBnb4BitTestLoadedModel::test_fp32_4bit_conversionfail with:When quantizing an already-loaded model (not on meta device), modules specified in
keep_in_fp32_modules(e.g.lm_head) are not correctly kept in fp32.Root Cause
In BLOOM,
lm_head.weightis tied totransformer.word_embeddings.weight(same Parameter object).model.named_parameters()deduplicates by parameter id and yields each parameter only once. Sincetransformer.word_embeddings.weightis encountered first in DFS traversal, it is the only one yielded — and the check"lm_head" in "transformer.word_embeddings.weight"isFalse, so the parameter stays in fp16.lm_head.weightis never iterated over.Fix
Add a second pass using
model.named_modules()to explicitly convert parameters ofkeep_in_fp32_modulesto fp32. This is not affected bynamed_parameters()deduplication since we access the module's parameters directly.