Skip to content

Fix AutoTP metadata updates for unsharded modules - #8299

Merged
delock merged 3 commits into
deepspeedai:masterfrom
zupengwang:fix/autotp-preserve-unsharded-module-attrs-publish-v2
Aug 25, 2026
Merged

delock merged 3 commits into
deepspeedai:masterfrom
zupengwang:fix/autotp-preserve-unsharded-module-attrs-publish-v2

Conversation

@zupengwang

Copy link
Copy Markdown
Contributor

Summary

  • defer module metadata updates until recursive AutoTP replacement has completed
  • update logical dimensions only when a subtree contains parameters carrying AutoTP TP metadata
  • preserve metadata for replicated vision modules and high-dimensional weights while retaining existing sharded Linear behavior
  • add regression coverage for PatchEmbed-style Conv3d wrappers, unsharded attention subtrees, and genuinely sharded parameters

Fixes #8285.

Problem

update_mp_params() previously ran before Linear replacement and scaled logical attributes for every traversed module. In multimodal models this changed replicated vision metadata, such as Qwen2-VL PatchEmbed embed_dim, even though the corresponding Conv3d weight was not partitioned. The metadata then disagreed with the full weight shape and broke vision forward.

Validation

Current master baseline e70b90352e93e07862c45ebb946d75b813f025a2 reproduces on 2-GPU NCCL with patch_embed.embed_dim=60 while proj.out_channels=120.

  • CPU targeted: 7 passed, 20 deselected
  • 2-process Gloo metadata check: unsharded num_heads=16, sharded hidden_size=6 on both ranks
  • 2-GPU custom-pattern suite: 27 passed
  • 4-GPU AutoTP/ZeRO adjacent suite: 33 passed, 2 skipped, 24 deselected
  • synthetic training on 1/2/3/5 RTX 3090 GPUs: forward, backward, and optimizer step all complete with zero cross-rank output, PatchEmbed gradient, and PatchEmbed parameter difference
  • 5-GPU synthetic, 3 runs with 3 warmup and 20 measured steps each: 5.008 ms mean step latency, 409,216 tokens/s, 28,170,752 peak allocated bytes, 52,428,800 peak reserved bytes
  • Qwen2-VL-2B AutoTP=2 vision forward: PatchEmbed 1280 -> 1280, vision heads 16 -> 16, language q_proj [1536,1536] -> [768,1536], zero cross-rank output difference
  • changed-file pre-commit hooks, DS_BUILD_OPS=0 python setup.py check, compileall, and git diff --check pass

@zupengwang
zupengwang marked this pull request as ready for review August 23, 2026 13:04

@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: cc5bce72a0

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread deepspeed/module_inject/auto_tp.py Outdated
ranks=[0])

def update_mp_params(self, child, name=None):
def update_mp_params(self, child, name=None, only_if_sharded=False):

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 has no Signed-off-by trailer, so it does not meet the repository's commit requirements and may be rejected by DCO/CI enforcement; recreate the commit with --signoff using the configured author identity.

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

Useful? React with 👍 / 👎.

Comment thread deepspeed/module_inject/auto_tp.py Outdated
ranks=[0])

def update_mp_params(self, child, name=None):
def update_mp_params(self, child, name=None, only_if_sharded=False):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does only_if_sharded switch needed if all call site pass True? We could avoid this condition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Since every call site requires the metadata guard, the switch was redundant. I removed only_if_sharded and made update_mp_params() always skip metadata updates when the subtree has no parameter carrying DS_AUTOTP_UC_META. The direct unit tests now mark their synthetic sharded parameters explicitly.

Validated on physical GPUs 4 and 5:

  • tests/unit/model_parallelism/test_autotp_custom_patterns.py: 27 passed
  • Qwen2-VL-2B AutoTP: vision output rank max absolute difference 0.0, PatchEmbed metadata preserved, and the language q_proj sharded as expected

Updated in 2cc5f6a7a0bc125850adef8848545e1eefd27e1d.

@delock
delock enabled auto-merge August 25, 2026 05:29
@delock
delock added this pull request to the merge queue Aug 25, 2026
Merged via the queue into deepspeedai:master with commit 7154a00 Aug 25, 2026
14 of 15 checks passed
delock added a commit that referenced this pull request Aug 26, 2026
The unsharded-metadata regression tests merged from master drive kv-head
counts through the process-wide set_num_kv_heads() helper this branch
removes, so they fail to resolve after the merge. Set the per-model
tp_meta directly instead; the surrounding try/finally is no longer needed
because there is no global state left to restore.

Signed-off-by: Ma, Guokai <[email protected]>
@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 14, 2026
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.

[AutoTP] update_mp_params shards vision-tower attributes (patch_embed.embed_dim) without sharding weights, breaking multimodal forward

2 participants