Skip to content

Updated in broadcast_str to use correct tensor size #1015

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion tests/utils/test_distributed_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ def test_spawn_multi_process(self) -> None:
def test_broadcast_str(self) -> None:
spawn_multi_process(2, "gloo", self._test_broadcast_str)

@skip_if_not_gpu
@skip_if_not_distributed
def test_broadcast_str_gpu(self) -> None:
spawn_multi_process(2, "nccl", self._test_broadcast_str)

@staticmethod
def _test_broadcast_str() -> None:
"""
Tests that test_broadcast_strworks as expected
"""

init_from_env()
val = None
if dist.get_rank() == 0:
val = "foo"
Expand Down
2 changes: 1 addition & 1 deletion torchtnt/utils/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def broadcast_str(
# convert string to tensor
buffer = torch.frombuffer(val.encode("utf-8"), dtype=torch.uint8)
buffer = buffer.to(device=device)
buffer_length = torch.tensor((len(buffer)), dtype=torch.int, device=device)
buffer_length = torch.tensor([len(buffer)], dtype=torch.int, device=device)

if fixed_buffer_size is not None:
if len(buffer) > fixed_buffer_size:
Expand Down
Loading