Skip to content

Partition AutoEP expert parameters per layer under ZeRO-3 - #8424

Open
tohtana wants to merge 3 commits into
deepspeedai:masterfrom
tohtana:tohtana/fix-autoep-zero3-init-memory-peak
Open

Partition AutoEP expert parameters per layer under ZeRO-3#8424
tohtana wants to merge 3 commits into
deepspeedai:masterfrom
tohtana:tohtana/fix-autoep-zero3-init-memory-peak

Conversation

@tohtana

@tohtana tohtana commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Problem

When a model created under zero.Init is passed to deepspeed.initialize, AutoEP creates new local-expert tensors while replacing MoE layers. ZeRO-3 previously converted those tensors only after every layer had been replaced, so full replacement-expert storage accumulated across layers and increased the initialization peak.

This addresses the initialization-memory behavior described as problem 1 in #8353. It does not change the independent debug-map retention behavior covered by #8356.

Approach

After each AutoEP layer is repacked, copied, tagged, and installed, resolve its expert-data-parallel group and immediately pass only its newly created expert parameters through the existing ZeRO conversion helper. Optimizer classification and grouping use the experts' ZeRO logical shape and size after partitioning. Existing source gathers, router/shared/dense placement, and batched output-recorder retargeting remain unchanged. The later ZeRO setup already skips parameters converted by this step.

Signed-off-by: Masahiro Tanaka <tanaka.masahiro@gmail.com>
Signed-off-by: Masahiro Tanaka <tanaka.masahiro@gmail.com>
Signed-off-by: Masahiro Tanaka <tanaka.masahiro@gmail.com>

@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: 03d2ffbfd6

ℹ️ 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".

@@ -0,0 +1,178 @@
# Copyright (c) DeepSpeed Team.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the required Signed-off-by trailer

This is a non-merge commit, but its message contains no Signed-off-by trailer, so it violates the repository's mandatory DCO/CI requirement and may be rejected before the code can merge. Recreate the commit using git commit --signoff with the configured author identity.

AGENTS.md reference: AGENTS.md:L8-L8

Useful? React with 👍 / 👎.

@tohtana
tohtana requested a review from pengdurice September 7, 2026 02:49
Comment thread deepspeed/__init__.py
if p.ndim >= 2 and not any(keyword in name.lower() for keyword in ("embed", "lm_head")):
is_partitioned_autoep_expert = (getattr(p, "ds_zero_placement_family", None) == "autoep_expert"
and hasattr(p, "ds_shape"))
ndim = len(p.ds_shape) if is_partitioned_autoep_expert else p.ndim

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this can be a bigger bug. regardless of this work: under zero.Init, models are already partitioned and p.ndim = 1 even for 2+ dimension tensors causing all parameters to not use muon. Do we want to take this opportunity to fix this?

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