Repository navigation
Report memory in the wall-clock timer log when memory_breakdown is set - #9143
varun-projects wants to merge 1 commit into
Conversation
DeepSpeedEngine logs its micro timers with the user's memory_breakdown
config value:
self.timers.log(names=self.engine_timers.micro_timers,
memory_breakdown=self.memory_breakdown())
SynchronizedWallClockTimer.log() accepted that argument and never read
it, so the per-step timing line carried no memory information however
the key was set. The class already had memory_usage() for exactly this
report, and the engine's other memory_breakdown call sites (the
see_memory_usage checkpoints) do honor the key, so only this line was
silently missing from the breakdown.
log() now appends memory_usage() when the flag is set. Output with the
flag unset is unchanged, byte for byte, since wall_clock_breakdown lines
are parsed by users.
memory_breakdown was also absent from the configuration reference even
though it is a documented-by-name top-level key with a default; it is now
listed next to wall_clock_breakdown, which gates the timing report it
extends.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: varun-projects <4797069+varun-projects@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25bf248f3f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if memory_breakdown: | ||
| string += self.memory_usage() |
There was a problem hiding this comment.
Forward memory breakdown to pipeline timer logs
When memory_breakdown is enabled for pipeline-parallel training, this branch never receives True: PipelineEngine disables the base step() in deepspeed/runtime/pipe/engine.py:1295-1297, and its wall-clock log calls at lines 1232-1247 omit memory_breakdown=self.memory_breakdown() (unlike the standard engine call at deepspeed/runtime/engine.py:3784). Consequently the newly documented memory fields are still absent from pipeline timing reports; forward the flag on the pipeline micro-timer log as well.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
SynchronizedWallClockTimer.log()accepts amemory_breakdownargument and never reads it, so the per-stepwall_clock_breakdownline reports no memory however the config key is set.Root cause
DeepSpeedEngine._stop_timerspasses the user's config value on a live path (deepspeed/runtime/engine.py:3784, underif self.wall_clock_breakdown():):log()(deepspeed/utils/timer.py:145) builds its string from the timers and callsprint_dist, never touching the parameter. The class already has amemory_usage()static method (deepspeed/utils/timer.py:135) that formats allocated / max-allocated / cached / max-cached throughget_accelerator(), which is what this report is for.To be precise about scope:
memory_breakdownis not dead overall — the engine'ssee_memory_usage(..., force=self.memory_breakdown())checkpoints do honor it. Only the timing line, the one place the key is passed as a parameter, dropped it.Change
log()appendsmemory_usage()when the flag is set, reusing the existing helper and its" | ..."format:Output with the flag unset is unchanged byte for byte, which matters because
wall_clock_breakdownlines get parsed.The no-op sibling
log()onNoopTimer(deepspeed/utils/timer.py:199) does not share the defect: that class's timers return 0 andget_timers()returns{}, so emitting nothing is correct there. Left alone.memory_breakdownwas also missing from the configuration reference despite being a top-level key with a default (MEMORY_BREAKDOWN/MEMORY_BREAKDOWN_DEFAULT,deepspeed/runtime/constants.py:327, parsed atdeepspeed/runtime/config.py:538). It is now listed next towall_clock_breakdown, which gates the report it extends.Not a duplicate
No open PR mentions
memory_breakdownor this method; a PR search formemory_breakdown timerreturns nothing. The open PRs touching timing code are unrelated: #8798 (comms_logger timer history), #8763 (flops profiler under gradient accumulation), #8430 (steps_per_printNone guard).Validation
1x aarch64 CPU host, no GPU, no C++ compiler, torch 2.15.0+cpu, Python 3.13,
DS_ACCELERATOR=cpu.1 passed, 2 skipped. The 2 skips are the pre-existing tests in that file, which need accelerator events.deepspeed/utils/timer.pyreverted and the new test kept: 1 failed —AssertionError: [Rank -1] time (ms) | op: 0.00, i.e. the logged line contains no memory figure.Falsecase was diffed against the base and is identical.pre-commit run --files deepspeed/utils/timer.py tests/unit/utils/test_timer.py docs/_pages/config-json.md: all hooks pass.The new test goes in the existing
tests/unit/utils/test_timer.pyrather than a new file. It asserts on the logged output through the publiclog()interface, uses the accelerator itself as the oracle for the reported figure rather than recomputing it, and also asserts thememory_breakdown=Falseline is unchanged — so it fails if either half of the contract breaks.python ci/tests_fetcher.py --base origin/masterselects 0 targets, since the diff-based selector only coverstests/unit/v1/. This test lives undertests/unit/utils/, whichcpu-torch-latestruns on every PR, so it is covered there.Compatibility
The changed line is accelerator-neutral: it calls the existing
memory_usage(), which goes throughget_accelerator()and has notorch.cudadependency (check-torchcudapasses). Verified on the CPU accelerator that all four queries return real values rather than raising. No ZeRO stage, offload, precision or parallelism axis is involved — the change is confined to formatting a log line, behind a config flag that defaults to false.Not validated: no GPU or vendor accelerator was available, so the memory figures were only observed via the CPU accelerator's implementations of
memory_allocated/max_memory_allocated/memory_cached/max_memory_cached.AI assistance
AI assistance was used for this change: the investigation, the two-line fix, the test and the doc entry were produced with an AI coding agent, and the validation above was run in that environment on the hardware stated. Flagging it explicitly per
AGENTS.md, along with the fact that no GPU validation was possible here.🤖 Generated with Claude Code