Support bounded distributed-optimizer main initialization - #86
Open
zianglih wants to merge 2 commits into
Open
Conversation
ziang-and
force-pushed
the
ziang/bounded-main-param-initialization
branch
from
August 20, 2026 23:23
0c35bad to
d7f63a0
Compare
zianglih
marked this pull request as ready for review
August 21, 2026 06:24
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 ?
@HumansAnd
Add one opt-in constructor primitive for external optimizer-state backends: retain stable distributed-optimizer FP32 main-param tensor handles without retaining the cumulative FP32 main state in HBM.
OptimizerConfig.defer_main_param_initializationdefaults toFalse; the ordinary path still usesshard_model_param.clone().float().+47/-0; no unrelated formatter changes and no addedtry,except, orfinallyblocks.This extends the integration point used by optimizer-state streaming from radixark/Megatron-LM#63. NVIDIA/Megatron-LM#6544 is related draft work on chunked optimizer-state offloading; this PR deliberately leaves storage policy outside Megatron core.
Paired PR
54f083eb0530e47fce951d2fba243c0d64038cb8.--stream-optimizer-state-to-diskis on, then initializes one existing runtime bucket at a time directly in its final files.Validation
Exact-head public-image B300 tests
docker.io/radixark/miles:dev-202608210021@sha256:e2e25e4121c595d352933fab81ce05cc8fb2aef8c8478a16abc704b51e330003.2.11.0+cu130; CUDA13.0.PYTHONPATHcontained only the synced public Miles and Megatron source roots; both imports were asserted to resolve there. The image needed test-onlymock==5.2.0for the Megatron unit-test module.20260821T051726Z.tightened-clean.log, SHA-256511b5a047716f8618d75f9aff89d96a0e00b1929093f56906f2499f6e636b1c9.Commands:
Raw output:
The Megatron test verifies that model and optimizer retain the same main-param tensor objects with nonzero logical size, FP32 CUDA metadata, and zero backing storage. The Miles test verifies exact BF16-to-FP32 bytes after initializing those handles into final storage and confirms the CUDA storage is released again.
Repository checks
File-wide Black/isort were not applied because the upstream file is not in their current canonical form and doing so introduces unrelated import and line-wrap changes. The submitted diff keeps the baseline formatting untouched.
Exact-head full-Miles four-node constructor validation
Run
20260821T060606Zexercised this exact Megatron head through the production Miles initialization path:miles/train.py --debug-train-only->RayTrainGroup-> 32MegatronTrainRayActor.initcalls ->initialize_model_and_optimizer-> paired deferred construction and NVMe initialization.docker.io/radixark/miles:dev-202608210021@sha256:e2e25e4121c595d352933fab81ce05cc8fb2aef8c8478a16abc704b51e330003; four C2 nodes; 32 NVIDIA B300 GPUs.5dcbc1020a94ea973316163e8db6719886823e63; Miles54f083eb0530e47fce951d2fba243c0d64038cb8; harnessbbb6b2df9643b7a06ec44d3f0a1488677d4491d6.Reproduction:
cd /Users/ziangli/playground/projects/upstream-optimizer-main-init-streaming/public_miles_debug_train_glm5_pp1_streaming ./launch_c2.sh provision ./launch_c2.sh sync ./launch_c2.sh ray ./launch_c2.sh prepare ./launch_c2.sh runFinal gate object:
{ "status": "pass", "checks": { "ray_job_exit_zero": true, "no_timeout": true, "no_cuda_oom": true, "no_host_oom": true, "no_disk_full": true, "native_store_records_64": true, "native_initialization_records_64": true, "unique_store_paths_64": true, "unique_initialization_paths_64": true, "store_and_initialization_paths_match": true, "all_32_ranks_have_dense_and_expert_stores": true, "zero_optimizer_streaming_steps": true, "zero_training_iterations": true, "scoped_optimizer_cleanup_succeeded": true } }Artifact integrity:
This is an initialization-only production-Miles test:
--num-rollout 0deliberately produced no forward pass, optimizer step, training iteration, or checkpoint operation.Predecessor two-step GLM-5.2 scale evidence
Run
20260821T001150Zexercised the same deferred-handle and direct-final bucket mechanism on a broader predecessor: Megatrond7f63a091dbe566c2fd8dfd7b7b34cb8821235c7with Miles1697c45ec3973376fdf7c0f0e3fa41aaf8f48682.docker.io/radixark/miles:dev-202608200558@sha256:89d2278b083c32d4e794df27aa266cb085a74d0b0bce0b09eab05eddaa972322; four C2 nodes; 32 NVIDIA B300 GPUs.(rank, store, step)events completed; no CUDA OOM, host OOM, ENOSPC, timeout, skipped iteration, or NaN.This scale run is mechanism and dense/expert-chain evidence, not an exact-current-head run. The current heads are covered by the focused public-image tests above; the tightened commits removed validation, formatter, checkpoint, path, lifecycle, and failure-handling changes while retaining the successful constructor mechanism.
Remaining limitations
Contribution process
flowchart LR A[Pre-checks] --> B[PR Tests] subgraph Code Review/Approval C1[Expert Review] --> C2[Final Review] end B --> C1 C2 --> D[Merge]Pre-checks
Core 0.8)Code review
The following process is enforced via the CODEOWNERS file for changes into
megatron/core. For changes outside ofmegatron/core, it is up to the PR author whether or not to tag the Final Reviewer team.For MRs into `main` branch
Feel free to message or comment the @mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
(Step 1): Add PR label
Expert Review(Step 2): Collect the expert reviewers reviews
Expert Reviewlabel when your PR is ready for review.Final Review might get declined if these requirements are not fulfilled.
(Step 3): Final Review
Final Reviewlabel(Optional Step 4): Cherry-pick into release branch
If this PR also needs to be merged into
core_r*release branches, after this PR has been merged, selectCherry-pickto open a new PR into the release branch.For MRs into `dev` branch
The proposed review process for `dev` branch is under active discussion.MRs are mergable after one approval by either
eharper@nvidia.comorzijiey@nvidia.com.Merging your PR
Any member of core-adlr and
core-nemowill be able to merge your PR.