Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix distributed devices #612

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/axolotl/utils/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def gather_scalar_from_all_ranks(fn, world_size=1): # pylint: disable=invalid-n
value_scalar = fn()
if not is_distributed():
return [value_scalar]
value_tensor = torch.tensor(value_scalar, device=dist.get_rank()).float()
value_tensor = torch.tensor(value_scalar, device=torch.cuda.current_device()).float()

if not is_main_process():
dist.gather(value_tensor, dst=0)
Expand Down Expand Up @@ -137,9 +137,9 @@ def compute_and_broadcast(fn): # pylint: disable=invalid-name
"""
if is_main_process():
value_scalar = fn()
value_tensor = torch.tensor(value_scalar, device=dist.get_rank()).float()
value_tensor = torch.tensor(value_scalar, device=torch.cuda.current_device()).float()
else:
value_tensor = torch.tensor(0.0, device=dist.get_rank()) # Placeholder tensor
value_tensor = torch.tensor(0.0, device=torch.cuda.current_device()) # Placeholder tensor

# Broadcast the tensor to all processes.
barrier()
Expand All @@ -164,7 +164,7 @@ def gather_from_all_ranks(fn, world_size=1): # pylint: disable=invalid-name
- A list of computed values from all ranks if on the gathering rank, otherwise None.
"""
value_scalar = fn()
value_tensor = torch.tensor(value_scalar, device=dist.get_rank()).float()
value_tensor = torch.tensor(value_scalar, device=torch.cuda.current_device()).float()

# Placeholder tensor for gathering results
if is_main_process():
Expand Down
Loading