NVIDIA-NeMo/RL #5001.
All permalinks pin the PR head 5223071.
_EarlyTrainerWarmup, hung on the trainer build as a done-callback. Whether to warm up is decided twice, in setup and in the controller.Three pages on this PR. Page 1 explains all the switches; this one is only about how the warm-up (switch â‘£) is started.
| Switch (page 1) | Changed by C8? | Same speedup? |
|---|---|---|
| â‘ Build the trainer before reserving vLLM | No | Yes |
| â‘¡ Scan the dataset's Gym routes when the dataset loads | No | Yes |
| â‘¢ Keep Triton autotune results and torch.compile shape profiles between jobs | No | Yes |
| â‘£ Warm-up, setup start (while vLLM loads) | Yes: the class becomes a wait in setup | Yes: same moment, below |
| â‘£ Warm-up, controller start (beside the first rollouts) | Yes: it reads setup's decision instead of checking again | Yes: same moment |
PR head: setup thread
# setup thread, setup_single_controller (PR head) ...dataset load, and the trainer rebuild if the dataset caps max_num_steps... early_warmup = _EarlyTrainerWarmup.maybe_create(cfg, loss_fn, # None if warm-up is off or skipped; generation_future=submitted['generation']) # the skip reason is not printed if early_warmup: submitted['trainer'].add_done_callback(early_warmup.start) # start() runs later, on another thread generation = submitted['generation'].result() trainer = submitted['trainer'].result() if early_warmup: trainer_warmup_ran = early_warmup.finish() # blocks until the warm-up is done
PR head: the class it calls
# runs on whichever thread finishes the trainer build class _EarlyTrainerWarmup: def start(self, trainer_future): # the done-callback try: if gen_future is None or not gen_future.done(): # vLLM still loading? self.refs = trainer.start_warmup_first_pass(...) # non-blocking: Ray futures except Exception as e: self.error = e # a callback's errors are only logged finally: self.started.set() # threading.Event # setup thread def finish(self): self.started.wait() # result() can return before start() ran if self.error: raise self.error # re-raise on the setup thread if self.refs is None: return False # vLLM won; the controller does it ray.get(self.refs) return True
Real code: _EarlyTrainerWarmup, callback attached, finish called.
Three of the class's parts exist only because the start is a callback:
the stored error (a callback's exceptions are only logged), the threading.Event
(result() can return before the callback has run), and the class itself, which carries state between the two threads.
Two things are also written twice: the skip check (setup, silent; controller, printed)
and the step's field list (controller; trainer_warmup_kwargs).
Both helpers live in the 5,275-line single_controller.py, and setup imports them back
inside a function to avoid an import loop.
The fix, as pseudocode (proposed, not run): setup
Where the fix lands: RL only, three files. setup.py loses the class and decides once;
single_controller.py reads that decision;
advantage_stage.py holds the one field list.
No Megatron worker change: its own skip check covers model settings the driver cannot see, so it stays.
# setup thread, setup_single_controller (proposed, not run) ...dataset load, and the trainer rebuild if the dataset caps max_num_steps... early_warmup = _EarlyTrainerWarmup.maybe_create(cfg, loss_fn, ...) if early_warmup: submitted['trainer'].add_done_callback(early_warmup.start) warmup_kwargs = _trainer_warmup_kwargs(cfg, stage_cfg, step) # the only skip check; prints why gen_f, trainer_f = submitted['generation'], submitted['trainer'] refs = None if warmup_kwargs is not None: wait([gen_f, trainer_f], return_when=FIRST_COMPLETED) # sleep until one build is done if trainer_f.done() and not gen_f.done(): # same test start() makes refs = trainer_f.result()[0].start_warmup_first_pass(...) # non-blocking generation = gen_f.result() # vLLM keeps loading; warm-up runs trainer = trainer_f.result() # build errors raise here, as before if early_warmup: trainer_warmup_ran = early_warmup.finish() if refs is not None: ray.get(refs) # warm-up errors raise here, normally warmup_kwargs = None # done: nothing left for the controller class _EarlyTrainerWarmup: ... # whole class, ~80 lines, removed SingleControllerActorArgs(..., trainer_warmup_ran=trainer_warmup_ran) trainer_warmup_kwargs=warmup_kwargs) # None = off, skipped, or already run
The fix: helpers
# setup.py, new private helper (moved out of single_controller.py) def _trainer_warmup_kwargs(cfg, stage_cfg, step): if not cfg.async_rl.trainer_warmup.enabled: return None # C2's config key if reason := trainer_warmup_skip_reason(cfg, stage_cfg, step): # moved here, the one caller print('trainer warm-up skipped:', reason); return None return {'train_fields': stage_cfg.train_fields(cfg), # shared with the controller 'run_logprobs': stage_cfg.policy_logprobs_required} # advantage_stage.py: one place for the step's fields class AdvantageStageConfig: def train_fields(self, cfg): return _train_fields_for_step(...) # the expression both copies use today
Real calls it uses: start_warmup_first_pass (returns Ray futures, does not block),
trainer_warmup_skip_reason. wait and FIRST_COMPLETED are from Python's concurrent.futures; they work across the two thread pools.
The fix: controller
# controller actor, event loop (proposed, not run) self._train_fields = _train_fields_for_step(...) # copy #1 of the expression self._train_fields = stage_cfg.train_fields(cfg) _maybe_start_trainer_warmup(): # called before the pumps start if warm-up off or trainer_warmup_ran: return if reason := skip_reason(cfg): print(reason); return # skip check #2 kwargs = self._trainer_warmup_kwargs # setup's decision if kwargs is None: return task = create_task(to_thread(trainer.warmup_first_pass, **kwargs)) # beside the first rollouts # train pump, before step 1 (unchanged) await _finish_trainer_warmup() # step 1 waits for it
Real code: _maybe_start_trainer_warmup, called, awaited before step 1.
wait sits in the same place and returns at the same moment.🟡 review comment C8 — setup.py:1125
Event, no stored error and no class.
Whether to warm up is decided once and the reason is always printed; the field list is written once.
Both start places stay, because each covers a different order.
Nothing here has been run; the PR still has no timings for any switch (page 1).