Skip to content

[DeepSeek V4] Fix MTP SPMD input layouts - #4521

Closed
Serendipity-matong wants to merge 2 commits into
pytorch:mainfrom
Serendipity-matong:fix/deepseek-v4-mtp-spmd-layout
Closed

Serendipity-matong wants to merge 2 commits into
pytorch:mainfrom
Serendipity-matong:fix/deepseek-v4-mtp-spmd-layout

Conversation

@Serendipity-matong

Copy link
Copy Markdown
Contributor

Summary

DeepSeek V4 MTP sharding declarations did not match the runtime tensor
ranks and sequence-parallel layouts.

For TP=2, the old MTP declarations omitted the TP token-axis placement
for 2-D activations and used 2-D PartitionSpecs for 3-D HC hidden states
and 1-D token metadata.

This change:

  • Adds the TP token-axis placement for MTP embeddings.
  • Uses rank-correct layouts for [T, hc_mult, D] HC hidden states.
  • Uses rank-correct layouts for [T] token IDs and validity masks.
  • Applies the same HC rank layout consistently to main layers, MTP layers,
    and the root HC head.
  • Adds regression coverage for both sequence-parallel and non-sequence-parallel
    configurations.

Validation

  • 2-GPU RTX 4090D baseline reproduced four SPMD layout failures.
  • 2-GPU fixed run passed on both ranks.
  • pytest -q tests/unit_tests/cpu/test_deepseek_v4_mtp.py
    passed with 2 passed.
  • git diff --check
  • Python compilation check

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 8, 2026
@tianyu-l

tianyu-l commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

can we follow up in #4490

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

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants