Skip to content
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 dtype when loading to meta model #36447

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

zucchini-nlp
Copy link
Member

What does this PR do?

Before #36335, when loading the weights to meta model we kept the dtype of the module params. This PR fixes it by setting assign=True. I am not sure though, why strict=False, should I change it to True?

Before (no dtype is passed to accelerate):
set_module_tensor_to_device(model, param_name, param_device, **set_module_kwargs)

After:
module.load_state_dict({param_type: param[:].to(param_device)}, False, True)

Copy link

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).

@github-actions github-actions bot marked this pull request as draft February 27, 2025 10:27
False,
True,
strict=False,
assign=False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assign=False,
assign=True,

we need to assign to get speed boost / leverage meta device

Copy link
Member Author

Choose a reason for hiding this comment

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

oke, then we will need to either cast params to same dtype as module or add a more involved logic of passing dtype for composite model. Personally, I think the second way is will complicate things even more

Otherwise any time one wants to load different dtypes for each backbones with accelerate (device_map or low_cpu_mem-usage), one will get only one dtype for the whole model

@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.

@zucchini-nlp zucchini-nlp marked this pull request as ready for review February 28, 2025 07:52
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.

3 participants