Skip to content

Conversation

@SunMarc
Copy link
Member

@SunMarc SunMarc commented Mar 6, 2025

What does this PR do?

This PR fixes a slicing issue that we have with 0-dim tensors (both with param from bin file and safetensors pyslice). We can do [:] but [...] works instead. Thx fxmarty-amd for finding this solution.

cc @DN6

@github-actions github-actions bot marked this pull request as draft March 6, 2025 09:27
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2025

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 Ready for review button (at the bottom of the PR page).

@SunMarc SunMarc marked this pull request as ready for review March 6, 2025 09:29
@HuggingFaceDocBuilderDev

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.

else:
param = param[:]
if is_safetensors_shard:
param = param[:]
Copy link
Contributor

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.

Copy link
Member Author

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay it's the same as here #36372 (comment)

@SunMarc SunMarc changed the title Fix bin state dict param Fix slicing for 0-dim param Mar 11, 2025
SunMarc and others added 4 commits March 11, 2025 15:56
Co-authored-by: fxmarty-amd <fxmarty-amd@users.noreply.github.com>
Co-authored-by: fxmarty-amd <felmarty@amd.com>
@SunMarc SunMarc merged commit bc3d578 into main Mar 13, 2025
24 checks passed
@SunMarc SunMarc deleted the fix-pointer branch March 13, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants