Repository navigation
Remove torch cuda empty cache - #5678
Conversation
ddbde1f to
da16039
Compare
|
/ok to test debb98a |
|
This is a replay of the change reverted in #5366, is CI passing with this PR? |
This test was recently updated in #6239. @shurkat-nvidia can you please check to see if the changes to the config are needed anymore? |
torch.cuda.empty_cache() was added as a workaround for out-of-memory errors on some models. With async-shm checkpointing, some of the memory pressure is reduced. Remaining memory fragmentation and pressure can be reduced by properly configuring the torch allocator. Signed-off-by: Skand Hurkat <shurkat@nvidia.com>
- Update checkpointing to use nvrx with shm. - Provide PYTORCH_ALLOC_CONF environment variable to initiate garbage collection. Use larger blocks to avoid fragmentation due to splitting. Signed-off-by: Skand Hurkat <shurkat@nvidia.com>
debb98a to
c7830f1
Compare
@cuichenx, @balasaajay ran the test manually a few weeks ago, it appeared to have addressed the OOM issue.
@Phlip79, I rebased the branch to the latest main. Still need changes to checkpoint args and to the |
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Skand Hurkat <shurkat@nvidia.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Skand Hurkat <shurkat@nvidia.com>
|
/ok to test 0f9153b |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/31719722747 |
Signed-off-by: Skand Hurkat <shurkat@nvidia.com> Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
What does this PR do?
The PR removes an expensive
torch.cuda.empty_cache()call withinsave_checkpoint_and_time(). This call took multiple seconds on every checkpoint and also increased the size of thegenerate_state_dict()function by multiple seconds. To avoid OOM errors, the code also modifies the Nemotron3 Super script to 1) use SHM to avoid expensiverebuild_cuda_tensor()calls during the IPC handoff and 2) garbage collect the torch allocator at 80% GPU allocation with a lower overhead than a rawempty_cache()call, and to use larger blocks to prevent fragmentation in the first place.Issue tracking
For PRs from open-source community contributors:
Linked issue:
Contribution process
Pre-checks
Code review
Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.