What the four startup switches in #5001 move earlier, and what still runs in order

NVIDIA-NeMo/RL #5001 (builds on the Megatron compile cache from #4715). All permalinks pin the PR head 5223071.

Before
Single-controller setup reserves the vLLM workers first, then builds vLLM, NeMo-Gym and the trainer side by side. It checks the dataset's Gym routes only after Gym is up. Every job's first training step pays for torch.compile and Triton autotuning from scratch.
This PR
Four switches, all off by default, set as environment variables: start the trainer earlier, scan routes earlier, keep compile results between jobs, and run a fake first step ahead of time.
Status
New and opt-in. The review is still pending. It asks to turn two switches on for everyone with no flag, and to make the warm-up a config key (C2). It also it found a crash in the warm-up switch when CUDA graphs are on (page 2).

Three pages on this PR. This one shows the feature. Page 2 shows a crash the review found in it; page 3 proposes a simpler way for setup to start the warm-up.

Where this sits. Only the v2 single-controller path reads these switches. The v1 driver loops (grpo_train, async_grpo_train, PPO, distillation) do not. The early trainer build and the early route scan need NeMo-Gym with vLLM on separate GPUs. The warm-up needs a Megatron trainer. Dotted words have a short explanation: hover or tap them.
mainthis PRafter the review's fixes (proposed)
v1 (driver loops)no switchesunchangedunchanged
v2 (single controller)no switches4 switches as NRL_* env vars, off by default① and ② always on where they apply, no flag. ④ becomes an async_rl config key, off by default. ③ stays env vars (C2). The warm-up skips CUDA-graph runs and restores RNG state in place (C1).
# how you turn them on in this PR: driver environment, passed to every Ray actor export NRL_EARLY_TRAINER_SUBMIT=1 # ① build the trainer earlier export NRL_OVERLAP_ROUTE_SCAN=1 # ② scan the dataset's Gym routes earlier export NRL_MEGATRON_TRITON_CACHE_AUTOTUNING=1 # ③ keep Triton autotune results ... export NRL_MEGATRON_TORCH_COMPILE_JOB_ID=my-run # ③ ... and torch.compile shape profiles export NRL_TRAINER_WARMUP=1 # ④ fake first step while setup or rollouts run # proposed in review comment C2, not in the PR: # ① and ② have no reason to be off, so they lose their flags and always run where they apply # ③ stays env vars, next to the compile cache from #4715 # ④ becomes config, off by default until it has a test (C3) and works with CUDA graphs (C1) async_rl: trainer_warmup: {enabled: false, seqlens: null}

Startup, before and after

main: switches off bar lengths are not to scale; the PR gives no timings setup thread vLLM NeMo-Gym dataset trainer controller reserve routes + sync load weights, start servers spin up servers load dataset build Megatron trainer first rollouts step 1: autotune + compile step 1 ends this PR: all four switches on setup thread vLLM NeMo-Gym dataset trainer controller reserve ② scan check+sync load weights, start servers spin up servers load dataset ① build trainer, earlier ④ warm-up first rollouts ③ step 1, cached step 1 ends sooner moved earlier or made cheaper by a switch unchanged the cost the switches attack

What each switch does, step by step

  1. ① Early trainer build. Setup starts building the trainer on its own thread before it reserves the vLLM workers, instead of in the task pool afterwards. It only applies to runs that already load the dataset alongside the other builds (NeMo-Gym, vLLM on separate GPUs, no resume) and set cluster.segment_size. In any other run it prints a warning and is ignored. Cost: Ray creates the trainer and vLLM actors at the same time, which adds load on its control service.
  2. ② Early route scan. Each dataset row names the Gym route it needs. The PR collects those names as soon as the dataset loads, e.g. {"train": {"alpha", "beta"}} in the PR's test. Once Gym is up, the coverage check only compares sets. A split whose routes only the running Gym knows (taskset rows) is still scanned at check time.
  3. ③ Compile results kept between jobs. The two variables are passed to the Megatron workers as Triton's and torch's own TRITON_CACHE_AUTOTUNING and TORCH_COMPILE_JOB_ID. The cache sync script then also publishes torch's per-rank shape profiles. They only do anything when the persistent compile cache from #4715 is on. Kernels whose autotune configs have a pre_hook are still benchmarked in every job.
  4. ④ Trainer warm-up. Each Megatron rank runs one logprob pass and one forward/backward on a fake batch. For the 1B math example the default lengths are [512, 512, 512, 512] tokens (max length 512, packing budget 4 × 512). Then it undoes what a real step would read: no optimizer step, gradients dropped, metric trackers and RNG reset. If the trainer is ready before vLLM, setup runs it right away. Otherwise the controller runs it alongside the first rollouts, and the train pump waits for it before step 1.

🟡 review comment C2 — setup.py:2020   🟡 review comment C3 — megatron_policy_worker.py:2711

So what. Nothing changes unless you set a switch. Switches ① and ② only move work earlier. ③ and ④ make step 1 cheaper, but they can also stop a run before step 1:

The PR gives no before/after timings yet. The review asks for time to the end of step 1, with each switch on and off.

The review comments linked above are part of a pending review, so they open only for its author until the review is published.