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

using tensor device in eval distributed #557

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions libai/evaluation/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ def inference_on_dataset(

# get valid sample
valid_data = {
key: dist.tensor_to_rank0(value, to_local=True)[:valid_sample]
key: dist.tensor_to_rank0(value, device=value.placement.type, to_local=True)[:valid_sample]
for key, value in data.items()
}
valid_outputs = {}
for key, value in outputs.items():
value = dist.tensor_to_rank0(value, to_local=True)
value = dist.tensor_to_rank0(value, device=value.placement.type, to_local=True)
if value.ndim > 1:
valid_outputs[key] = value[:valid_sample] # Slice if it's batched output
else:
Expand Down
1 change: 0 additions & 1 deletion libai/utils/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ def tton(tensor, local_only=False, ranks=None):

def tensor_to_rank0(tensor, device="cuda", to_local=False):
"""Global tensor to rank0."""
# assert device in ["cpu", "cuda"], f"not supported for device:{device}"
if tensor.is_global:
# Consider if it's 2d mesh, ranks should be [[0]] instead of [0]
placement = flow.placement(device, ranks=[0] if tensor.placement.ranks.ndim == 1 else [[0]])
Expand Down