Repository navigation
Conversation
The automodel backend always loaded model weights in float32 so the optimizer could keep fp32 master weights. But TE FusedAdam with master_weights=True maintains its own fp32 master internally (bf16 params + int16 remainder). Forcing an fp32 load in that case is redundant and roughly doubles both model-weight and optimizer master-weight memory (~131GB -> ~102GB optimizer state in the reporter's run). Pick the load dtype from the optimizer config: load in the compute dtype when the optimizer keeps its own fp32 master (master_weights=True), and keep the fp32 load otherwise (plain AdamW, or no optimizer configured). Fixes NVIDIA-NeMo#2865. Signed-off-by: Shubhankar Tripathy <[email protected]>
|
/ok to test 718c17b |
terrykong
left a comment
There was a problem hiding this comment.
@hemildesai could you review?
|
Gentle ping @hemildesai @terrykong — this has been green and mergeable since mid-July (all checks passing, no conflicts). Happy to address any feedback or rebase if you'd prefer it freshened before review. |
|
@hemildesai @yuki-97 — gentle ping when you have bandwidth. This fixes #2865: the automodel path loads weights in fp32 even when the precision-aware optimizer already holds fp32 master weights, doubling load-time memory for no benefit. All pre-CI checks are green and the branch is mergeable against current main; it still needs a |
|
Closing: main has since landed a more complete version of this fix in #4143 — For the record on #2865: @tianyi-zhang-02's measurements there confirmed both halves of this PR's premise — ~2× params/optimizer-state/peak from the fp32 load, and the fp32 |
What
The automodel (DTensor) backend hard-coded the model load dtype to
float32innemo_rl/models/automodel/setup.pyso the optimizer could keep fp32 master weights. When the optimizer maintains its own fp32 master — TEFusedAdamwithmaster_weights=True(bf16 params + int16 remainder) — that fp32 load is redundant and roughly doubles both model-weight and optimizer master-weight memory.Fixes #2865.
Change
Pick the load dtype from the optimizer config in
validate_and_prepare_config:master_weights=True(optimizer holds the master) → load in the compute dtype.master_weights/ no optimizer configured → keep the fp32 load (unchanged behavior).Only the load dtype changes; the FSDP mixed-precision policy and everything downstream are untouched.
Impact
No behavior change for the exemplar configs (they use
torch.optim.AdamW, which has no internal master → still fp32). The savings apply only to the FusedAdam+master_weightspath the issue reports (~131GB → ~102GB optimizer state, ~67GB → ~36GB model params in the reporter's run).Test plan
tests/unit/models/automodel/test_automodel_setup.pyasserting thetorch_dtypepassed toAutoConfig.from_pretrained:float32master_weights=True→ compute dtype (bf16)float32/ok to test)Note: local test run blocked by an unrelated
uv/Pythonmac_ver()issue on the dev box; logic validated in isolation and syntax-checked. CI will exercise the full suite.