Skip to content

[Docs] Add Mixture of Experts guide - #3494

Open
pggPL wants to merge 55 commits into
NVIDIA:mainfrom
pggPL:docs_moe
Open

[Docs] Add Mixture of Experts guide#3494
pggPL wants to merge 55 commits into
NVIDIA:mainfrom
pggPL:docs_moe

Conversation

@pggPL

@pggPL pggPL commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Adds a Mixture of Experts guide covering routing, token permutation, grouped expert computation, and expert parallelism.

Includes concise PyTorch and JAX examples.

pggPL and others added 30 commits May 4, 2026 15:00
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…PI entries

- Add code snippets and SVG figures referenced by mixture_of_experts.rst
  (moe_permute / moe_unpermute / grouped_linear tabbed examples for both
  PyTorch and JAX)
- Add JAX API reference entries for token_dispatch, token_combine and
  grouped_dense so the cross-references from the MoE page resolve
- Make wording framework-neutral where it was PyTorch-only (Grouped GEMM
  instead of GroupedLinear/grouped linear in shared sections, both
  m_splits and group_sizes mentioned, figure labels generalized)
- Tighten routing-kernel intro: consolidate the redundant "multiple
  variants exist / see API ref" notes into one paragraph next to the
  example, and explicitly state that the kernels are differentiable
- Sharpen merging_probs explanation (top-1 vs top-k) and explicitly
  describe what token_dispatch / token_combine return
- Snippet cleanups: define previously undefined symbols, drop the JAX
  probs= argument from the basic example and explain its purpose in a
  comment, document the ignored permuted_probs / pad_offsets outputs
- Reorder MoE entry in the docs/index.rst toctree

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…ecision

Add Router (score function + top-k + load-balancing loss) and Putting-it-together
sections, plus token-probabilities / padding-and-alignment / chunk-sort subsections
and a fused-expert-MLP note. New SVG figures and PyTorch/JAX snippets. Add the
router and moe_permute_and_pad_with_probs API reference entries (PyTorch and JAX)
and sort_chunks_by_index (JAX).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…ument EP APIs

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…iagram

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…MM, grouped MLP, EP

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
… in introduction

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…e introduction

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…section

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…mework specifics to snippets

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…P conditions

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…LP figure

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…w layer figure

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…ections

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…-framework API)

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…, MXFP8 dispatch, shared experts

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
pggPL and others added 19 commits September 7, 2026 17:42
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…transfer path)

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…p placement footer

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…zero-copy vs CUDA graphs

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…viour

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
@pggPL pggPL added the documentation Improvements or additions to documentation label Sep 8, 2026
…th -W

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>

# Conflicts:
#	docs/_static/css/diagram-colors.css
@pggPL
pggPL marked this pull request as ready for review September 8, 2026 10:48
@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds a comprehensive Mixture of Experts guide covering routing, token permutation, grouped expert computation, and expert parallelism across PyTorch and JAX.

  • Adds runnable-style PyTorch and JAX snippets for MoE building blocks and complete layer composition.
  • Extends the public API references and documentation navigation.
  • Adds diagrams with light- and dark-theme styling.
  • Updates router and JAX MoE docstrings to clarify API contracts.
  • Correctly masks unused fixed-capacity PyTorch EP receive slots before combine, resolving the previous finding.

Confidence Score: 5/5

The PR appears safe to merge; no outstanding correctness, security, or repository-rule issues remain.

The only change since the previous review constructs a per-expert validity mask from the fixed slot capacity and token counts, then zeros padded expert outputs while applying routing weights. This fully addresses the previously reported risk of undefined padded rows reaching expert combine, and the resolved thread is not outstanding.

Important Files Changed

Filename Overview
docs/features/mixture_of_experts/mixture_of_experts.rst Adds the central MoE guide and accurately connects routing, permutation, grouped computation, and expert-parallel APIs.
docs/features/mixture_of_experts/moe_expert_parallel_pytorch.py Demonstrates PyTorch expert parallelism and now masks padded receive slots before combining expert outputs.
docs/features/mixture_of_experts/moe_expert_parallel_jax.py Demonstrates the required eager bootstrap, mesh-resource setup, signature recording, and functional JAX MoE call.
docs/features/mixture_of_experts/moe_layer_pytorch.py Adds a concise differentiable single-device PyTorch MoE composition example.
docs/features/mixture_of_experts/moe_layer_jax.py Adds a jitted single-device JAX MoE composition using dispatch, grouped dense, and weighted combine.
transformer_engine/jax/moe.py Improves documentation of JAX MoE behavior and public contracts without changing runtime behavior.
transformer_engine/jax/router.py Clarifies JAX router API documentation without changing routing behavior.
transformer_engine/pytorch/router.py Clarifies PyTorch router API documentation without changing routing behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Input tokens] --> B[Router scoring and top-k]
  B --> C[Token or EP dispatch]
  C --> D[Expert-contiguous tokens]
  D --> E[Grouped expert computation]
  E --> F[Token or EP combine]
  F --> G[Output in original token order]
  B -. routing weights .-> F
Loading

Reviews (2): Last reviewed commit: "[Docs] MoE: mask padded receive slots be..." | Re-trigger Greptile

Comment thread docs/features/mixture_of_experts/moe_expert_parallel_pytorch.py Outdated
…P snippet

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant