Skip to content

Report memory in the wall-clock timer log when memory_breakdown is set - #9143

Open
varun-projects wants to merge 1 commit into
deepspeedai:masterfrom
varun-projects:fix/timer-memory-breakdown
Open

varun-projects wants to merge 1 commit into
deepspeedai:masterfrom
varun-projects:fix/timer-memory-breakdown

Conversation

@varun-projects

Copy link
Copy Markdown

SynchronizedWallClockTimer.log() accepts a memory_breakdown argument and never reads it, so the per-step wall_clock_breakdown line reports no memory however the config key is set.

Root cause

DeepSpeedEngine._stop_timers passes the user's config value on a live path (deepspeed/runtime/engine.py:3784, under if self.wall_clock_breakdown():):

self.timers.log(names=self.engine_timers.micro_timers, memory_breakdown=self.memory_breakdown())

log() (deepspeed/utils/timer.py:145) builds its string from the timers and calls print_dist, never touching the parameter. The class already has a memory_usage() static method (deepspeed/utils/timer.py:135) that formats allocated / max-allocated / cached / max-cached through get_accelerator(), which is what this report is for.

To be precise about scope: memory_breakdown is not dead overall — the engine's see_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() appends memory_usage() when the flag is set, reusing the existing helper and its " | ..." format:

memory_breakdown=False -> [Rank 0] time (ms) | step: 0.00
memory_breakdown=True  -> [Rank 0] time (ms) | step: 0.00 | mem_allocated: 0.2414 GB | max_mem_allocated: 0.2414 GB | cache_allocated: 0.2414 GB | max_cache_allocated: 0.2414 GB

Output with the flag unset is unchanged byte for byte, which matters because wall_clock_breakdown lines get parsed.

The no-op sibling log() on NoopTimer (deepspeed/utils/timer.py:199) does not share the defect: that class's timers return 0 and get_timers() returns {}, so emitting nothing is correct there. Left alone.

memory_breakdown was 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 at deepspeed/runtime/config.py:538). It is now listed next to wall_clock_breakdown, which gates the report it extends.

Not a duplicate

No open PR mentions memory_breakdown or this method; a PR search for memory_breakdown timer returns nothing. The open PRs touching timing code are unrelated: #8798 (comms_logger timer history), #8763 (flops profiler under gradient accumulation), #8430 (steps_per_print None guard).

Validation

1x aarch64 CPU host, no GPU, no C++ compiler, torch 2.15.0+cpu, Python 3.13, DS_ACCELERATOR=cpu.

DS_ACCELERATOR=cpu PYTHONPATH=. python3.13 -m pytest tests/unit/utils/test_timer.py -q
  • With this change: 1 passed, 2 skipped. The 2 skips are the pre-existing tests in that file, which need accelerator events.
  • With deepspeed/utils/timer.py reverted and the new test kept: 1 failed — AssertionError: [Rank -1] time (ms) | op: 0.00, i.e. the logged line contains no memory figure.
  • Before/after reproduction of the logged line is shown above; the False case 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.py rather than a new file. It asserts on the logged output through the public log() interface, uses the accelerator itself as the oracle for the reported figure rather than recomputing it, and also asserts the memory_breakdown=False line is unchanged — so it fails if either half of the contract breaks.

python ci/tests_fetcher.py --base origin/master selects 0 targets, since the diff-based selector only covers tests/unit/v1/. This test lives under tests/unit/utils/, which cpu-torch-latest runs on every PR, so it is covered there.

Compatibility

The changed line is accelerator-neutral: it calls the existing memory_usage(), which goes through get_accelerator() and has no torch.cuda dependency (check-torchcuda passes). 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

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T03:50:13.696159Z 25bf248 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 22, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread deepspeed/utils/timer.py
Comment on lines +153 to +154
if memory_breakdown:
string += self.memory_usage()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant