-
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 dtype when loading to meta model #36447
base: main
Are you sure you want to change the base?
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 |
src/transformers/modeling_utils.py
Outdated
False, | ||
True, | ||
strict=False, | ||
assign=False, |
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.
assign=False, | |
assign=True, |
we need to assign to get speed boost / leverage meta device
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.
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
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. |
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 settingassign=True
. I am not sure though, whystrict=False
, should I change it toTrue
?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)