Revert default behavior of get_state_dict_from_offload
#3253
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?