-
Notifications
You must be signed in to change notification settings - Fork 6k
[bitsandbbytes] follow-ups #9730
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
14a44e5
bnb follow ups.
sayakpaul 065700c
add a warning when dtypes mismatch.
sayakpaul 9c3a952
fx-copies
sayakpaul e39544a
clear cache.
sayakpaul 23fdc7a
check_if_quantized_param
sayakpaul cb94414
add a check on shape.
sayakpaul 1fa9d7f
updates
sayakpaul 4c7ea4f
docs
sayakpaul 6dc8936
improve readability.
sayakpaul 3dbe41f
resources.
sayakpaul 8a99701
Merge branch 'main' into bnb-follow-up
sayakpaul 1af10a8
Merge branch 'main' into bnb-follow-up
sayakpaul 3298a04
fix
sayakpaul 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
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 |
---|---|---|
|
@@ -211,21 +211,28 @@ def load_model_dict_into_meta( | |
set_module_kwargs["dtype"] = dtype | ||
|
||
# bnb params are flattened. | ||
if not is_quant_method_bnb and empty_state_dict[param_name].shape != param.shape: | ||
model_name_or_path_str = f"{model_name_or_path} " if model_name_or_path is not None else "" | ||
raise ValueError( | ||
f"Cannot load {model_name_or_path_str}because {param_name} expected shape {empty_state_dict[param_name]}, but got {param.shape}. If you want to instead overwrite randomly initialized weights, please make sure to pass both `low_cpu_mem_usage=False` and `ignore_mismatched_sizes=True`. For more information, see also: https://github.com/huggingface/diffusers/issues/1619#issuecomment-1345604389 as an example." | ||
) | ||
if empty_state_dict[param_name].shape != param.shape: | ||
if ( | ||
is_quant_method_bnb | ||
and hf_quantizer.pre_quantized | ||
and hf_quantizer.check_if_quantized_param(model, param, param_name, state_dict, param_device=device) | ||
): | ||
hf_quantizer.check_quantized_param_shape(param_name, empty_state_dict[param_name].shape, param.shape) | ||
elif not is_quant_method_bnb: | ||
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. Could have done with |
||
model_name_or_path_str = f"{model_name_or_path} " if model_name_or_path is not None else "" | ||
raise ValueError( | ||
f"Cannot load {model_name_or_path_str} because {param_name} expected shape {empty_state_dict[param_name]}, but got {param.shape}. If you want to instead overwrite randomly initialized weights, please make sure to pass both `low_cpu_mem_usage=False` and `ignore_mismatched_sizes=True`. For more information, see also: https://github.com/huggingface/diffusers/issues/1619#issuecomment-1345604389 as an example." | ||
) | ||
|
||
if not is_quantized or ( | ||
not hf_quantizer.check_quantized_param(model, param, param_name, state_dict, param_device=device) | ||
if is_quantized and ( | ||
hf_quantizer.check_if_quantized_param(model, param, param_name, state_dict, param_device=device) | ||
): | ||
hf_quantizer.create_quantized_param(model, param, param_name, device, state_dict, unexpected_keys) | ||
else: | ||
if accepts_dtype: | ||
set_module_tensor_to_device(model, param_name, device, value=param, **set_module_kwargs) | ||
else: | ||
set_module_tensor_to_device(model, param_name, device, value=param) | ||
else: | ||
hf_quantizer.create_quantized_param(model, param, param_name, device, state_dict, unexpected_keys) | ||
|
||
return unexpected_keys | ||
|
||
|
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
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
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
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
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
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.
To unify the content between 8bit and 4bit hfoption.