Skip to content

Commit

Permalink
Sync states for xpu fsdp (#2005)
Browse files Browse the repository at this point in the history
* sync states for xpu fsdp

* Update src/accelerate/utils/dataclasses.py

Co-authored-by: Zach Mueller <[email protected]>

---------

Co-authored-by: Zach Mueller <[email protected]>
  • Loading branch information
abhilash1910 and muellerzr authored Oct 2, 2023
1 parent 206ab49 commit 420743a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/accelerate/utils/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

from .constants import FSDP_AUTO_WRAP_POLICY, FSDP_BACKWARD_PREFETCH, FSDP_STATE_DICT_TYPE
from .environment import str_to_bool
from .imports import is_xpu_available
from .versions import compare_versions


Expand Down Expand Up @@ -920,7 +921,8 @@ def __post_init__(self):
self.activation_checkpointing = str_to_bool(os.environ.get(prefix + "ACTIVATION_CHECKPOINTING", "False")) == 1

if self.sync_module_states:
self.param_init_fn = lambda x: x.to_empty(device=torch.cuda.current_device(), recurse=False)
device = torch.cuda.current_device() if not is_xpu_available() else torch.xpu.current_device()
self.param_init_fn = lambda x: x.to_empty(device=device, recurse=False)

@staticmethod
def get_module_class_from_name(module, name):
Expand Down

0 comments on commit 420743a

Please sign in to comment.