Skip to content

perf(sc): opt-in switches that shorten startup and the first training step - #5001

Merged
terrykong merged 1 commit into
NVIDIA-NeMo:mainfrom
sarichardson-nv:sarichardson/sc-startup-switches-pr
Nov 20, 2026
Merged

terrykong merged 1 commit into
NVIDIA-NeMo:mainfrom
sarichardson-nv:sarichardson/sc-startup-switches-pr

Conversation

@sarichardson-nv

@sarichardson-nv sarichardson-nv commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Shortens single-controller startup and the first training step: two opt-in config keys, cached Megatron autotuning, and an early route scan that is always on.

  • Early trainer build (async_rl.early_trainer_build: true, off by default): builds the trainer while setup creates the vLLM workers, not after. Needs NeMo-Gym, non-colocated vLLM, no resume and cluster.segment_size; otherwise setup warns and ignores it.
  • Early route scan (always on for NeMo-Gym runs, no setting): reads the dataset's NeMo-Gym routes during the setup tasks, not after. The coverage check is unchanged.
  • Cached Megatron autotuning and shape profiles (NRL_MEGATRON_TRITON_CACHE_AUTOTUNING=1, NRL_MEGATRON_TORCH_COMPILE_JOB_ID=<id>): keeps Triton autotune results and torch.compile shape profiles in the perf: Dblanaru/persistent compile caches #4715 Megatron compile cache, so later jobs skip the autotuning and the fixed-shape compiles. Needs the same id in every run and the Megatron inductor and Triton caches under ${NRL_LOCAL_COMPILE_CACHE}/megatron; kernels with an autotune pre_hook are still benchmarked in every process.
  • Trainer warm-up (async_rl.trainer_warmup.enabled: true, off by default; optional async_rl.trainer_warmup.seqlens): each Megatron rank runs one logprob pass and one forward/backward on a synthetic batch while generation starts or the first rollouts run, then resets the state a real step reads. The optimizer step is not warmed; unsupported setups, listed in docs/guides/single-controller.md, skip it and log why.

Other

  • With both keys off and the compile-cache variables unset, three changes still apply: the early route scan, vLLM generation-config writes move into _apply_vllm_generation_config, and ClippedPGLossFn is built before the setup tasks.
  • The early trainer build creates the trainer and vLLM actors at once, adding load on the Ray GCS.
  • The warm-up allocates full-size microbatches, so an out-of-memory error or a failed warm-up stops the run before step 1.
  • Concurrent jobs sharing a compile job id overwrite each other's shape profiles.

Issues

Builds on #4715 (merged).

Usage

The early trainer build and the warm-up are config keys, both off by default:

async_rl:
  early_trainer_build: true
  trainer_warmup:
    enabled: true
    seqlens: null  # optional; null fills two microbatches near the microbatch token budget

The compile-cache settings stay environment variables, next to the rest of the #4715 compile cache. Set them in the driver's environment before launching:

export NRL_MEGATRON_TRITON_CACHE_AUTOTUNING=1
export NRL_MEGATRON_TORCH_COMPILE_JOB_ID=my-grpo-run

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

@copy-pr-bot

copy-pr-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 30, 2026
@snivertynv snivertynv added the CI:L1 Run doctests, unit tests, and functional tests label Nov 3, 2026
@sarichardson-nv

sarichardson-nv commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

@terrykong Hey I just wanted to mention that this PR depends on #4715 . Note in original PR, although wanted to flag it so it doesn't cause confusion later on.

@sarichardson-nv
sarichardson-nv force-pushed the sarichardson/sc-startup-switches-pr branch from 673d61e to 6e2c566 Compare November 5, 2026 05:49
@terrykong terrykong added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Nov 5, 2026
@sarichardson-nv
sarichardson-nv force-pushed the sarichardson/sc-startup-switches-pr branch from 6e2c566 to 5223071 Compare November 12, 2026 01:03
@sarichardson-nv

Copy link
Copy Markdown
Contributor Author

#4715 has merged, so this PR is now a single commit.

  • Sampler replay (#5006) is new on main since the last push; like score centering, it needs sampler data recorded during generation, so the trainer warm-up skips it with a logged reason.
  • +Docs: a job whose ranks start from shape profiles saved at different points of an earlier run can hang on its first step; unset the job id if it does.

@Connor-XY Connor-XY left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Read through this with an eye on the compile-cache parts, since we've been doing similar persistent-cache work on the Megatron side for pretraining and SFT startup.

The startup switches look reasonable to me, and keeping everything opt-in with only the two refactors on by default makes this easy to take. Most of my comments are about NRL_MEGATRON_TORCH_COMPILE_JOB_ID.

  1. Shape profiles break the cache's "published files never change" rule, and that's what causes the first-step hang in the docs. The sidecar pushes each rank's code_state_*.pkl with rsync --update every 60 s, per node and per file. The next job can start with rank 0's profile from minute 5 and rank 7's from minute 40. Those ranks then make different static/dynamic decisions, compile different graphs, and the collectives stop lining up. I don't think "unset the job id if it hangs" is enough here. Could the profiles be published once, as a full set, after the job has finished at least one good step (or only on the final write-back pass), into a directory named for that job? Then a later job either gets all ranks from the same point or none.

  2. The job id is the only cache key. If someone keeps the same id but changes TP/PP/EP, world size, or the container, ranks will load profiles recorded for a different layout without any warning. Could the key be derived from (or at least checked against) the parallel config, world size and image? I'd make the user-supplied id an extra suffix on top of that.

  3. Autotune caching won't help Mamba-hybrid models much. As the comment in compile_cache.py says, Triton skips the disk cache for any kernel whose configs have a pre_hook. The mamba_ssm SSD kernels use init_to_zero pre_hooks, so on hybrid models (Nemotron-H/NT-style) most of the autotune time comes back every job. It's fine to land the passthrough as is, but please say this in the docs so nobody expects a big step-1 drop on those models. We patched around this on our side and can share notes if useful.

  4. Determinism. The pre_hook kernels are still timed per process, so ranks can pick different configs within a run. That's the same mechanism we traced a cross-run determinism break to at 24+ nodes. Cached kernels now take their config from whichever node published first, so a run's numerics depend on the cache's history. That's probably fine for RL, but it's worth one line in the docs. It should also be skipped or warned about when deterministic mode is on.

  5. Warm-up and shape profiles together. The synthetic warm-up seqlens get recorded into the dynamo profile too, which can mark dims dynamic or cause recompiles on the first real shapes. Has the combination of NRL_TRAINER_WARMUP=1 and the compile job id been run?

Smaller things are inline. Also the "ran unit/functional tests" box is still unchecked. Do you have a before/after on time-to-end-of-step-1 for each switch? That would make it easier to decide which ones are worth turning on by default later.

Comment thread nemo_rl/utils/cache_sync.sh Resolved
Comment thread nemo_rl/utils/compile_cache.py Resolved
Comment thread nemo_rl/utils/compile_cache.py Resolved
Comment thread docs/guides/single-controller.md Resolved

@terrykong terrykong left a comment

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.

Thanks for the docs table and for making each switch skip itself safely where it does not apply.

  1. (C1) With the warm-up and Megatron CUDA graphs on, the RNG save crashes before step 1. Once that is fixed, the warm-up would capture CUDA graphs on synthetic shapes. Skip the warm-up when CUDA graphs are on, restore the RNG states in place, and add a test.
  2. (C2) Remove the flags for the early route scan and the early trainer build, and always do both where they apply. Make the warm-up an async_rl.trainer_warmup config key, off by default.
  3. (C3) Turn the warm-up on in the fast L1 run of grpo_async_gym_single_controller.sh, and fail the test if the warm-up was skipped.
  4. (C8) Replace _EarlyTrainerWarmup with a wait in setup. Decide once whether the warm-up runs, and keep one copy of the step's field list.

The replies on Connor's threads (C4–C7) add to his points. +1 to his ask for before/after time to the end of step 1 for each switch.

Explainers: what the switches change · warm-up crash with CUDA graphs · warm-up without a callback

Generated by Claude Code

Comment thread nemo_rl/utils/cache_sync.sh Resolved
Comment thread nemo_rl/utils/compile_cache.py Resolved
Comment thread nemo_rl/utils/compile_cache.py Resolved
@sarichardson-nv
sarichardson-nv force-pushed the sarichardson/sc-startup-switches-pr branch from 5223071 to a5e6469 Compare November 18, 2026 08:16
@sarichardson-nv

Copy link
Copy Markdown
Contributor Author

a5e6469 committed with changes for @Connor-XY feedback. Not yet resolved @terrykong points yet.

Shape profiles break the cache's "published files never change" rule

The sidecar no longer publishes shape profiles. The trainer saves every rank's profile as one set, in a folder named for the job and step, after steps 1, 2, 4, 8, … when a profile changed and the step succeeded on every rank. Rank 0 writes the set's manifest last and sets without one are never read, so a later job loads all ranks from one set or none. The "unset the job id" advice is gone from the docs.

The job id is the only cache key.

Sets are stored under the job id, the user and a hash of the model, TP/PP/CP/SP/EP/ETP, first/last pipeline stage sizes, world size and torch version, so reusing an id after any of those change starts without a profile. The image isn't in the hash: torch matches each profile entry to its code by a hash of the source file, so entries recorded against other code aren't applied.

Autotune caching won't help Mamba-hybrid models much.

Triton still benchmarks kernels whose autotune configs carry a pre_hook in every process, as with the mamba_ssm SSD kernels (init_to_zero), so hybrid Mamba models gain less from cached autotune results. Notes on your patch would be helpful 😄

Determinism.

A kernel runs the config of whichever job tuned it first, which a job without the cache may not pick. The trainer warns about this when cached autotuning is on with zero_train_gen_mismatch or batch_invariant_mode.

Has the combination of NRL_TRAINER_WARMUP=1 and the compile job id been run?

Not on GPUs at this commit. The warm-up never saves a set: the first one is saved after step 1, so it holds the real shapes as well as the warm-up's, and a later job compiles any dim that varied across them as dynamic from the start. The default warm-up packs two microbatches of different sizes, so torch.compile meets its second shape there rather than in step 1.

@sarichardson-nv
sarichardson-nv force-pushed the sarichardson/sc-startup-switches-pr branch from a5e6469 to 1d8741f Compare November 19, 2026 10:44
@snivertynv

Copy link
Copy Markdown
Contributor

/ok to test 1d8741f

@sarichardson-nv
sarichardson-nv force-pushed the sarichardson/sc-startup-switches-pr branch 2 times, most recently from 960af81 to dc19a26 Compare November 19, 2026 14:19
@sarichardson-nv

Copy link
Copy Markdown
Contributor Author

/ok to test dc19a26

1 similar comment
@snivertynv

Copy link
Copy Markdown
Contributor

/ok to test dc19a26

terrykong
terrykong previously approved these changes Nov 19, 2026
@terrykong
terrykong enabled auto-merge (squash) November 19, 2026 18:33
auto-merge was automatically disabled November 20, 2026 14:20

Head branch was pushed to by a user without write access

@sarichardson-nv
sarichardson-nv force-pushed the sarichardson/sc-startup-switches-pr branch from dc19a26 to 47785ee Compare November 20, 2026 14:20
@sarichardson-nv

Copy link
Copy Markdown
Contributor Author

47785ee is dc19a26 rebased onto current main, plus a test fix for the Megatron policy unit tests. test_worker_initialization_preserves_only_restored_rng runs the real MegatronPolicyWorkerImpl.__init__ with a compile_cache stub that only had seed, but this PR's __init__ also uses compile_cache.ShapeProfiles.load, compile_cache.warn_if_autotuning_is_shared, _SHAPE_PROFILE_LAYOUT and config["model_name"]. The test now provides those. No other changes.

@terrykong
terrykong enabled auto-merge (squash) November 20, 2026 14:42
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test 47785ee

@terrykong
terrykong merged commit 9a7640c into NVIDIA-NeMo:main Nov 20, 2026
102 checks passed
zyzhou5 added a commit to zyzhou5/RL that referenced this pull request Nov 20, 2026
…ting

Resolve one conflict with NVIDIA-NeMo#5001 in validate_dataset_agent_coverage: keep
main's precomputed agent names and pass multi_harness when a split is
scanned here. Taskset rows are always scanned here, since main's
precomputed scan skips them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants