Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerzr committed Sep 13, 2023
1 parent 5cb9f2b commit 4d7c276
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/accelerate/accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,12 @@ def save(self, obj, f, safe_serialization=False):
>>> accelerator.save(arr, "array.pkl")
```
"""
save(obj, f, save_on_each_node=self.project_configuration.save_on_each_node, safe_serialization=safe_serialization)
save(
obj,
f,
save_on_each_node=self.project_configuration.save_on_each_node,
safe_serialization=safe_serialization,
)

def save_model(
self,
Expand Down
12 changes: 7 additions & 5 deletions src/accelerate/utils/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,19 @@ def wait_for_everyone():
"""
PartialState().wait_for_everyone()

def save(obj, f, save_on_each_node: bool = False, safe_serialization:bool = False):

def save(obj, f, save_on_each_node: bool = False, safe_serialization: bool = False):
"""
Save the data to disk. Use in place of `torch.save()`.
Args:
obj:
obj:
The data to save
f:
f:
The file (or file-like object) to use to save the data
save_on_each_node (`bool`, *optional*, defaults to `False`):
save_on_each_node (`bool`, *optional*, defaults to `False`):
Whether to only save on the global main process
safe_serialization (`bool`, *optional*, defaults to `False`):
safe_serialization (`bool`, *optional*, defaults to `False`):
Whether to save `obj` using `safetensors`
"""
save_func = torch.save if not safe_serialization else partial(safe_save_file, metadata={"format": "pt"})
Expand All @@ -131,6 +132,7 @@ def save(obj, f, save_on_each_node: bool = False, safe_serialization:bool = Fals
elif PartialState().is_local_main_process and not save_on_each_node:
save_func(obj, f)


@contextmanager
def clear_environment():
"""
Expand Down

0 comments on commit 4d7c276

Please sign in to comment.