fix(examples): enable activation checkpointing for phi_4_squad#2634
Merged
Conversation
The checkpoint-robustness test builds a full FSDP2 model + optimizer in every phase. A bare `del <trainer>` did not reclaim them between phases: the per-part optimizers are reachable from the model (built over model.parts), so the Adam state lingered, and ModelSupports pinned the model strongly via model._supports. - Add `_release_recipe_memory()`: clear optimizer state in place (the Adam moments are the bulk) + drop the recipe's model/optimizer/scheduler refs + gc, so each phase's state is reclaimed before the next phase allocates its own. - Hold the model weakly in `ModelSupports` so the capability descriptor can never be the reason a multi-GiB model stays resident after its owner is gone. Memory hygiene only (verified: model + optimizer reclaim to ~0 between phases). This is NOT the OOM fix — see the activation-checkpointing change. Signed-off-by: Alexandros Koumparoulis <akoumparouli@nvidia.com>
phi-4 (14B) stores ~60 GiB of activations per training step; without recomputation a single forward/backward peaks at ~74 GiB on an 80 GiB H100 and OOMs on long SQuAD batches. This surfaced in the sft_ckpt_robustness suite, whose resume phase trains max_steps+3 steps and reliably hits the spike (steady alloc is a flat ~10 GiB, so it is a per-step activation peak, not a leak or cross-phase accumulation). Enabling activation_checkpointing bounds the per-step peak; verified end-to-end on 8xH100 (EOS): the phi_4_squad checkpoint-robustness test passes (peak ~70 GiB, no OOM, all phases incl. resume). Ref (failing CI before the fix): https://gitlab-master.nvidia.com/dl/JoC/nemo-ci/-/jobs/343744188 Signed-off-by: Alexandros Koumparoulis <akoumparouli@nvidia.com>
d9e7937 to
a42e855
Compare
Contributor
Author
|
/ok to test a42e855 |
HuiyingLi
previously approved these changes
Jun 19, 2026
Contributor
Author
|
Verified on EOS (8×H100), running just the
Per-step profiling: steady |
ModelSupports now holds the model via weakref.ref (this PR), so the magi capability helper that built a throwaway `_BackendModel(attn)` let CPython collect it before `.supports_*` was read -> ReferenceError. Bind the model in each caller so it outlives the capability check; this mirrors production, where the model owns its `_supports` and is always live at `model.supports.X` access. Fixes the 6 test_capabilities_magi.py failures in L0_Unit_Tests_CPU (GHA run 27801277153, job 82274392657). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Alexandros Koumparoulis <akoumparouli@nvidia.com>
Contributor
Author
|
/ok to test 7eae20f |
HuiyingLi
approved these changes
Jun 19, 2026
akoumpa
added a commit
that referenced
this pull request
Jun 20, 2026
* test(checkpoint): reclaim model+optimizer between robustness phases The checkpoint-robustness test builds a full FSDP2 model + optimizer in every phase. A bare `del <trainer>` did not reclaim them between phases: the per-part optimizers are reachable from the model (built over model.parts), so the Adam state lingered, and ModelSupports pinned the model strongly via model._supports. - Add `_release_recipe_memory()`: clear optimizer state in place (the Adam moments are the bulk) + drop the recipe's model/optimizer/scheduler refs + gc, so each phase's state is reclaimed before the next phase allocates its own. - Hold the model weakly in `ModelSupports` so the capability descriptor can never be the reason a multi-GiB model stays resident after its owner is gone. Memory hygiene only (verified: model + optimizer reclaim to ~0 between phases). This is NOT the OOM fix — see the activation-checkpointing change. Signed-off-by: Alexandros Koumparoulis <akoumparouli@nvidia.com> * fix(examples): enable activation checkpointing for phi_4_squad phi-4 (14B) stores ~60 GiB of activations per training step; without recomputation a single forward/backward peaks at ~74 GiB on an 80 GiB H100 and OOMs on long SQuAD batches. This surfaced in the sft_ckpt_robustness suite, whose resume phase trains max_steps+3 steps and reliably hits the spike (steady alloc is a flat ~10 GiB, so it is a per-step activation peak, not a leak or cross-phase accumulation). Enabling activation_checkpointing bounds the per-step peak; verified end-to-end on 8xH100 (EOS): the phi_4_squad checkpoint-robustness test passes (peak ~70 GiB, no OOM, all phases incl. resume). Ref (failing CI before the fix): https://gitlab-master.nvidia.com/dl/JoC/nemo-ci/-/jobs/343744188 Signed-off-by: Alexandros Koumparoulis <akoumparouli@nvidia.com> --------- Signed-off-by: Alexandros Koumparoulis <akoumparouli@nvidia.com> (cherry picked from commit c75d9cf) Signed-off-by: Alexandros Koumparoulis <akoumparouli@nvidia.com>
HuiyingLi
pushed a commit
that referenced
this pull request
Jun 20, 2026
…2661) fix(examples): enable activation checkpointing for phi_4_squad (#2634) * test(checkpoint): reclaim model+optimizer between robustness phases The checkpoint-robustness test builds a full FSDP2 model + optimizer in every phase. A bare `del <trainer>` did not reclaim them between phases: the per-part optimizers are reachable from the model (built over model.parts), so the Adam state lingered, and ModelSupports pinned the model strongly via model._supports. - Add `_release_recipe_memory()`: clear optimizer state in place (the Adam moments are the bulk) + drop the recipe's model/optimizer/scheduler refs + gc, so each phase's state is reclaimed before the next phase allocates its own. - Hold the model weakly in `ModelSupports` so the capability descriptor can never be the reason a multi-GiB model stays resident after its owner is gone. Memory hygiene only (verified: model + optimizer reclaim to ~0 between phases). This is NOT the OOM fix — see the activation-checkpointing change. * fix(examples): enable activation checkpointing for phi_4_squad phi-4 (14B) stores ~60 GiB of activations per training step; without recomputation a single forward/backward peaks at ~74 GiB on an 80 GiB H100 and OOMs on long SQuAD batches. This surfaced in the sft_ckpt_robustness suite, whose resume phase trains max_steps+3 steps and reliably hits the spike (steady alloc is a flat ~10 GiB, so it is a per-step activation peak, not a leak or cross-phase accumulation). Enabling activation_checkpointing bounds the per-step peak; verified end-to-end on 8xH100 (EOS): the phi_4_squad checkpoint-robustness test passes (peak ~70 GiB, no OOM, all phases incl. resume). Ref (failing CI before the fix): https://gitlab-master.nvidia.com/dl/JoC/nemo-ci/-/jobs/343744188 --------- (cherry picked from commit c75d9cf) Signed-off-by: Alexandros Koumparoulis <akoumparouli@nvidia.com>
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
Fixes the recurring OOM in the
phi_4_squadsft_ckpt_robustnessfunctional test.Two commits:
fix(examples)— the actual fix: enableactivation_checkpointing: trueforphi_4_squad.test(checkpoint)— memory hygiene in the robustness test (reclaim each phase's model + optimizer before the next builds its own). Useful on its own, but not what fixes this OOM.Root cause (it was not a leak)
Profiled per-step CUDA memory on 8×H100. The OOM is not cross-phase accumulation, not FSDP, not validation, not the optimizer/
_supports:allocis flat at ~10 GiB every step → no leak / no accumulation.max_steps + 3(8) steps vs the base 5, so it gets more rolls of the dice and reliably hits a spiking batch → OOM. (Base phase survives by a hair.)Enabling activation checkpointing bounds the per-step peak so it fits.
Verification
Reproduced and fixed end-to-end on EOS (8×H100), running only the
phi_4_squadcheckpoint-robustness test in the CI container:activation_checkpointing: OOM at step 5 (75 GiB allocated), matching CI.activation_checkpointing: true: passes — all phases incl. resume, peak ~70 GiB,1 passed in 624s.Failing CI before the fix (reference): https://gitlab-master.nvidia.com/dl/JoC/nemo-ci/-/jobs/343744188