Skip to content

[symm_mem] Reject alloc and first rendezvous during CUDA graph capture - #197857

Closed
RohitRathore1 wants to merge 4 commits into
pytorch:mainfrom
RohitRathore1:symm-mem-graph-capture-guard
Closed

RohitRathore1 wants to merge 4 commits into
pytorch:mainfrom
RohitRathore1:symm-mem-graph-capture-guard

Conversation

@RohitRathore1

@RohitRathore1 RohitRathore1 commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

alloc() and a first-time rendezvous() block the host on the current stream (handle exchange, peer-table upload, stream synchronize). Doing either while the stream is capturing a CUDA graph previously failed with a bare cudaErrorStreamCaptureUnsupported raised from deep inside the driver call, with nothing pointing at the actual mistake.

Both paths now raise a TORCH_CHECK up front, naming the operation and telling the caller what to do instead: allocate with _symmetric_memory.empty() and run the first rendezvous eagerly before starting capture. Subsequent rendezvous calls on the same buffer hit the cache and remain capture-safe, and collectives on a rendezvoused buffer stay capturable after one eager run - each replay performs that rank's peer synchronization, so every rank must replay the same number of times. Docs for empty() and rendezvous() updated to state the contract.

Fixes #198140

@pytorch-bot

pytorch-bot Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/197857

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit b127f94 with merge base 3374f39 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

// surfaces as a bare cudaErrorStreamCaptureUnsupported from deep inside the
// driver call, with nothing telling the caller what to change. Callers must
// hold a CUDAGuard for the target device before calling this.
void check_not_capturing(const std::string& op, const char* hint) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

currently in caching allocator we have fast helper functions to check if captures are underway (to minimize effect on eager calls and not call currentStreamCaptureStatusMayInitCtx() in every eager rendezvous), try to see if you can reuse them

@RohitRathore1 RohitRathore1 Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

is_capture_context() on DeviceCachingAllocator is the one that reads the CaptureTracker count first and only hits the driver if a capture is actually active on the device but today it's private though, so we'd need a small public accessor on CUDAAllocator (isCaptureContext(device) or similar) that forwards to it, plus a driver-query fallback in the base class for pluggable allocators that don't track captures and then symm_mem just calls that. Does that sound ok, or did you have a different way in mind to get at it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah sounds good

not PLATFORM_SUPPORTS_SYMM_MEM, "SymmMem is not supported on this ROCm arch"
)
@skip_if_lt_x_gpu(2)
def test_one_shot_all_reduce_cuda_graph(self) -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pare down the tests, no need to test each op individually

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sure, will cut it down to two: one for the two refusals and one capture/replay on one_shot_all_reduce and rest of the ops go through the same path anyway.

@RohitRathore1

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased symm-mem-graph-capture-guard onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout symm-mem-graph-capture-guard && git pull --rebase)

@skipIf(
not PLATFORM_SUPPORTS_SYMM_MEM, "SymmMem is not supported on this ROCm arch"
)
@skip_if_lt_x_gpu(2)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do these tests need skip_if_rocm_ver_lessthan_multiprocess((10, 1))?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

if these creates any problems while merge then we can skip

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@RohitRathore1

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased symm-mem-graph-capture-guard onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout symm-mem-graph-capture-guard && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the symm-mem-graph-capture-guard branch from a456d27 to 83674fb Compare October 1, 2026 13:18
@RohitRathore1
RohitRathore1 marked this pull request as ready for review October 2, 2026 05:35
soulitzer added a commit that referenced this pull request Oct 2, 2026
The first day of shadow runs on pytorch/pytorch (347 runs, 01:53-14:10 UTC on
2026-10-02) found three problems.

1. Ten eligible PRs were never analyzed. The labeler adds several labels to a
new PR in the same second, and every label event queued a run in the same
per-PR concurrency group. GitHub keeps one pending run per group, so a later
label's run replaced the pending `open source` run and then skipped itself.
For example, "Remove unused parameters in autograd" got five runs at
07:12:28: both eligible runs were cancelled and the other three skipped. Now
only entry events (the `open source` label and ready_for_review) share the
per-PR group; every other event gets its own group keyed by run id. Entry
events still run one at a time per PR.

2. Four runs (#199436, #199440, #199463, #199484) failed with Claude Code's
`error_max_structured_output_retries`: the worker produced no schema-valid
output within the default 5 attempts. Many successful runs also needed a retry
(4 turns instead of 2). MAX_STRUCTURED_OUTPUT_RETRIES is now 25. Every attempt
is a turn, so --max-turns goes from 5 to 30. A failed run cost about $0.02 per
attempt, so --max-budget-usd goes from 0.50 to 1.50. When the SDK errors like
this, the action writes no execution log and leaves `execution_file` empty.
Stage 2c then opened `Path("")`, which is `.`, and recorded
"IsADirectoryError" as the processing error. It now records "Claude action
wrote no execution log".

3. Eight runs failed the evidence-excerpt check. One cut a long line short (the
case that started this change, #199425). Five skipped lines
inside an excerpt (#197857, #199447, #199471, #199472, #199497). Two turned an
unchanged context line, which also appeared in the `@@` hunk header, into a
fake `-`/`+` pair (#199453, #199461). The worker prompt now says to keep
excerpts short by choosing a shorter run of adjacent lines, never by skipping
or cutting lines, and never to turn unchanged lines or hunk-header text into
changed lines. The validator stays strict: a mismatched excerpt can't be told
apart from an invented one, and a failed run falls back to human triage. The
replay below shows the wording fixes the hunk-header pattern but only partly
helps the other two, so a structural follow-up is still needed.

The same change is being made to pytorch/pytorch and pytorch/ciforge.

Test Plan:

```
cd scripts/auto_pr_triage && python -m unittest discover -p 'test_*.py'
actionlint .github/workflows/auto-pr-triage.yml
```

The worker was replayed locally (claude-sonnet-4-6, --effort low, the CI
flags and the old 5-attempt limits) on the exact inputs of three failed runs:
each run's patch at its analyzed head_sha and CODEOWNERS at its workflow_sha.
Outputs were checked with validate_result. Evidence-excerpt failures:

| PR (pattern)                         | old worker.md | new worker.md |
|--------------------------------------|---------------|---------------|
| #199461 (fake -/+ from hunk header)  | 2/3           | 0/3           |
| #197857 (skipped comment lines)      | 4/4           | 2/3           |
| #199425 (cut a long comment line)    | 2/5           | 3/5           |

The remaining failures still drop two comment lines from the middle of an
excerpt (#197857) or stop a long comment line at the end of a sentence
(#199425).

This PR was authored with an AI assistant (Claude Code).

ghstack-source-id: d937117
Pull-Request-resolved: #199428
soulitzer added a commit that referenced this pull request Oct 2, 2026
The first day of shadow runs on pytorch/pytorch (347 runs, 01:53-14:10 UTC on
2026-10-02) found three problems.

1. Ten eligible PRs were never analyzed. The labeler adds several labels to a
new PR in the same second, and every label event queued a run in the same
per-PR concurrency group. GitHub keeps one pending run per group, so a later
label's run replaced the pending `open source` run and then skipped itself.
For example, "Remove unused parameters in autograd" got five runs at
07:12:28: both eligible runs were cancelled and the other three skipped. Now
only entry events (the `open source` label and ready_for_review) share the
per-PR group; every other event gets its own group keyed by run id. Entry
events still run one at a time per PR.

2. Four runs (#199436, #199440, #199463, #199484) failed with Claude Code's
`error_max_structured_output_retries`: the worker produced no schema-valid
output within the default 5 attempts. Many successful runs also needed a retry
(4 turns instead of 2). MAX_STRUCTURED_OUTPUT_RETRIES is now 25. Every attempt
is a turn, so --max-turns goes from 5 to 30. A failed run cost about $0.02 per
attempt, so --max-budget-usd goes from 0.50 to 1.50. When the SDK errors like
this, the action writes no execution log and leaves `execution_file` empty.
Stage 2c then opened `Path("")`, which is `.`, and recorded
"IsADirectoryError" as the processing error. It now records "Claude action
wrote no execution log".

3. Eight runs failed the evidence-excerpt check. One cut a long line short (the
case that started this change, #199425). Five skipped lines inside an excerpt
(#197857, #199447, #199471, #199472, #199497). Two turned an unchanged line,
which also appeared in the `@@` hunk header, into a fake `-`/`+` pair (#199453,
#199461).

The worker prompt still asks for whole, adjacent lines, and now also says never
to cut or skip lines or to turn unchanged lines or hunk-header text into
changed lines. A local replay showed that wording alone does not stop the
model from dropping comment lines or stopping a long line at the end of a
sentence, so the validator is relaxed as a safety net. Every excerpt line must
still come from the file's patch, in patch order, but lines may be skipped in
between, and a line may stop early if it keeps some text after its marker.
Every character shown still comes from the patch, so the model still cannot
add text; what we give up is that an excerpt may show two lines without the
lines between them. A fake `-`/`+` pair is still rejected, because it claims an
unchanged line changed.

We also considered having the model cite patch line ranges and extracting the
excerpt in the controller, which removes these failures by construction. The
relaxed check fixes almost all of them with a much smaller change.

The same change is being made to pytorch/pytorch and pytorch/ciforge.

Test Plan:

```
cd scripts/auto_pr_triage && python -m unittest discover -p 'test_*.py'
actionlint .github/workflows/auto-pr-triage.yml
```

The worker was replayed locally (claude-sonnet-4-6, --effort low, the CI
flags and the old 5-attempt limits) on the exact inputs of the eight runs that
failed the excerpt check: each run's patch at its analyzed head_sha and
CODEOWNERS at its workflow_sha. Outputs were checked with validate_result.

| Prompt and check                     | Excerpt failures |
|--------------------------------------|------------------|
| old worker.md, old check (3 PRs)     | 8/12             |
| new worker.md, old check (3 PRs)     | 5/11             |
| new worker.md, relaxed check (8 PRs) | 1/21             |

Re-checking the eight original CI outputs with the relaxed check, six pass.
The two that still fail (#199453, #199461), and the one replay failure
(#199453), are all the fake `-`/`+` pair, which stays rejected. An extra
prompt example aimed at that pattern made it worse in a replay, so it is not
included.

This PR was authored with an AI assistant (Claude Code).

ghstack-source-id: 546c754
Pull-Request-resolved: #199428
pytorchmergebot pushed a commit that referenced this pull request Oct 2, 2026
…99428)

The first day of shadow runs on pytorch/pytorch (347 runs, 01:53-14:10 UTC on
2026-10-02) found three problems.

1. Ten eligible PRs were never analyzed. The labeler adds several labels to a
new PR in the same second, and every label event queued a run in the same
per-PR concurrency group. GitHub keeps one pending run per group, so a later
label's run replaced the pending `open source` run and then skipped itself.
For example, "Remove unused parameters in autograd" got five runs at
07:12:28: both eligible runs were cancelled and the other three skipped. Now
only entry events (the `open source` label and ready_for_review) share the
per-PR group; every other event gets its own group keyed by run id. Entry
events still run one at a time per PR.

2. Four runs (#199436, #199440, #199463, #199484) failed with Claude Code's
`error_max_structured_output_retries`: the worker produced no schema-valid
output within the default 5 attempts. Many successful runs also needed a retry
(4 turns instead of 2). MAX_STRUCTURED_OUTPUT_RETRIES is now 25. Every attempt
is a turn, so --max-turns goes from 5 to 30. A failed run cost about $0.02 per
attempt, so --max-budget-usd goes from 0.50 to 1.50. When the SDK errors like
this, the action writes no execution log and leaves `execution_file` empty.
Stage 2c then opened `Path("")`, which is `.`, and recorded
"IsADirectoryError" as the processing error. It now records "Claude action
wrote no execution log".

3. Eight runs failed the evidence-excerpt check. One cut a long line short (the
case that started this change, #199425). Five skipped lines inside an excerpt
(#197857, #199447, #199471, #199472, #199497). Two turned an unchanged line,
which also appeared in the `@@` hunk header, into a fake `-`/`+` pair (#199453,
#199461).

The worker prompt still asks for whole, adjacent lines, and now also says never
to cut or skip lines or to turn unchanged lines or hunk-header text into
changed lines. A local replay showed that wording alone does not stop the
model from dropping comment lines or stopping a long line at the end of a
sentence, so the validator is relaxed as a safety net. Every excerpt line must
still come from the file's patch, in patch order, but lines may be skipped in
between, and a line may stop early if it keeps some text after its marker.
Every character shown still comes from the patch, so the model still cannot
add text; what we give up is that an excerpt may show two lines without the
lines between them. A fake `-`/`+` pair is still rejected, because it claims an
unchanged line changed.

We also considered having the model cite patch line ranges and extracting the
excerpt in the controller, which removes these failures by construction. The
relaxed check fixes almost all of them with a much smaller change.

The same change is being made to pytorch/pytorch and pytorch/ciforge.

Test Plan:

```
cd scripts/auto_pr_triage && python -m unittest discover -p 'test_*.py'
actionlint .github/workflows/auto-pr-triage.yml
```

The worker was replayed locally (claude-sonnet-4-6, --effort low, the CI
flags and the old 5-attempt limits) on the exact inputs of the eight runs that
failed the excerpt check: each run's patch at its analyzed head_sha and
CODEOWNERS at its workflow_sha. Outputs were checked with validate_result.

| Prompt and check                     | Excerpt failures |
|--------------------------------------|------------------|
| old worker.md, old check (3 PRs)     | 8/12             |
| new worker.md, old check (3 PRs)     | 5/11             |
| new worker.md, relaxed check (8 PRs) | 1/21             |

Re-checking the eight original CI outputs with the relaxed check, six pass.
The two that still fail (#199453, #199461), and the one replay failure
(#199453), are all the fake `-`/`+` pair, which stays rejected. An extra
prompt example aimed at that pattern made it worse in a replay, so it is not
included.

This PR was authored with an AI assistant (Claude Code).
Pull Request resolved: #199428
Approved by: https://github.com/janeyx99
@ngimel

ngimel commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

@claude review this PR. Flag only real correctness and overhead issues, ignore nits

@claude

claude Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Claude finished @ngimel's task in 1m 36s —— View job


I found no blocking correctness or overhead issues. The one gap: the guard only catches captures that CUDAGraph starts, so the docs promise a little more than the check does.

PR Review: #197857

Summary

alloc() and the first rendezvous() now check for an active capture through a new CUDAAllocator::isCaptureContext(device). The native allocator answers that check from its CaptureTracker count. I looked only at correctness and overhead, as you asked.

Performance

I found no overhead issues.

  • On the eager path, the check is a mutex acquire plus a counter read. It runs only in alloc() and on a rendezvous cache miss. Both of those already do IPC, mapping and cudaStreamSynchronize, so the cost doesn't show. The cached rendezvous() path, which collectives hit during capture, is unchanged.
  • Allocators that don't track captures (pluggable ones) fall back to a DeviceGuard plus a driver query. That also runs only on those two cold paths.

Code Quality

  • The guard misses captures that CUDAGraph didn't start, and the docs don't say so (c10/cuda/CUDACachingAllocator.cpp:3356, torch/distributed/_symmetric_memory/__init__.py:2205,2269). Only CUDAGraph::capture_begin calls markCaptureBegin. That happens in CUDAGraph.cpp:194 and :598. Captures started some other way leave hasActiveCaptures() false under the native allocator, so the check returns false without querying the driver. Examples are a raw cudaStreamBeginCapture from cuda-python or another library. Those users get the old bare cudaErrorStreamCaptureUnsupported. This doesn't regress anything, but both docstrings now say the CUDA backend "raises an error" during capture. Either narrow the wording to torch.cuda.graph/CUDAGraph captures, or accept the gap explicitly. Deliberately skipping the driver query when the counter is zero is the right call for overhead.

Things I checked that hold up

  • Locking: No CUDASymmetricMemoryAllocator::mutex_ is held when check_not_capturing runs, so there is no lock-order inversion with the allocator's device mutex. The other route is the symmetric-memory MemPool, where the caching allocator calls into symm alloc while holding its device mutex. That mutex is a recursive_mutex and the call stays on the same thread and device, so it can't deadlock.
  • Before allocator init: NativeCachingAllocator::isCaptureContext returns false, which is correct because no CUDAGraph capture can be active yet.
  • Lazy rendezvous inside a collective: Every rank raises locally before any store exchange, so the refusal can't leave peers hanging.

Recommendation

Approve. Correctness and overhead look fine. The only open item is how precisely the docstrings describe what the guard catches.

@ngimel ngimel added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 2, 2026
@galv

galv commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

I am honestly skeptical of this code change. Sure, it's true that you cannot synchronize a capturing stream. But instead of forcing people to do a warmup run first, I think you should use a separate, non-capturing stream to do the block exchange on that stream, and then synchronize. That guarantees that the peer-table upload and exchanges "happen before" whenever you first launch the cuda graph.

This is actually what NCCL already does, though I spent about 15 minutes trying to find the relevant code and couldn't, so I'll leave that be for now. Edit: This code: https://github.com/NVIDIA/nccl/blob/12df1a11afad322be5a204a2db890161cbf8131d/src/dev_runtime.cc#L235-L243

It's not quite the same thing (it happens during destruction), but similar concept. You can just have a separate non-capturing stream do work "eagerly" during stream capture, for a more robust solution than "make sure your warmup caches work that you don't want to happen during stream capture", which is a design pattern that generally speaking concerns me.

BTW, I'm here from #199439 because I also want a public is_capture_context() method on CUDACachingAllocator over there. In general, it's easier in the future if you make independent changes via ghstack, so that a concern with one part of your PR doesn't hold back another part of it.

To be clear, if Natalia still approves, that's fine with me.

@ngimel

ngimel commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

idk, I'm generally skeptical about "let's capture without warmup, so I'm fine witht his PR landing as is, until capture without warmup becomes a real thing

@ngimel

ngimel commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

@RohitRathore1 please take a look at the failure, and prioritize landing, to make cudagraph capturing helper available

@RohitRathore1

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased symm-mem-graph-capture-guard onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout symm-mem-graph-capture-guard && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the symm-mem-graph-capture-guard branch from a7bdd5f to 6a779e8 Compare October 6, 2026 05:32
@RohitRathore1

Copy link
Copy Markdown
Collaborator Author

there seems some infrastructure problem.

@RohitRathore1

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

alloc() and a first-time rendezvous() block the host on the current
stream (handle exchange, peer-table upload, stream synchronize). Doing
either while the stream is capturing a CUDA graph previously failed
with a bare cudaErrorStreamCaptureUnsupported raised from deep inside
the driver call, with nothing pointing at the actual mistake.

Both paths now raise a TORCH_CHECK up front, naming the operation and
telling the caller what to do instead: allocate with
_symmetric_memory.empty() and run the first rendezvous eagerly before
starting capture. Subsequent rendezvous calls on the same buffer hit
the cache and remain capture-safe, and collectives on a rendezvoused
buffer stay capturable after one eager run - each replay performs that
rank's peer synchronization, so every rank must replay the same number
of times. Docs for empty() and rendezvous() updated to state the
contract.
…e tests

Add CUDAAllocator::isCaptureContext(device). The native allocator answers
from the capture count kept by markCaptureBegin/End and only queries the
driver while a capture is active on that device, so eager alloc and
first-rendezvous checks cost a counter read. Allocators that do not track
captures fall back to the driver query. Both paths select `device` before
querying, because the default stream's nullptr handle resolves against the
current device.

Collapse the capture tests to one covering both refusals and one
capture-and-replay on one_shot_all_reduce.
The symm_mem multiprocess collectives are gated on ROCm >= 10.1 everywhere
else in this file. Without the gate the refusal test hung on the MI350
runner (ROCm 10.0) until the per-test timeout and took the rest of the
shard with it.
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased symm-mem-graph-capture-guard onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout symm-mem-graph-capture-guard && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the symm-mem-graph-capture-guard branch from 6a779e8 to b127f94 Compare October 6, 2026 16:44
@stmcgovern

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
…torch#199428)

The first day of shadow runs on pytorch/pytorch (347 runs, 01:53-14:10 UTC on
2026-10-02) found three problems.

1. Ten eligible PRs were never analyzed. The labeler adds several labels to a
new PR in the same second, and every label event queued a run in the same
per-PR concurrency group. GitHub keeps one pending run per group, so a later
label's run replaced the pending `open source` run and then skipped itself.
For example, "Remove unused parameters in autograd" got five runs at
07:12:28: both eligible runs were cancelled and the other three skipped. Now
only entry events (the `open source` label and ready_for_review) share the
per-PR group; every other event gets its own group keyed by run id. Entry
events still run one at a time per PR.

2. Four runs (pytorch#199436, pytorch#199440, pytorch#199463, pytorch#199484) failed with Claude Code's
`error_max_structured_output_retries`: the worker produced no schema-valid
output within the default 5 attempts. Many successful runs also needed a retry
(4 turns instead of 2). MAX_STRUCTURED_OUTPUT_RETRIES is now 25. Every attempt
is a turn, so --max-turns goes from 5 to 30. A failed run cost about $0.02 per
attempt, so --max-budget-usd goes from 0.50 to 1.50. When the SDK errors like
this, the action writes no execution log and leaves `execution_file` empty.
Stage 2c then opened `Path("")`, which is `.`, and recorded
"IsADirectoryError" as the processing error. It now records "Claude action
wrote no execution log".

3. Eight runs failed the evidence-excerpt check. One cut a long line short (the
case that started this change, pytorch#199425). Five skipped lines inside an excerpt
(pytorch#197857, pytorch#199447, pytorch#199471, pytorch#199472, pytorch#199497). Two turned an unchanged line,
which also appeared in the `@@` hunk header, into a fake `-`/`+` pair (pytorch#199453,
pytorch#199461).

The worker prompt still asks for whole, adjacent lines, and now also says never
to cut or skip lines or to turn unchanged lines or hunk-header text into
changed lines. A local replay showed that wording alone does not stop the
model from dropping comment lines or stopping a long line at the end of a
sentence, so the validator is relaxed as a safety net. Every excerpt line must
still come from the file's patch, in patch order, but lines may be skipped in
between, and a line may stop early if it keeps some text after its marker.
Every character shown still comes from the patch, so the model still cannot
add text; what we give up is that an excerpt may show two lines without the
lines between them. A fake `-`/`+` pair is still rejected, because it claims an
unchanged line changed.

We also considered having the model cite patch line ranges and extracting the
excerpt in the controller, which removes these failures by construction. The
relaxed check fixes almost all of them with a much smaller change.

The same change is being made to pytorch/pytorch and pytorch/ciforge.

Test Plan:

```
cd scripts/auto_pr_triage && python -m unittest discover -p 'test_*.py'
actionlint .github/workflows/auto-pr-triage.yml
```

The worker was replayed locally (claude-sonnet-4-6, --effort low, the CI
flags and the old 5-attempt limits) on the exact inputs of the eight runs that
failed the excerpt check: each run's patch at its analyzed head_sha and
CODEOWNERS at its workflow_sha. Outputs were checked with validate_result.

| Prompt and check                     | Excerpt failures |
|--------------------------------------|------------------|
| old worker.md, old check (3 PRs)     | 8/12             |
| new worker.md, old check (3 PRs)     | 5/11             |
| new worker.md, relaxed check (8 PRs) | 1/21             |

Re-checking the eight original CI outputs with the relaxed check, six pass.
The two that still fail (pytorch#199453, pytorch#199461), and the one replay failure
(pytorch#199453), are all the fake `-`/`+` pair, which stays rejected. An extra
prompt example aimed at that pattern made it worse in a replay, so it is not
included.

This PR was authored with an AI assistant (Claude Code).
Pull Request resolved: pytorch#199428
Approved by: https://github.com/janeyx99
cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
pytorch#197857)

alloc() and a first-time rendezvous() block the host on the current stream (handle exchange, peer-table upload, stream synchronize). Doing either while the stream is capturing a CUDA graph previously failed with a bare cudaErrorStreamCaptureUnsupported raised from deep inside the driver call, with nothing pointing at the actual mistake.

Both paths now raise a TORCH_CHECK up front, naming the operation and telling the caller what to do instead: allocate with _symmetric_memory.empty() and run the first rendezvous eagerly before starting capture. Subsequent rendezvous calls on the same buffer hit the cache and remain capture-safe, and collectives on a rendezvoused buffer stay capturable after one eager run - each replay performs that rank's peer synchronization, so every rank must replay the same number of times. Docs for empty() and rendezvous() updated to state the contract.

Fixes pytorch#198140
Pull Request resolved: pytorch#197857
Approved by: https://github.com/ngimel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/b200-symm-mem ciflow/h100-symm-mem ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: distributed (c10d) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[symm_mem] Allocation or first rendezvous inside CUDA graph capture fails with a bare cudaErrorStreamCaptureUnsupported

7 participants