-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Fix bin state dict param #36580
base: main
Are you sure you want to change the base?
Fix bin state dict param #36580
Conversation
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. When it is ready for review, please click the |
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. |
if old_param is not None and old_param.is_contiguous(): | ||
param = param.contiguous() | ||
module_to_tp.load_state_dict({param_type: param}, strict=False, assign=True) | ||
|
||
else: | ||
param = param[:] | ||
if is_safetensors_shard: | ||
param = param[:] |
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.
Also can't slice 0-dim tensors. See CI from diffusers
with MusicLDM
and AudioLDM2
which use ClapModel
from transformers
. https://github.com/huggingface/diffusers/actions/runs/13714387592/job/38359634948?pr=10997
model = ClapModel(
(text_model): ClapTextModel(
(embeddings): ClapTextEmbeddings(
(word_embeddings): Embedding(100...eatures=16, bias=True)
(activation): ReLU()
(linear2): Linear(in_features=16, out_features=16, bias=True)
)
)
state_dict = {'audio_model.audio_encoder.batch_norm.bias': tensor(..., device='meta', size=(8,)), 'audio_model.audio_encoder.batch_...ice='meta', size=(8,)), 'audio_model.audio_encoder.batch_norm.running_var': tensor(..., device='meta', size=(8,)), ...}
...
> param = param[:]
E IndexError: slice() cannot be applied to a 0-dim tensor.
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.
did you launch the tests if this specific pr ?
For safetensors file, param is a PySlice object. This is why we need to do param = param[:]
param = file_pointer.get_slice(serialized_param_name)
What does this PR do?
This PR fixes a small issue when using bin format. We only need to slice when loading safetensors file, not bin file.
cc @DN6