-
Notifications
You must be signed in to change notification settings - Fork 977
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
Revert default behavior of get_state_dict_from_offload
#3253
base: main
Are you sure you want to change the base?
Revert default behavior of get_state_dict_from_offload
#3253
Conversation
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
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. |
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.
Oh dear, thanks for the follow up! We have a release planned shortly after thanksgiving so this can be included in it :)
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.
Thanks for the bug fix !
cc @ArthurZucker for final |
What does this PR do?
Purpose
get_state_dict_from_offload
introduced starting in accelerate 1.1.0Background
Starting in accelerate 1.1.0,
get_state_dict_from_offload
moves state_dict tensors to the CPU by default.In the case that a module has parameters on the GPU,
get_state_dict_from_offload
implements the following procedure:get_state_dict_from_offload
is called, copies of the tensors are created on the CPU (2) which are returned laterstate_dict
, the CPU tensors (2) are copied back to the GPU (3)This procedure ensures memory efficiency due to how reference to GPU tensors (1) is dropped before GPU tensors (3) are allocated.
However, in the downstream case of transformers,
PretrainedModel.save_pretrained
keeps a copy of the original GPU tensors (1) for longer than they are needed. This long-lived reference to (1) results in references to both (1) and (3) being alive at the same time, leading to increased memory usage.Changes
get_state_dict_from_offload
to not move parameter tensors by defaultsave_pretrained
for partially offloaded models transformers#34890Testing
save_offloaded.py
transformers <= 4.46.0 | accelerate < 1.1.0
transformers <= 4.46.0 | accelerate == 1.1.0, 1.1.1
transformers <= 4.46.0 | accelerate > 1.1.1 (this branch)
transformers > 4.46.0 | accelerate > 1.1.1 (this branch)
Who can review?