Repository navigation
refactor(training): initialize runtime services after config validation - #8272
Conversation
Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Chen Cui <chcui@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
cuichenx
left a comment
There was a problem hiding this comment.
the important two refactors are
| ) | ||
|
|
||
| # Runtime services consume the validated config, before distributed/RNG setup. | ||
| initialize_runtime_services(args, build_tokenizer=build_tokenizer, training=training) |
|
|
||
| if build_tokenizer: | ||
| _build_tokenizer(args) | ||
| resolve_tokenizer_vocab_size(get_run_config(), getattr(args, "padded_vocab_size", None)) |
There was a problem hiding this comment.
before, this wasn't always running every time initialize_runtime_services() was called. is it fine to do that now? should it be on some condition, eg if build_tokenizer or if build_tokenizer and training ?
| skip_model_parallel_init=True, | ||
| p2p_communicator=communicator, | ||
| pg_collection=topology.schedule_pg_collection, | ||
| build_tokenizer=False, |
There was a problem hiding this comment.
note for later, this should be handled by a cfg.tokenizer=None
maanug-nv
left a comment
There was a problem hiding this comment.
just 1 minor question.
|
|
||
| if build_tokenizer: | ||
| _build_tokenizer(args) | ||
| resolve_tokenizer_vocab_size(get_run_config(), getattr(args, "padded_vocab_size", None)) |
There was a problem hiding this comment.
before, this wasn't always running every time initialize_runtime_services() was called. is it fine to do that now? should it be on some condition, eg if build_tokenizer or if build_tokenizer and training ?
maanug-nv
left a comment
There was a problem hiding this comment.
addressed offline. good to merge now.
Signed-off-by: Chen Cui <chcui@nvidia.com>
| assert cfg_container is not None | ||
|
|
||
| _ensure_var_is_not_initialized(_GLOBAL_ARGS, 'args') | ||
| cfg_container.validate() |
There was a problem hiding this comment.
There are a couple config in the inference container that are environment-dependent: --inference-kv-cache-management-mode and --inference-static-kv-memory-pointers. They both require torch_memory_saver to be installed under some of the argument values.
This validation check leads to an odd case, where a checkpoint that was RL-trained on a machine that has torch_memory_saver can fail validation if the checkpoint is loaded on a machine without torch_memory_saver.
I think that before this PR, most codepaths already did validation and would encounter this issue. But I see that tools/checkpoint/convert.py specifically did not validate before this, and this is new behavior.
I don't think this is a problem. But I'm noting it down here, because it's a strange interaction.
Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Chen Cui <chcui@nvidia.com>
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/39110341563 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/39157400748 |
…tion config migration Merge main including NVIDIA#8272. Resolve batch defaults during one-time finalization, keep repeated validation read-only, and consume config-owned batch policy throughout training. Signed-off-by: Chen Cui <chcui@nvidia.com>
Resolve conflicts with the runtime-services refactor (NVIDIA#8272), the config validate/finalize split, and disaggregated inference process groups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com>
Repair main-to-dev sync compatibility for the 2026-10-20 slice (main 13a9d46 merged into dev ff4fbc9): - moe/router: InferenceTopKRouter._compiled_topk_routing accepts and forwards precomputed_indices, matching the base router call site. - tensor_parallel/random: MHCCheckpointManager subclasses CheckpointWithoutOutputManager so main's checkpoint consumers accept it. - moe/token_dispatcher: _HybridEPManager.setup_metadata clears the stale num_permuted_tokens budget when no capacity factor is configured. - tests: align dev-only tests with main API changes (test_training TrainingConfig and TrainState, test_mhc_schedule _model_chunk_state, test_hybrid_hash_routing tensor_parallel import, test_route_metadata_cpu token_dispatcher fake, MTP argmax acceptance-count test). - tests: test_train_step_schedule_plumbing provides the cfg.train, cfg.validation, cfg.ddp and TrainState inputs main's train_step and setup_model_and_optimizer now read. - tests: test_virtual_experts quantile cases select the micro_batch estimation scope that main's quantile estimator implements; the merged default keeps dev's global_batch scope. - tests/test_utils/recipes/gb200/unit-tests.yaml: drop the duplicated tests/unit_tests/ssm/test_gated_delta_net.py bucket produced by the merge, restoring the one-bucket-per-file unit-test scope contract. - tests: test_hybrid_distillation_entry expects the multimodal_dev entry point to leave runtime services and tokenizer vocabulary resolution to initialize_megatron, which main NVIDIA#8272 made their owner. - examples/mimo_bagel/train.py: read the training iteration from get_train_state() for the PP>1 data seed and the loss-alignment audit log, because main NVIDIA#7932 no longer sets args.curr_iteration or args.iteration (review 5609274485). - pyproject.toml: carry main NVIDIA#7494's [tool.setuptools.package-data] entry so wheel and sdist installs ship megatron/core/allocator/csrc/vmm_symm_allocator.cpp (review 5609274485). Signed-off-by: svcnemo-autobot <svcnemo-autobot@nvidia.com>
Repair main-to-dev sync compatibility for the 2026-10-20 slice (main 0156c21 merged into dev ae76c60): - moe/router: InferenceTopKRouter._compiled_topk_routing accepts and forwards precomputed_indices, matching the base router call site. - tensor_parallel/random: MHCCheckpointManager subclasses CheckpointWithoutOutputManager so main's checkpoint consumers accept it. - moe/token_dispatcher: _HybridEPManager.setup_metadata clears the stale num_permuted_tokens budget when no capacity factor is configured. - tests: align dev-only tests with main API changes (test_training TrainingConfig and TrainState, test_mhc_schedule _model_chunk_state, test_hybrid_hash_routing tensor_parallel import, test_route_metadata_cpu token_dispatcher fake, MTP argmax acceptance-count test). - tests: test_train_step_schedule_plumbing provides the cfg.train, cfg.validation, cfg.ddp and TrainState inputs main's train_step and setup_model_and_optimizer now read. - tests: test_virtual_experts quantile cases select the micro_batch estimation scope that main's quantile estimator implements; the merged default keeps dev's global_batch scope. - tests/test_utils/recipes/gb200/unit-tests.yaml: drop the duplicated tests/unit_tests/ssm/test_gated_delta_net.py bucket produced by the merge, restoring the one-bucket-per-file unit-test scope contract. - tests: test_hybrid_distillation_entry expects the multimodal_dev entry point to leave runtime services and tokenizer vocabulary resolution to initialize_megatron, which main NVIDIA#8272 made their owner. - examples/mimo_bagel/train.py: read the training iteration from get_train_state() for the PP>1 data seed and the loss-alignment audit log, because main NVIDIA#7932 no longer sets args.curr_iteration or args.iteration (review 5609274485). - pyproject.toml: carry main NVIDIA#7494's [tool.setuptools.package-data] entry so wheel and sdist installs ship megatron/core/allocator/csrc/vmm_symm_allocator.cpp (review 5609274485). Signed-off-by: svcnemo-autobot <svcnemo-autobot@nvidia.com>
What does this PR do?
Move runtime-service initialization into
initialize_megatron(), after run-config validation and before distributed/RNG setup.pretrain(); inference entrypoints callinitialize_megatron()without separately constructing runtime services.build_tokenizer=Falsefor heterogeneous MiMo, which supplies its own tokenization.Most entrypoint changes remove the old explicit runtime/vocabulary calls and their imports. This does not change config ownership, training/inference selection, or distributed/RNG behavior.
This is the separate startup-order follow-up discussed in #7778; #7778 does not depend on it. Pending #7778 and #8149 changes will need to be merged here once they land.
Issue tracking
Related to #3554 and #7778.
Contribution process
Pre-checks
jit_fuser/torch.compile, CUDA extension, TE or external-library dispatch, or a scatter/index accumulation), I have added or updated its bit-exact determinism test and registered it intests/unit_tests/determinism/kernels/manifest.pyValidation at
77521cccbe1451984d949873ccc647ec34e9bc45: 405 targeted tests passed on each of two GPU ranks across argument adapters, initialization lifecycle, inference, RNG, profiling, kernel warmup, autotuning, run config, and container validation. Existing lifecycle tests cover validation before side effects, tokenizer-derived/explicit/checkpoint vocabulary, tokenizer suppression, and the RL entrypoint's single initialization boundary. Independent full-diff review completed.Changed-test formatting and diff checks pass. The all-files pre-commit run reports existing lint/format issues in untouched files; those are left unchanged to keep this diff focused.
Code review
Draft for startup-order review. No GPU kernels or numerical operations changed.