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

[C10D] Add __repr__ to P2POp class #126538

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 15 additions & 0 deletions torch/distributed/distributed_c10d.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,21 @@ def __new__(cls, op: Callable, tensor: torch.Tensor, peer: int,
_check_single_tensor(tensor, "tensor")
return object.__new__(cls)

def __repr__(self):
my_group_rank = get_rank(self.group)
peer_group_rank = get_group_rank(self.group, self.peer) if self.group else self.peer
op_name = self.op.__name__
group_name = self.group.group_name if self.group else "default_pg"
if "send" in op_name:
s = my_group_rank
d = peer_group_rank
elif "recv" in op_name:
s = peer_group_rank
d = my_group_rank
else:
return super().__repr__()

return f"P2POp({op_name} pg={group_name}, s={s}, d={d}, {self.tensor.shape}, {self.tensor.dtype})"
Copy link
Contributor

@c-p-i-o c-p-i-o May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print the tag too if it exists?
Don't know how/when it's used - but might be useful?

tag (int, optional): Tag to match send with recv.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea.... actually NCCL doesn't even support tag. So i would print it out of 'completeness' or compatibility with Gloo, but i think nobody is using tag anyway and we should probably deprecate it.


class _CollOp:
"""
Expand Down
Loading