Skip to content

Wire CP into MIMO - #7758

Merged
Mellonta merged 2 commits into
NVIDIA:mainfrom
Mellonta:cp_mimo
Oct 15, 2026
Merged

Mellonta merged 2 commits into
NVIDIA:mainfrom
Mellonta:cp_mimo

Conversation

@Mellonta

@Mellonta Mellonta commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Integrates the shared CP batch/layout handling into MIMO and extends heterogeneous MIMO grids with GTP sequence partitioning from #7748.

  • Partition language embeddings, token IDs, positions, labels, loss masks, and MTP masks together through ContextParallelBatch, keeping dense and packed inputs aligned across contiguous and zigzag CP layouts.
  • Build separate weight and batch/sequence views of each language grid. Weight groups control GTP weight sharding; sequence groups combine --mimo-llm-cp with sequence partitions inside GTP. Remaining GTP partitions process independent microbatches.

For example, with TP=1, weight shards=64, sequence shards=64, and --mimo-llm-cp 2, the language grid partitions each sequence across 128 ranks while retaining 64-rank weight-sharding groups.

Test

uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q \
  tests/unit_tests/models/mimo \
  tests/unit_tests/pipeline_parallel/test_bridge_communicator.py \
  tests/unit_tests/data/test_get_batch.py \
  tests/unit_tests/transformer/test_multi_token_prediction.py

@copy-pr-bot

copy-pr-bot Bot commented Sep 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@Mellonta Mellonta changed the title Cp mimo Wire CP into MIMO Sep 30, 2026
@fanshiqing fanshiqing linked an issue Oct 8, 2026 that may be closed by this pull request
@Mellonta
Mellonta force-pushed the cp_mimo branch 2 times, most recently from c1f56e9 to 8285cbd Compare October 12, 2026 21:09
@Mellonta
Mellonta marked this pull request as ready for review October 12, 2026 21:10
@Mellonta
Mellonta requested review from a team as code owners October 12, 2026 21:10
(cherry picked from commit e597a976901c3f5c2c71061f30f3c1dfeadfc3d5)

Signed-off-by: Haoran Zhang <haoranz@nvidia.com>
Signed-off-by: Haoran Zhang <haoranz@nvidia.com>
@fanshiqing

Copy link
Copy Markdown
Member

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

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.

Light review completed across the changed files and directly affected CP/GTP paths. One logic error and one configuration-documentation issue remain. Tests were not executed; suggested changes below require author verification.

1. Dual-layout batches crash GPT-backed MIMO

Failure. With CP=2, linear_cp_layout="contiguous", attention_cp_layout="zigzag", and a dense [1, 8] input, the adapter creates two layout views. The new language-forward helper consequently passes cp_batch to the language model. However, GPTModel.forward has no such parameter, so GPT-backed MIMO raises TypeError: ... unexpected keyword argument 'cp_batch'. GPT remains a MIMO receiver, including in the mock provider.

Correction. Distinguish the receiver contracts when configuring the adapter. Legacy GPT's TransformerBlock execution does not perform CP layout transitions, so GPT-backed MIMO should prepare one batch in the attention layout. Hybrid-backed MIMO must retain its linear boundary layout, alternate attention view, and cp_batch. Merely suppressing the keyword would leave GPT consuming contiguous activations as zigzag attention inputs.

A small suggested patch for MimoModel initialization: add imports for dataclasses.replace and GPTModel, then insert this immediately after self._initialize_language_model():

if self.partition_adapter is not None and isinstance(
    unwrap_model(self.language_model), GPTModel
):
    self.partition_adapter = PartitionAdapter(
        replace(
            self.partition_adapter.cfg,
            linear_cp_layout=self.partition_adapter.cfg.attention_cp_layout,
        )
    )

This restores the invariant that each receiver gets activations in its supported boundary ordering and only supported keywords.

Preservation. Ordinary GPT zigzag CP must remain unchanged; CP=1 must remain a passthrough; SP must still scatter only decoder embeddings. Hybrid/Mamba receivers must continue receiving both layouts, including the converted MTP validity mask. Encoder-only ranks must still have no partition adapter.

Acceptance — proposed regression checks, not executed. Add a GPT-backed MIMO case with CP=2, TP=1, the differing layouts above, sequence length 8, and identifiable embedding rows. Keep GPT's real forward signature: if the environment lacks a CP attention backend, replace only its decoder as the existing MIMO tests do. Forward must not raise, rank 0 must receive embedding rows [0, 1, 6, 7], rank 1 rows [2, 3, 4, 5], and labels/loss masks must follow those same rows. Also retain the CP/SP shape-and-content assertions in the distributed partition tests, and the assertion that Hybrid MTP receives the zigzag mask in the MTP regression. Verify statically that the normalization is limited to GPT receivers.

2. Document the added PartitionConfig fields

Failure. The new public fields linear_cp_layout, attention_cp_layout, and tp_cp_group in PartitionConfig lack adjacent MyST docstrings, contrary to the base configuration-documentation rule. This is a documentation issue, not a demonstrated runtime failure.

Correction. Add descriptions immediately after those declarations, for example:

linear_cp_layout: CPLayout = "zigzag"
"""Boundary CP ordering used when preparing language-model inputs."""
attention_cp_layout: CPLayout = "zigzag"
"""Attention/MTP ordering; a differing layout requests an additional batch view."""
cp_group: Optional[ProcessGroup] = None
tp_group: Optional[ProcessGroup] = None
tp_cp_group: Optional[ProcessGroup] = None
"""Explicit TP x CP group used for sequence-parallel layout conversion."""

Preservation and acceptance — static checks. Keep the existing field types, defaults, and group forwarding unchanged. Inspect that each of the three added public fields has its own immediately following docstring and that the descriptions agree with the adapter's layout selection and the conversion helper's explicit-group requirements. No runtime test is needed for this documentation-only correction.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Approved All necessary approvals have been made label Oct 14, 2026
@Mellonta
Mellonta added this pull request to the merge queue Oct 14, 2026
@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/38688830700

Merged via the queue into NVIDIA:main with commit 0101df9 Oct 15, 2026
184 of 192 checks passed
@Mellonta
Mellonta deleted the cp_mimo branch October 15, 2026 08:05

This branch was successfully deployed

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

Labels

Approved All necessary approvals have been made complexity: high nemotron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GTP+CP

5 participants