Skip to content

Commit

Permalink
Enable Unwrapping for Model State Dicts (FSDP) (huggingface#2959)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex-Brooks <[email protected]>
  • Loading branch information
alex-jw-brooks authored Jul 31, 2024
1 parent a14260c commit f35cbd1
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/accelerate/accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3289,6 +3289,8 @@ def get_state_dict(self, model, unwrap=True):
from torch.distributed.fsdp import FullStateDictConfig, StateDictType
from torch.distributed.fsdp import FullyShardedDataParallel as FSDP

if unwrap:
model = self.unwrap_model(model)
full_state_dict_config = FullStateDictConfig(offload_to_cpu=True, rank0_only=True)
with FSDP.state_dict_type(model, StateDictType.FULL_STATE_DICT, full_state_dict_config):
state_dict = model.state_dict()
Expand Down

0 comments on commit f35cbd1

Please sign in to comment.