Skip to content

Commit

Permalink
[Checkpoint] Minor update to checkpoint utils (#89964)
Browse files Browse the repository at this point in the history
Change to only print temp directory once on rank0.

Pull Request resolved: #89964
Approved by: https://github.com/XilunWu
  • Loading branch information
wz337 authored and pytorchmergebot committed Dec 1, 2022
1 parent a43e09c commit ad1585b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion torch/testing/_internal/distributed/checkpoint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ def wrapper(self, *args: Tuple[object], **kwargs: Dict[str, Any]) -> None:
# Only create temp_dir when rank is 0
if dist.get_rank() == 0:
temp_dir = tempfile.mkdtemp()
print(f"Using temp directory: {self.temp_dir }")
else:
temp_dir = ""
object_list = [temp_dir]

# Broadcast temp_dir to all the other ranks
dist.broadcast_object_list(object_list)
self.temp_dir = object_list[0]
print(f"Using temp directory: {self.temp_dir }")

try:
func(self)
finally:
Expand Down

0 comments on commit ad1585b

Please sign in to comment.