Repository navigation
feat(megatron): support fractional optimizer CPU offload - #3628
Conversation
Signed-off-by: seonjinn <[email protected]>
Signed-off-by: seonjinn <[email protected]>
Signed-off-by: seonjinn <[email protected]>
|
Self-review ( Resolved findings:
Direct Ruff, formatting, YAML parsing, Python compilation, and config validation checks pass. The remaining readiness gate is the Linux/GPU functional and off/50%/100% performance validation; the PR remains draft until that evidence is attached. |
|
/ok to test 60b5c93 |
Signed-off-by: seonjinn <[email protected]>
|
/ok to test 640283b |
Signed-off-by: seonjinn <[email protected]>
|
/ok to test cf3cfd8 |
Signed-off-by: seonjinn <[email protected]>
|
/ok to test 04f286f |
Signed-off-by: seonjinn <[email protected]>
|
/ok to test 71ae2ed |
Optimizer CPU Offload A/B ResultsResultCW job
The slowdown remains stable when the analysis begins at steps 21, 41, or 61. Interpretation
Configuration
Provenance
|
Signed-off-by: seonjinn <[email protected]>
|
/ok to test 11104a9 |
…fload-20260813 Signed-off-by: seonjinn <[email protected]>
|
/ok to test ee766da |
Signed-off-by: seonjinn <[email protected]>
Signed-off-by: seonjinn <[email protected]>
|
/ok to test 788fcf0 |
Signed-off-by: seonjinn <[email protected]>
|
Contributor self-review refresh for An independent source audit found no actionable correctness issues in optimizer offload validation, policy/value lifecycle handling, defaults, or docs. Ruff/format/config checks pass locally. Residual validation: rerun the 0%/50%/100% GPU matrix on the current Bridge/MCore pins and add checkpoint save/resume coverage; the earlier performance run used older dependency pins. |
Signed-off-by: seonjinn <[email protected]>
|
/ok to test c599b31 |
terrykong
left a comment
There was a problem hiding this comment.
Reviewed by an agent team (6 reviewers plus an adversarial pass), checking every Megatron Core claim against the pinned SHA d12f6c8c9aff51e166d872fd70151687a8e3f375.
No action items — the two things we would have raised you already fixed yourself in 788fcf0 (dropping the , False call-site default from the .get(), and deleting the redundant optimizer_kwargs.setdefault(...)), which is also what config-conventions asks for. The added adam/sgd guard there is right too: Megatron Core only wires CPUAdam/CPUSGD into the hybrid optimizer, so anything else would have failed obscurely.
Thanks for the validation write-up — the 100-step A/B with an explicit measurement window, the note superseding the 8-step pilot, and the finite-loss check made this much easier to review.
Context — no action. Things we verified and deliberately are not raising, in case it saves a round trip:
- The
optimizer_cpu_offload→use_distributed_optimizerguard is correct and worth keeping. The combination it rejects fails with aKeyErroron the first optimizer step:Float16OptimizerWithFloat16Params.__init__overwrites theHybridDeviceOptimizer's ownparam_groupswith fresh fp32 clones (optimizer.py#L1018), while HDO keyedparam_to_inner_paramon the original tensors (hybrid_optimizer.py#L189) andstep()looks them up unguarded (#L339). Your docs sentence about the "parameter mapping" is accurate. - Removing
assert optimizer_offload_fraction == 1.0is right: Megatron Core has always accepted arbitrary fractions (HDO's own default is0.5) and range-checks the field nowhere, so your0 < f <= 1check is the only validation that exists. _force_sync_optimizer_fp32_from_modelstays correct atf<1— it iterates the HDO maps rather than assuming full coverage, and the precision-aware on/off branches turn out to be covered by complementary levels (level 3 when it is on, level 1 when it is off).- The greedy per-parameter partition rounds the realized offload fraction up, never down, so it can never leave more on the GPU than requested.
- Config coverage is complete: every YAML declaring
optimizer_cpu_offloadgot the new key except twodefaults:-based override files, where omitting it is correct.
One thing you may want to note in the docs paragraph at some point (not blocking): with optimizer_cpu_offload: false NeMo RL moves the whole optimizer state to CPU before colocated generation (offload_before_refit, and grpo.py's offload_after_refit() under if colocated_inference:), and both are gated on not self.optimizer_cpu_offload — so a fraction below 1.0 skips that eviction entirely and can leave a higher generation-phase peak than turning offload off. The worker gating is unchanged on main; this PR is just what makes f<1 reachable.
Two pre-existing items worth a follow-up issue rather than this PR: the _force_sync_optimizer_fp32_from_model docstring describes the upstream gap backwards (_copy_model_params_to_main_params does level 3 only and returns early, distrib_optimizer.py#L3067) — the same error is in Megatron-Bridge's copy; and that helper now duplicates Bridge's public sync_hybrid_device_optimizer_fp32_master_copies.
Generated by Claude Code
What does this PR do?
Adds fractional optimizer CPU offload to the Megatron policy backend.
optimizer_offload_fractionvalues in(0, 1].overlap_cpu_optimizer_d2h_h2doption.HybridDeviceOptimizer.Optimizer CPU offload requires
use_distributed_optimizer=true. This PR doesnot change activation offload or NeMo RL's generic optimizer movement path.
Usage
Validation
lifecycle behavior.
configurations. All 400 recorded losses were finite.
throughput trade-off:
0.752s15.24 GiB1.187s14.13 GiB1.216s14.65 GiB1.678s10.53 GiBTimings use steps 11-100. This is a functional microbenchmark, not a
production-scale throughput claim.
Before your PR is "Ready for review"
/review-pr-teamself-review and resolved findings.