Skip to content

Fix: [BUG] Memory leak in loss backward when enabled torch activation check - #8690

Open
goransh-walia wants to merge 1 commit into
deepspeedai:masterfrom
goransh-walia:fix/issue-8481-880
Open

goransh-walia wants to merge 1 commit into
deepspeedai:masterfrom
goransh-walia:fix/issue-8481-880

Conversation

@goransh-walia

Copy link
Copy Markdown

This PR addresses #8481.

[BUG] Memory leak in loss backward when enabled torch activation checkpoint & zero3 & single-model-multi-branch network

Generated with AI assistance and validated against the original
file before submission (syntax check + change-scope check).
Please review carefully — happy to adjust based on feedback.

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Persistent and delegated counters can suppress parameter release, and the reported topology lacks regression coverage.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Fixes ZeRO-3 parameter retention during backward for activation-checkpointed multi-branch models.

Changes:

  • Preserves ds_grads_remaining across repeated module hooks.
  • Removes an unused alternate backward-hook implementation.
File Description
deepspeed/​runtime/​zero/​parameter_offload.py Revises post-backward reference counting and cleanup triggering.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +418 to +419
if not hasattr(module, 'ds_grads_remaining'):
module.ds_grads_remaining = 0
Comment on lines +500 to 502
if not hasattr(module, 'ds_grads_remaining'):
module.ds_grads_remaining = 0
module.ds_grads_remaining += 1

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants