Skip to content

[rl] fix the breakable cudagraph env var - #3829

Merged
tianyu-l merged 1 commit into
mainfrom
qwen3-8b-batch-invariant
Jun 30, 2026
Merged

tianyu-l merged 1 commit into
mainfrom
qwen3-8b-batch-invariant

Conversation

@wwwjn

@wwwjn wwwjn commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

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.
Screenshot 2026-06-29 at 10 08 53 PM
Screenshot 2026-06-29 at 10 25 16 PM

The Cudagraph break enviorment

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 30, 2026
@tianyu-l
tianyu-l requested a review from pzhan9 June 30, 2026 02:14

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

stamping to unblock, but should follow up with @pzhan9 to see if this is the proper way

@tianyu-l
tianyu-l merged commit 9e4a851 into main Jun 30, 2026
15 of 23 checks passed
@tianyu-l
tianyu-l deleted the qwen3-8b-batch-invariant branch June 30, 2026 03:42
@pzhan9

pzhan9 commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

stamping to unblock, but should follow up with @pzhan9 to see if this is the proper way

@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 SetupActor on this proc mesh, and run the provisioner.allocate function inside that actor. Since this happens before the VllmGenerator actor is spawned, that will make sure VLLM_USE_BREAKABLE_CUDAGRAPH env var is set up before any VllmGenerator's modules being imported.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants