Skip to content

Fuse per-sequence AlltoAll into a unified one in GDN forward#4913

Merged
xuantengh merged 13 commits into
NVIDIA:mainfrom
xuantengh:xuantengh/gdn_a2a
Jun 9, 2026
Merged

Fuse per-sequence AlltoAll into a unified one in GDN forward#4913
xuantengh merged 13 commits into
NVIDIA:mainfrom
xuantengh:xuantengh/gdn_a2a

Conversation

@xuantengh

@xuantengh xuantengh commented May 21, 2026

Copy link
Copy Markdown
Contributor

What does this PR do ?

PR #2645 adds the THD support for GDN, but it requires per-sequence, per-section (qkv, alpha, beta, gate) AlltoAll converting activation between CP <-> HP. This PR fuses the per-sequence AlltoAll into a unified one, with local indexing mappings to reorder at the sequence dimension and feature dimension.

wandb link for running a Qwen3 Next proxy model with 16K sequence length and CP size = 4, the iteration time speedup is around 7% - 10%.

image

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Code review

Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.

Step 1: Mark PR as "Ready for Review"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

Step 2: Final Review

For PRs that change megatron/core, once all expert reviewers have approved, the Final Review label is applied automatically and final reviewers are assigned.

For PRs outside megatron/core, this step is skipped.

Step 3: Approved

Once all required reviewers have approved, the Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

For MRs into `dev` branch The proposed review process for `dev` branch is under active discussion.

MRs are mergable after one approval by either eharper@nvidia.com or zijiey@nvidia.com.

@copy-pr-bot

copy-pr-bot Bot commented May 21, 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.

@xuantengh

Copy link
Copy Markdown
Contributor Author

/claude review

@claude claude Bot 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.

LGTM

@xuantengh

Copy link
Copy Markdown
Contributor Author

/ok to test 8dcfd7d

@xuantengh

Copy link
Copy Markdown
Contributor Author

/ok to test 6d28256

@xuantengh

Copy link
Copy Markdown
Contributor Author

/claude review

Comment thread tests/unit_tests/ssm/test_gated_delta_net.py Outdated
@xuantengh

Copy link
Copy Markdown
Contributor Author

/claude review

Comment thread tests/unit_tests/ssm/test_gated_delta_net.py
Comment thread tests/unit_tests/ssm/test_gated_delta_net.py Outdated

@claude claude Bot 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: the core logic for fusing per-sequence AlltoAll into a single batched a2a + local permutations looks correct. The mamba_context_parallel.py cleanup is a clean replacement with existing utility functions. Test coverage in TestFusedThdAllToAll is solid — it validates both directions and a round-trip identity check across multiple cu_seqlens configurations and cp_sizes.

Only nit: unused import os and a commented-out os.environ.setdefault line in the test file (see inline comments).

@xuantengh xuantengh force-pushed the xuantengh/gdn_a2a branch from efb43a2 to de01425 Compare May 23, 2026 04:01
@xuantengh xuantengh force-pushed the xuantengh/gdn_a2a branch from 7f7b668 to 5d261d1 Compare June 9, 2026 04:32
@xuantengh

Copy link
Copy Markdown
Contributor Author

/ok to test 5d261d1

@xuantengh

Copy link
Copy Markdown
Contributor Author

/ok to test 4137f93

@svcnvidia-nemo-ci

Copy link
Copy Markdown

🔄 Merge queue validation started!

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

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: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants