Repository navigation
perf(sc): Load the training dataset while generation, Gym and the trainer start - #4596
Merged
Merged
Conversation
…iner start On the NeMo-Gym + vLLM + non-colocated path, setup_single_controller loaded the training dataset and built the dataloader before starting any worker, although no worker build needs them: generation and Gym need only URLs and the tokenizer, and the trainer needs only Megatron's train_iters. For a large data blend that load is minutes of single-threaded driver work on the startup critical path (111 s for a 22 GB blend). Start generation, Gym and the trainer first and load the dataset while they build. The trainer is built with train_iters from the unclamped max_num_steps. Once the dataset is in, the clamped value is compared; if the clamp bound (a run asking for more steps than max_num_epochs * len(dataloader) holds), the trainer is shut down and rebuilt with the right value. A new pure helper, _megatron_train_iters, computes the values without writing the config the trainer build is reading, and returns None for a model that does not train with Megatron, so a non-Megatron trainer is never rebuilt. Every other path keeps the original order. On an 86-node Nano 3.5 RLVR run (on an earlier base) this removed ~90 s of serial driver work ahead of the workers and had Megatron ready 83 s earlier. Signed-off-by: sniverty <[email protected]>
Contributor
Author
|
/ok to test 5647e21 |
Contributor
Author
|
/ok to test 9c938ec |
yfw
reviewed
Oct 16, 2026
On the overlapped path the trainer is first built with train_iters from the unclamped max_num_steps. A resume restores Megatron's LR scheduler from the checkpoint, which asserts that the saved horizon (computed from the clamped value) equals train_iters, so the first build failed before the rebuild could correct it whenever the dataset caps max_num_steps. Resumes now load the dataset first, as on main; the critic's resume paths come from the same checkpoint, so this covers PPO too. Test: a resumed Gym + vLLM run builds the trainer once, with the clamped train_iters. Signed-off-by: sniverty <[email protected]>
Contributor
Author
|
/ok to test f3c00ba |
yfw
approved these changes
Oct 16, 2026
yfw
enabled auto-merge (squash)
October 16, 2026 21:30
alexandery-nvidia
added a commit
that referenced
this pull request
Oct 16, 2026
…failures-and-redispatch main gained #4745, #4542 and #4596 since the previous merge, which put this head eleven commits behind it; the merge keeps the head within main's up-to-date rule for CI. No conflicts. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
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.
What does this PR do ?
Takes the training-dataset load off the SingleController startup critical path on the NeMo-Gym + vLLM + non-colocated path: generation, Gym and the trainer start first, and the dataset loads on the driver while they build.
Before:
setup_single_controllerloaded the dataset and built the dataloader before starting any worker, although no worker build needs them. Generation and Gym need only URLs and the tokenizer, and the trainer needs only Megatron'strain_iters. For a large data blend that load is minutes of single-threaded driver work ahead of every worker (111 s for a 22 GB blend).After, on the NeMo-Gym + vLLM + non-colocated path:
_load_training_data()runs on the driver while they build.train_iters: the trainer is built with Megatrontrain_itersfrom the unclampedmax_num_steps. Once the dataset is in, the clamped value (max_num_epochs * len(dataloader)) is compared. If the clamp bound (the run asked for more steps than its data holds), a warning is printed and the trainer (and PPO critic) is shut down and rebuilt with the right value. In the normal case they match and nothing is rebuilt._megatron_train_iters, computes the values without writing the config the trainer build is reading on another thread._maybe_inject_megatron_train_itersnow uses it. It returnsNonefor a model that doesn't train with Megatron, so a non-Megatron trainer is never rebuilt.Issues
Usage
No new configuration; the change applies automatically on the NeMo-Gym + vLLM + non-colocated path. When
max_num_stepsexceeds what the data holds, startup logs:Before your PR is "Ready for review"
Pre checks:
Additional Information
New tests (
tests/unit/single_controller/test_setup.py):test_megatron_train_iters_helper_reads_without_writing: the helper doesn't write the config, and returnsNonewhen Megatron is off.test_gym_vllm_loads_dataset_while_trainer_builds: the mocked dataset load waits for the trainer build to start, so the old order (load first) would fail.test_native_path_loads_dataset_before_building: other paths keep the original order.test_gym_vllm_keeps_speculative_trainer_when_clamp_does_not_bind: one trainer build, with the speculativetrain_iters.test_gym_vllm_rebuilds_trainer_when_clamp_binds:train_iters1000 → 8, the stale trainer shut down, the warning printed.test_gym_vllm_dataset_load_failure_shuts_down_gym: a load failure on the new path re-raises and shuts Gym down.The existing
test_nemo_gym_wires_env_handlealso runs the changed path and checks thatvalidate_dataset_agent_coveragestill receives both datasets.Measured with the same change on an earlier NeMo-RL base (Nano 3.5 RLVR, 86 nodes, NeMo-Gym with external judge pools):