feat(megatron): report peak memory for log_probs and actor_train - #2693
Open
EazyReal wants to merge 1 commit into
Open
feat(megatron): report peak memory for log_probs and actor_train#2693EazyReal wants to merge 1 commit into
EazyReal wants to merge 1 commit into
Conversation
print_memory samples current allocation only at fixed lifecycle points, so it cannot show a phase's high-water mark and an OOM can happen before the next report. Add report_peak_memory(phase), which resets the current CUDA device's allocator peak stats on entry and logs max_memory_allocated/max_memory_reserved in a finally block. Compose it with the existing log_probs and actor_train timers. Measured on a 128x H100 DeepSeek-V4-Flash run at 262,144-token context: the finally-path report is what attributed a 132k-context log_probs OOM to 25 GiB of retained activations; the OOM traceback alone never shows the phase's high-water mark. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
EazyReal
force-pushed
the
upstream-pr/peak-memory-report
branch
from
August 22, 2026 21:40
f443848 to
9e93175
Compare
EazyReal
marked this pull request as ready for review
August 22, 2026 21:40
EazyReal
requested review from
Shi-Dong,
Zhichenzzz,
fzyzcjy,
guapisolo,
jybsuper,
maocheng23,
yueming-yuan and
yushengsu-thu
as code owners
August 22, 2026 21:40
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.
Summary
print_memorysamples current allocation only at fixed lifecycle points, so it does not expose a phase's high-water mark and an OOM can happen before the next reportreport_peak_memory(phase)tomiles/utils/memory_utils.py:torch.cuda.reset_peak_memory_stats()on entry scopes the peak to exactly one phase;max_memory_allocated/max_memory_reservedare logged in afinallyblock, so an OOMing phase still reports its peak{store_prefix}log_probsforward andactor_trainin the Megatron actor with it, composed with the existingtimer(...)scopes; each executed ref/teacher/actor pass reports under its existing prefix, while a skipped actor forward emits no report (--use-rollout-logprobsunless mismatch metrics require it, or--skip-actor-forward-only)ci_utils.pyfires before any rollout, so the scoped resets cannot affect it. The critic phases are left for a follow-up.Measured on a 128x H100 DeepSeek-V4-Flash run at 262,144-token context: the
finally-path report is what attributed a 132k-contextlog_probsOOM to 25 GiB of retained activations — the OOM traceback alone never shows the phase's high-water mark.Testing
pytest tests/fast/utils/test_memory_utils.py— scoped reset, GB formatting, and the report-on-raise path (torch.cudamocked, CPU-only); 3/3 pass locally on CPU-only torchblack,ruff, andisortchecks pass on the touched files