8000 [async-tp] fix a race condition that can cause silent correctness issue by yifuwang · Pull Request #137199 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[async-tp] fix a race condition that can cause silent correctness issue #137199

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

Closed
wants to merge 3 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
8 changes: 5 additions & 3 deletions torch/distributed/_symmetric_memory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def _pipelined_all_gather_and_consume(
group_size = symm_mem.world_size
rank = symm_mem.rank

symm_mem.barrier(channel=0)
backend_stream = _get_backend_stream()
backend_stream.wait_stream(torch.cuda.current_stream())
local_p2p_buf = symm_mem.get_buffer(rank, shard.shape, shard.dtype)
Expand All @@ -169,7 +170,7 @@ def _pipelined_all_gather_and_consume(

with torch.cuda.stream(backend_stream):
local_p2p_buf.copy_(shard)
symm_mem.barrier(channel=0)
symm_mem.barrier(channel=1)
torch.cuda.current_stream().wait_stream(backend_stream)

# At this point, all ranks have copied their local shard to
Expand All @@ -186,9 +187,8 @@ def _pipelined_all_gather_and_consume(
chunks[remote_rank].copy_(remote_p2p_buf)
shard_consumer(chunks[remote_rank], remote_rank)

with torch.cuda.stream(backend_stream):
symm_mem.barrier(channel=group_size % 2)
torch.cuda.current_stream().wait_stream(backend_stream)
symm_mem.barrier(channel=0)


def _pipelined_produce_and_all2all(
Expand All @@ -212,6 +212,7 @@ def _pipelined_produce_and_all2all(
group_size = symm_mem.world_size
rank = symm_mem.rank

symm_mem.barrier(channel=0)
backend_stream = _get_backend_stream()
backend_stream.wait_stream(torch.cuda.current_stream())

Expand Down Expand Up @@ -251,6 +252,7 @@ def get_p2p_buf(rank: int, idx: int) -> torch.Tensor:

chunk_producer(rank, out_chunks[rank])
torch.cuda.current_stream().wait_stream(backend_stream)
symm_mem.barrier(channel=0)


lib = torch.library.Library("symm_mem", "DEF") # noqa: TOR901
Expand Down
Loading
0