Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/181218
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 1 New FailureAs of commit 6174b7e with merge base 12c7b75 ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 19e29f6 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: a1b3024 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 32ab8f0 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: fafa061 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit
Summary:
Closes the reduce-scatter race in the grouped chunked-loss path on
ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers
post_backward, chunk N+1's autograd backward runs on the default
stream concurrently with chunk N's accumulate on the RS stream. The
caching allocator can hand an autograd kernel a block that is a live
input/output of chunk N's accumulate, corrupting head.weight.grad
on non-zero ranks.
Fix: at post_backward exit, detect the chunked path via
TrainingState.FORWARD entry state (group post-hook never fires full
path, so pre_backward never runs) and call
current_stream().wait_event(self._post_reduce_event). Pure
stream-level wait, no CPU sync. Gated on in_chunked_path so normal
FSDP (non-grouped or grouped with full forward) is unaffected.
Why post-accumulate event at exit (not pre-accumulate at entry):
waiting on reduce_scatter_event at post_backward exit FAILS; waiting
on _post_reduce_event at post_backward exit PASSES. The accumulate
kernel itself is load-bearing, and autograd queues chunk N+1's
backward between this chunk's post_backward exit and the next one's
entry — a wait at entry is too late.
Nature of the bug (refined 2026-04-23 after CUDA + ROCm experiments):
The production failure as observed is ROCm-specific; the underlying
stream-ordering hazard is cross-platform. Two race windows, both
closed by the same stream-level wait:
1. rs_input block reuse. Active in the standalone repro on both CUDA
(2/3 baseline, 3/3 with _sleep on H100) and ROCm (32/200 baseline,
49-50/50 with --ag etc). Inert in FSDP on both platforms because
reduce_scatter_states.append(...) ref-holds rs_input. Verified by
adding --hold-refs input to the standalone repro on ROCm: 0/200.
2. Allocator-internal buffer (HIP caching allocator; not
Python-reachable; FSDP-code-path specific). Active in FSDP on
ROCm. Not reproducible in the standalone repro on ROCm by any
combination of --hold-refs + --sleep + --alloc-pressure, which
implies the racing buffer is something the standalone loop
doesn't allocate — most plausibly an autograd backward
intermediate, reshard buffer, or RCCL workspace from the
all_gather + reduce_scatter sequence FSDP issues per param
group. CUDA FSDP status of vector 2 is indeterminate from
FSDP-path data alone (either absent or timing-masked).
The conditional gating on in_chunked_path is currently kept to
minimize blast radius; making the fix unconditional is the right
long-term decision but requires a real-model perf check first.
Also adds investigation artifacts:
- fsdp2_chunked_loss_rocm_race.md — full writeup with all experiments
(row O/O' bisect, CUDA H100 discriminator, ROCm MI350X ref-hold
verification, vector 2 FSDP-specificity proof).
- rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop
repro. --hold-refs {off,input,both} toggles the FSDP-style
reduce_scatter_states ref-hold.
- rccl_chunked_loss_repro_sleep.py — _sleep variant for CUDA
discriminator + ROCm vector-2 isolation. Adds --hold-refs and
--alloc-pressure N (+ --alloc-pressure-numel).
- hip_allocator_cross_stream_repro.py — pure-allocator attempt that
did NOT reproduce; rules out a generic HIP allocator
cross-stream-reuse bug.
- analyze_memory_snapshot.py — summarizer for torch.cuda.memory
snapshot pickles.
Test Plan:
- ROCm MI350X (gfx950, ROCm 7.0.51831): full subtest sweep of
TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone
passes 5/5 with fix, fails bit-exactly (11.481... at (0,10), 2048/4096
elements, rank-1 shard) without.
- Standalone RCCL repro on ROCm: 0/500 with any stream-level sync
(rs_event_stream, post_accum_event_stream, device), 500/500 with
none. --hold-refs input: 0/200 (confirms vector 1 is rs_input).
- _sleep stress on ROCm: 1e9-cycle sleep at rs_after_accum or
rs_between_rs_and_accum races 50/50 without fix, 0/3 with fix.
- CUDA H100 + NCCL 2.29.7: baseline 2/3 races, sleep 1e9 = 3/3
races without fix; sleep 1e9 + post_accum_event_stream = 0/3.
Confirms vector 1 is cross-platform.
- ROCm vector-2 isolation: --hold-refs both × --sleep-cycles 1e9 ×
--alloc-pressure 1000 (numel 256/2048/4096) = 0/50 across the
matrix. Confirms vector 2 is FSDP-code-path-specific, not a
generic "RCCL + allocator + chunked loop" hazard.
Authored with Claude.
Reviewers:
Subscribers:
Tasks:
Tags:
ghstack-source-id: fafa061
Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: fd60a47 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: fd60a47 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: fd60a47 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: d6e0915 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: d6e0915 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: d6e0915 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 94af962 Pull-Request: #181218
weifengpy
added a commit
that referenced
this pull request
Apr 23, 2026
…d exit Summary: Closes the reduce-scatter race in the grouped chunked-loss path on ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers post_backward, chunk N+1's autograd backward runs on the default stream concurrently with chunk N's accumulate on the RS stream. The caching allocator can hand an autograd kernel a block that is a live input/output of chunk N's accumulate, corrupting head.weight.grad on non-zero ranks. Fix: at post_backward exit, detect the chunked path via TrainingState.FORWARD entry state (group post-hook never fires full path, so pre_backward never runs) and call current_stream().wait_event(self._post_reduce_event). Pure stream-level wait, no CPU sync. Gated on in_chunked_path so normal FSDP (non-grouped or grouped with full forward) is unaffected. Why post-accumulate event at exit (not pre-accumulate at entry): waiting on reduce_scatter_event at post_backward exit FAILS; waiting on _post_reduce_event at post_backward exit PASSES. The accumulate kernel itself is load-bearing, and autograd queues chunk N+1's backward between this chunk's post_backward exit and the next one's entry — a wait at entry is too late. Also adds investigation artifacts: - fsdp2_chunked_loss_rocm_race.md — full writeup (experiments O/O' bisect, root-cause, minimal repro, open question for CUDA) - rccl_chunked_loss_repro.py — standalone 2-process RCCL-in-loop repro. 500/500 races with none, 0/500 with any stream-level sync. - rccl_chunked_loss_repro_sleep.py — _sleep variant for the CUDA discriminator (pure stream-ordering-bug vs allocator event-gating-bug). - hip_allocator_cross_stream_repro.py — pure-allocator attempt that did NOT reproduce; rules out a generic HIP allocator cross-stream-reuse bug. - analyze_memory_snapshot.py — summarizer for torch.cuda.memory snapshot pickles. Test Plan: - Full subtest sweep on MI350X (gfx950, ROCm 7.0.51831): 5/5 clean on TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone. - Standalone RCCL repro: 0/500 races with rs_event_stream or post_accum_event_stream sync modes, vs 500/500 with none. - _sleep stress on ROCm: 1e9-cycle sleep injected on RS stream after accumulate; fix holds (0/3 races). Without fix: 3/3 races. - CUDA discriminator run still pending — see fsdp2_chunked_loss_rocm_race.md "Open question" section. Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 3d281c0 Pull-Request: #181218
Contributor
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
Summary:
Closes the reduce-scatter race in the grouped chunked-loss path on
ROCm (MI350X, RCCL). When a standalone per-chunk head call triggers
post_backward, chunk N+1's autograd backward runs on the default
stream concurrently with chunk N's accumulate on the RS stream. The
caching allocator can hand an autograd kernel a block that is a live
input/output of chunk N's accumulate, corrupting head.weight.grad
on non-zero ranks.
Fix: at post_backward exit, detect the chunked path via
TrainingState.FORWARD entry state (group post-hook never fires full
path, so pre_backward never runs) and call
current_stream().wait_event(self._post_reduce_event). Pure
stream-level wait, no CPU sync. Gated on in_chunked_path so normal
FSDP (non-grouped or grouped with full forward) is unaffected.
Why post-accumulate event at exit (not pre-accumulate at entry):
waiting on reduce_scatter_event at post_backward exit FAILS; waiting
on _post_reduce_event at post_backward exit PASSES. The accumulate
kernel itself is load-bearing, and autograd queues chunk N+1's
backward between this chunk's post_backward exit and the next one's
entry — a wait at entry is too late.
Nature of the bug (refined 2026-04-23 after CUDA + ROCm experiments):
The production failure as observed is ROCm-specific; the underlying
stream-ordering hazard is cross-platform. Two race windows, both
closed by the same stream-level wait:
rs_input block reuse. Active in the standalone repro on both CUDA
(2/3 baseline, 3/3 with _sleep on H100) and ROCm (32/200 baseline,
49-50/50 with --ag etc). Inert in FSDP on both platforms because
reduce_scatter_states.append(...) ref-holds rs_input. Verified by
adding --hold-refs input to the standalone repro on ROCm: 0/200.
Allocator-internal buffer (HIP caching allocator; not
Python-reachable; FSDP-code-path specific). Active in FSDP on
ROCm. Not reproducible in the standalone repro on ROCm by any
combination of --hold-refs + --sleep + --alloc-pressure, which
implies the racing buffer is something the standalone loop
doesn't allocate — most plausibly an autograd backward
intermediate, reshard buffer, or RCCL workspace from the
all_gather + reduce_scatter sequence FSDP issues per param
group. CUDA FSDP status of vector 2 is indeterminate from
FSDP-path data alone (either absent or timing-masked).
The conditional gating on in_chunked_path is currently kept to
minimize blast radius; making the fix unconditional is the right
long-term decision but requires a real-model perf check first.
Also adds investigation artifacts:
(row O/O' bisect, CUDA H100 discriminator, ROCm MI350X ref-hold
verification, vector 2 FSDP-specificity proof).
repro. --hold-refs {off,input,both} toggles the FSDP-style
reduce_scatter_states ref-hold.
discriminator + ROCm vector-2 isolation. Adds --hold-refs and
--alloc-pressure N (+ --alloc-pressure-numel).
did NOT reproduce; rules out a generic HIP allocator
cross-stream-reuse bug.
snapshot pickles.
Test Plan:
TestFullyShard1DTrainingCompose.test_partial_group_forward_then_standalone
passes 5/5 with fix, fails bit-exactly (11.481... at (0,10), 2048/4096
elements, rank-1 shard) without.
(rs_event_stream, post_accum_event_stream, device), 500/500 with
none. --hold-refs input: 0/200 (confirms vector 1 is rs_input).
rs_between_rs_and_accum races 50/50 without fix, 0/3 with fix.
races without fix; sleep 1e9 + post_accum_event_stream = 0/3.
Confirms vector 1 is cross-platform.
--alloc-pressure 1000 (numel 256/2048/4096) = 0/50 across the
matrix. Confirms vector 2 is FSDP-code-path-specific, not a
generic "RCCL + allocator + chunked loop" hazard.
Authored with Claude.
Reviewers:
Subscribers:
Tasks:
Tags:
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang