Skip to content

Support MTP+PP - #4488

Open
acisseJZhong wants to merge 1 commit into
mtp-pp-runtimefrom
enable_mtp_pp
Open

acisseJZhong wants to merge 1 commit into
mtp-pp-runtimefrom
enable_mtp_pp

Conversation

@acisseJZhong

@acisseJZhong acisseJZhong commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR enables DeepSeek-V3 MTP with eager pipeline parallelism using the
model-owned pipeline runtime and shared-parameter lifecycle.

The first pipeline stage owns the canonical token embedding, while the final
stage keeps a replica so it can embed shifted MTP tokens locally. Original
token IDs are available on each PP rank from the local microbatch, so pipeline
edges continue to carry only hidden activations.

Design

pipeline_deepseek_v3() adds the MTP-specific pipeline behavior:

  • generated layouts place all MTP layers and an embedding replica on the final
    virtual stage;
  • user-defined layouts are validated for final-stage MTP, norm, LM-head, and
    embedding ownership;
  • static stage metadata describes token inputs, hidden-state boundaries, and
    the final tuple of main/MTP predictions and validity masks; and
  • _MTPPipelineRuntime supplies stage-local source token IDs and uses the
    shared-parameter runtime to synchronize the embedding replica, combine its
    gradients, and count the logical embedding once in grad norm.

After pipeline splitting, num_mtp_layers retains the full model's configured
MTP depth, while self.mtp_layers contains only the layers assigned to the
current virtual stage. The final stage shifts mtp_source_tokens with
roll_mtp_sequence(), embeds them with its tok_embeddings replica, and
returns (*predictions, *valid_masks) for regular or chunked loss.

The generic pipeline_llm() now accepts
stage_metadata_fn(stage_idx, num_stages) for each PipelineStage's input and
output metadata. When module_fqns_per_model_part is set, its length defines
the number of virtual stages.

Scope

  • Standard Trainer eager PP is supported.
  • Context parallelism and GraphPP with MTP remain unsupported.

Tests

pytest -q \
  tests/unit_tests/cpu/test_loss.py \
  tests/unit_tests/cpu/test_pipeline_parallel.py

Result: 36 passed.

Compared deepseek_v3_debugmodel_mtp on the parent commit without PP against
this commit with two-stage PP. Both runs used the same seed checkpoint,
--debug.seed=42, --debug.deterministic, five training steps, two 256-token
microbatches per optimizer step, and CUDA graphs disabled.

Comparison Training steps Maximum loss relative difference Maximum grad-norm relative difference
1 GPU MTP vs. 2 GPU MTP + PP 5 8.16e-6 1.01e-4

Both runs completed successfully and followed the same loss and grad-norm
trajectories. The small differences are expected from the changed pipeline and
gradient-accumulation order.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 5, 2026
@acisseJZhong
acisseJZhong marked this pull request as draft September 5, 2026 00:55
@acisseJZhong acisseJZhong changed the title Support MTP+PP [do not review] Support MTP+PP Sep 5, 2026
@acisseJZhong
acisseJZhong force-pushed the enable_mtp_pp branch 3 times, most recently from bd9290e to 9513cb1 Compare September 5, 2026 06:47
@acisseJZhong acisseJZhong changed the title [do not review] Support MTP+PP Support MTP+PP Sep 5, 2026
@acisseJZhong
acisseJZhong marked this pull request as ready for review September 5, 2026 06:47
@acisseJZhong
acisseJZhong removed this pull request from stack #4487 September 9, 2026 17:13
@acisseJZhong
acisseJZhong added this pull request to stack #4545 September 9, 2026 17:14
@acisseJZhong
acisseJZhong force-pushed the enable_mtp_pp branch 2 times, most recently from 0e39e97 to 1bf9af3 Compare September 10, 2026 04:25
@acisseJZhong
acisseJZhong removed this pull request from stack #4545 September 10, 2026 04:38

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

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.

1 participant