Repository navigation
[rl] fix the breakable cudagraph env var - #3829
Merged
Merged
Conversation
Contributor
@tianyu-l yeah, this is the correct way to set up the env var before spawning the actor mesh. What happens under the hood is, monarch will spawn a |
jemitche1
pushed a commit
to jemitche1/torchtitan
that referenced
this pull request
Jul 15, 2026
## Symptom
Async-RL MoE runs (Qwen3-30B-A3B) generated fluent, coherent text that
ignored the prompt → reward
never increased. E.g., asked to sort Charlie, Alice, Bob, the model
rambled about "software
development / SourceGraph."
## What it looked like vs what it was
It appeared MoE-/DeepEP-/HybridEP-specific and was variously suspected
to be: base-vs-instruct
checkpoint, prompt rendering, or trainer→generator weight sync. All of
those were ruled out:
- Base vs instruct — the /mnt/.../Qwen3-30B-A3B checkpoint sorts
correctly (it IS
instruction-tuned); staged Instruct-2507 failed identically under the
bad config.
- Rendering — the decoded prompt is a correct qwen3 chat template and
reaches the model intact.
- Weight sync — reproduced in inference-only (no trainer, no sync).
- Key tell: coherent output rules out weight corruption (that would be
gibberish).
## Root cause
The corruption was zeroed prefill attention, and it was backend-agnostic
(in
rl/models/attention.py, used by dense + MoE). The trigger was purely the
cudagraph mode:
- @eager_break_during_capture makes prefill attention a cudagraph break
(run eager at replay). It
reads VLLM_USE_BREAKABLE_CUDAGRAPH at module-import time.
- The env was set at runtime (generator.py:778), which is too late —
attention.py is imported
earlier and, critically, re-imported in the vLLM EngineCore worker
subprocesses, which don't
inherit a runtime-set os.environ.
- So in the workers the decorator no-op'd → prefill attention was
captured as output.fill_(0) on
all 48 layers → the model never reads the prompt.
Proven by an instrumented run: all 4 EngineCore workers showed
is_breakable=False at import;
output was garbage. Ablation isolated it to FULL_AND_PIECEWISE only
(FULL_DECODE_ONLY / eager /
All2All-with-cudagraph-off all produced correct output — All2All only
"worked" because its config
disabled cudagraph).
## The fix
Set VLLM_USE_BREAKABLE_CUDAGRAPH=1 in the generator's launch env (so
it's present at import in the
actor and every EngineCore worker), via one shared helper
breakable_cudagraph_env():
- OSS train.py — helper + threads it through the spawn bootstrap
(generator_env → extra_env →
allocate).
- mast.py — applies the same helper to the generator role.env (MAST
launches via AppDef env, not
the bootstrap).
- generate.py was already correct; generator.py:778 runtime set is now
redundant.
## Verification
FAP MoE run with the fix → all EngineCore workers is_breakable=True,
output correct
(<alphabetical_sorted>Alice, Bob, Charlie</alphabetical_sorted>).
FULL_AND_PIECEWISE is now safe
to use again.
<img width="688" height="371" alt="Screenshot 2026-06-29 at 10 08 53 PM"
src="https://github.com/user-attachments/assets/c0486530-a30f-4d61-afb5-27840e4401b7"
/>
<img width="847" height="239" alt="Screenshot 2026-06-29 at 10 25 16 PM"
src="https://github.com/user-attachments/assets/4d89ca9f-cd01-43c3-bf45-d8cbd0bc67d8"
/>
The Cudagraph break enviorment
pzhan9
added a commit
to pzhan9/torchtitan
that referenced
this pull request
Nov 3, 2026
Review feedback (tianyu-l). generator_env was added in pytorch#3829 so train.py could pass the breakable CUDA graph env var to the generator procs; pytorch#4834 removed that caller, and nothing in torchtitan or fairtitan sets it since. Remove it from MonarchActorSystem and spawn_proc_mesh, along with extra_env on PerHostProvisioner.allocate and _spawn_proc_mesh, whose only source it was.
pzhan9
added a commit
to pzhan9/torchtitan
that referenced
this pull request
Nov 3, 2026
Review feedback (tianyu-l). generator_env was added in pytorch#3829 so train.py could pass the breakable CUDA graph env var to the generator procs; pytorch#4834 removed that caller, and nothing in torchtitan or fairtitan sets it since. Remove it from MonarchActorSystem and spawn_proc_mesh, along with extra_env on PerHostProvisioner.allocate and _spawn_proc_mesh, whose only source it was.
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.
Symptom
Async-RL MoE runs (Qwen3-30B-A3B) generated fluent, coherent text that ignored the prompt → reward
never increased. E.g., asked to sort Charlie, Alice, Bob, the model rambled about "software
development / SourceGraph."
What it looked like vs what it was
It appeared MoE-/DeepEP-/HybridEP-specific and was variously suspected to be: base-vs-instruct
checkpoint, prompt rendering, or trainer→generator weight sync. All of those were ruled out:
instruction-tuned); staged Instruct-2507 failed identically under the bad config.
Root cause
The corruption was zeroed prefill attention, and it was backend-agnostic (in
rl/models/attention.py, used by dense + MoE). The trigger was purely the cudagraph mode:
reads VLLM_USE_BREAKABLE_CUDAGRAPH at module-import time.
earlier and, critically, re-imported in the vLLM EngineCore worker subprocesses, which don't
inherit a runtime-set os.environ.
all 48 layers → the model never reads the prompt.
Proven by an instrumented run: all 4 EngineCore workers showed is_breakable=False at import;
output was garbage. Ablation isolated it to FULL_AND_PIECEWISE only (FULL_DECODE_ONLY / eager /
All2All-with-cudagraph-off all produced correct output — All2All only "worked" because its config
disabled cudagraph).
The fix
Set VLLM_USE_BREAKABLE_CUDAGRAPH=1 in the generator's launch env (so it's present at import in the
actor and every EngineCore worker), via one shared helper breakable_cudagraph_env():
allocate).
the bootstrap).
Verification
FAP MoE run with the fix → all EngineCore workers is_breakable=True, output correct


(<alphabetical_sorted>Alice, Bob, Charlie</alphabetical_sorted>). FULL_AND_PIECEWISE is now safe
to use again.
The Cudagraph break enviorment