Repository navigation
[tools] Fix CUDA Graph dependency arrows - #5743
Conversation
|
@claude review the pr |
|
Claude finished @fegin's task in 1m 40s —— View job Approve -- see review (one optional inline suggestion). |
There was a problem hiding this comment.
Verdict: Approve -- This fixes a real bug: a GPU dependency arrow can end up on the wrong lane, or compaction can fail. The fix is small, and the regression test fails on the base branch.
What this PR does. Before this PR, the compactor matched every GPU ac2g flow endpoint to a slice by its start time. A flow source (ph == "s") sits at the end of its source slice, though. Now sources are matched against slice ends, accepting the exact value or one float ulp on either side. Destinations still match slice starts. Endpoints that can't be matched still raise ValueError.
Example.
stream 1: A = ncclAllGather [10, 12] -> lane "NCCL all-gather"
B = compute [12, 13] -> lane "Compute"
flow s @ ts=12 (A -> ...), flow f @ ts=12
before: s looked up by start=12 -> B's lane (silently wrong arrow)
s @ nextafter(12) -> no match -> ValueError
after: s looked up by end=12 (+/-1 ulp) -> A's lane; f -> B's lane
Should consider
compact_cuda_graph_trace.py:554--end_pointscan be built in the same loop asstart_points(see the inline suggestion).
Details
- Gate: the bug is real on the base branch. With only start-keyed lookup, the new test's first subtest maps the source to the compute lane, and the second subtest raises. The change is local to the skill script; no core code, numerics, or CI are affected.
- The +/-1 ulp tolerance is enough if the profiler writes
ts/duras exact decimal microseconds from integer ns. In that casefloat(ts) + float(dur)andfloat(ts_flow)differ by at most ~1.5 ulp of the result, which rounds to one representable step. Wider drift would still raise rather than mis-map. - The test lives with the skill, reuses the existing
_kernel/_flowhelpers, and puts A and B in different semantic groups. That way a wrong lane assignment actually shows up.
Not verified: I did not run the unit tests or check the Muse Glimmer trace. The CI checkout didn't have the PR's files in its working tree.
| start_points = {} | ||
| for item in assignments: | ||
| by_old_stream[(item.pid, item.old_tid)].append(item) | ||
| exact_points[(item.pid, item.old_tid, item.start)] = item.new_tid | ||
| start_points[(item.pid, item.old_tid, item.start)] = item.new_tid | ||
| for values in by_old_stream.values(): | ||
| values.sort(key=lambda item: item.start) | ||
| starts = { | ||
| key: [item.start for item in values] for key, values in by_old_stream.items() | ||
| } | ||
| return starts, by_old_stream, exact_points | ||
| end_points = { | ||
| (item.pid, item.old_tid, item.end): item.new_tid | ||
| for values in by_old_stream.values() | ||
| for item in values | ||
| } | ||
| return starts, by_old_stream, start_points, end_points |
There was a problem hiding this comment.
Optional: the second pass over by_old_stream doesn't depend on the sort, so end_points can be filled in the same loop as start_points. That keeps the two lookup tables next to each other.
| start_points = {} | |
| for item in assignments: | |
| by_old_stream[(item.pid, item.old_tid)].append(item) | |
| exact_points[(item.pid, item.old_tid, item.start)] = item.new_tid | |
| start_points[(item.pid, item.old_tid, item.start)] = item.new_tid | |
| for values in by_old_stream.values(): | |
| values.sort(key=lambda item: item.start) | |
| starts = { | |
| key: [item.start for item in values] for key, values in by_old_stream.items() | |
| } | |
| return starts, by_old_stream, exact_points | |
| end_points = { | |
| (item.pid, item.old_tid, item.end): item.new_tid | |
| for values in by_old_stream.values() | |
| for item in values | |
| } | |
| return starts, by_old_stream, start_points, end_points | |
| start_points = {} | |
| end_points = {} | |
| for item in assignments: | |
| by_old_stream[(item.pid, item.old_tid)].append(item) | |
| start_points[(item.pid, item.old_tid, item.start)] = item.new_tid | |
| end_points[(item.pid, item.old_tid, item.end)] = item.new_tid | |
| for values in by_old_stream.values(): | |
| values.sort(key=lambda item: item.start) | |
| starts = { | |
| key: [item.start for item in values] for key, values in by_old_stream.items() | |
| } | |
| return starts, by_old_stream, start_points, end_points |
## Summary (human-written) Fix a bug of cudagraph dependency arrow. The AI summary shows an example that can cause errors. This PR fixes the issue. ## Why The trace compactor matches GPU dependency arrows to kernel start times. An arrow's source is at the source kernel's end. This can attach the arrow to the next kernel or make compaction fail. ```text Kernel A: [10, 12] Kernel B: [12, 14] At time 12, an arrow source belongs to A and a destination belongs to B. ``` ## What changed - Match GPU arrow sources to slice ends and destinations to slice starts. - Accept one adjacent floating-point value when matching a source timestamp. This handles rounding in timestamp + duration. - Keep errors for endpoints that cannot be matched. ## Numerics / performance This tool processes saved profiler traces. Kernel timestamps and durations are preserved. Training code is outside the change. ## Testing - Six tests pass: `python -m unittest discover -s .claude/skills/cuda_graph_trace_compaction/scripts -p test_compact_cuda_graph_trace.py`. - The regression test checks adjacent kernels, a rounded source timestamp, and preservation of the arrow timestamp. - Saved Muse Glimmer trace validation maps all 4228 and 3372 GPU flow endpoints. stack-info: PR: #5743, branch: fegin/stack/3
Stacked PRs: * #5746 * #5745 * #5744 * #5743 * __->__#5742 --- --- --- [docs] Clarify PyTorch library ownership ## Summary (human-written) Agents are confused by what "PyTorch libraries" means. They may treat meta-pytorch repos as non-pytorch repo and request changes if we use repos in the core parallelisms, which violates one of the core principal. ## Why The dependency rule does not define PyTorch libraries. This can incorrectly exclude libraries such as meta-pytorch/attention-gym. ## What changed - Count pytorch/pytorch and meta-pytorch repos as PyTorch libraries. - Keep complex techniques upstream, in pytorch/pytorch or a suitable meta-pytorch repo. ## Testing Documentation only. `pre-commit run --files .claude/CLAUDE.md` passes.
Stacked PRs: * #5746 * #5745 * #5744 * __->__#5771 --- --- --- [tools] Fix CUDA Graph dependency arrows Reland #5743, accidentally land #5743 to an incorrect branch. ## Summary (human-written) Fix a bug of cudagraph dependency arrow. The AI summary shows an example that can cause errors. This PR fixes the issue. ## Why The trace compactor matches GPU dependency arrows to kernel start times. An arrow's source is at the source kernel's end. This can attach the arrow to the next kernel or make compaction fail. ```text Kernel A: [10, 12] Kernel B: [12, 14] At time 12, an arrow source belongs to A and a destination belongs to B. ``` ## What changed - Match GPU arrow sources to slice ends and destinations to slice starts. - Accept one adjacent floating-point value when matching a source timestamp. This handles rounding in timestamp + duration. - Keep errors for endpoints that cannot be matched. ## Numerics / performance This tool processes saved profiler traces. Kernel timestamps and durations are preserved. Training code is outside the change. ## Testing - Six tests pass: `python -m unittest discover -s .claude/skills/cuda_graph_trace_compaction/scripts -p test_compact_cuda_graph_trace.py`. - The regression test checks adjacent kernels, a rounded source timestamp, and preservation of the arrow timestamp. - Saved Muse Glimmer trace validation maps all 4228 and 3372 GPU flow endpoints.
Stacked PRs:
[tools] Fix CUDA Graph dependency arrows
Summary (human-written)
Fix a bug of cudagraph dependency arrow. The AI summary shows an example
that can cause errors. This PR fixes the issue.
Why
The trace compactor matches GPU dependency arrows to kernel start times. An arrow's source is at the source kernel's end. This can attach the arrow to the next kernel or make compaction fail.
What changed
Numerics / performance
This tool processes saved profiler traces. Kernel timestamps and durations are preserved. Training code is outside the change.
Testing
python -m unittest discover -s .claude/skills/cuda_graph_trace_compaction/scripts -p test_compact_cuda_graph_trace.py.