Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
3637508
[Docs] Add MoE feature overview
pggPL May 4, 2026
c497c81
[Docs] Refine MoE overview, add supporting snippets/figures and JAX A…
pggPL May 5, 2026
f905bbd
[Docs] Extend MoE overview: router, end-to-end layer, padding, low-pr…
pggPL Jun 24, 2026
ce3c799
Merge remote-tracking branch 'upstream/main' into docs_moe
pggPL Jun 24, 2026
82ec7d5
[Docs] MoE: fused grouped MLP and expert parallelism sections
pggPL Sep 7, 2026
dbc2b04
Merge remote-tracking branch 'origin/main' into docs_moe
pggPL Sep 7, 2026
f66df65
[Docs] MoE: split into per-topic pages, match current docs style, doc…
pggPL Sep 7, 2026
8cbeadf
[Docs] MoE: single article with sections, redraw expert parallelism d…
pggPL Sep 7, 2026
2758490
[Docs] MoE: warn about uneven low-precision support
pggPL Sep 7, 2026
c850a45
[Docs] MoE: shorten low-precision warning
pggPL Sep 7, 2026
ae16f61
[Docs] MoE: reword low-precision note
pggPL Sep 7, 2026
b8f5625
[Docs] MoE: drop API-reference pointer from low-precision note
pggPL Sep 7, 2026
473273f
[Docs] MoE: reorganize into introduction, routing kernels, grouped GE…
pggPL Sep 7, 2026
ff4da34
[Docs] MoE: move end-to-end example to the end of the article
pggPL Sep 7, 2026
90624cb
[Docs] MoE: add expert-parallel layer diagram to the end-to-end example
pggPL Sep 7, 2026
c1460e6
[Docs] MoE: use expert-parallel layer diagram as Figure 1, mention EP…
pggPL Sep 7, 2026
bd5c926
[Docs] MoE: fold EP into the stage list, surface load balancing in th…
pggPL Sep 7, 2026
23392d1
[Docs] MoE: explain grouped routing, simplify router wording
pggPL Sep 7, 2026
ccdfef4
[Docs] MoE: deduplicate expert_bias description
pggPL Sep 7, 2026
9aeff33
[Docs] MoE: move routing-kernels lead paragraphs above the router sub…
pggPL Sep 7, 2026
9c52362
[Docs] MoE: describe what the blocks do and how to use them; move fra…
pggPL Sep 7, 2026
8cae00b
[Docs] MoE: describe grouped GEMM execution paths; shorten grouped ML…
pggPL Sep 7, 2026
4960ac3
[Docs] MoE: move grouped GEMM paths above snippet; simplify grouped M…
pggPL Sep 7, 2026
f8eed3d
[Docs] MoE: EP dispatch/combine replace token dispatch/combine; redra…
pggPL Sep 7, 2026
a852117
[Docs] MoE: split routing kernels into Router and Token permutation s…
pggPL Sep 7, 2026
fa068ef
[Docs] MoE: fix EP figure dispatch arrows; animate dispatch and combine
pggPL Sep 7, 2026
20bc2ac
[Docs] MoE: drop EP figure animation
pggPL Sep 7, 2026
d9b260e
[Docs] MoE: restructure expert parallelism (overview, common API, per…
pggPL Sep 7, 2026
2b66b28
[Docs] MoE: EP back in tabs without C API; describe sort_chunks_by_index
pggPL Sep 7, 2026
86afa76
[Docs] MoE: EP placement figure matches flow figure; clarify capacity…
pggPL Sep 7, 2026
dfc3a19
[Docs] MoE: break long paragraphs into lists
pggPL Sep 7, 2026
a0eec9b
[Docs] MoE: explain NCCL EP and zero-copy mode; link examples
pggPL Sep 7, 2026
2ea91cb
[Docs] MoE: EP wording (optimized ops, worst-case capacity, MXFP8 sta…
pggPL Sep 7, 2026
6b144c9
[Docs] MoE: describe EP buffer allocation and data flow (PyTorch)
pggPL Sep 7, 2026
4ffa15f
[Docs] MoE: clarify what EpBuffer holds and when to reuse it
pggPL Sep 7, 2026
3bda8aa
[Docs] MoE: spell out the JAX EP primitives
pggPL Sep 7, 2026
11dec2e
[Docs] MoE: precise wording for MXFP8 dispatch output
pggPL Sep 7, 2026
7edde44
[Docs] MoE: restructure EP overview along one step (buffer, payload, …
pggPL Sep 7, 2026
490e922
[Docs] MoE: EP overview headings and terser bullets
pggPL Sep 7, 2026
df27819
[Docs] MoE figures: larger fonts, fix label anchors and clipping, dro…
pggPL Sep 7, 2026
1368387
[Docs] MoE: EP overview - one-step permutation, buffer sizing modes, …
pggPL Sep 7, 2026
3132e40
[Docs] MoE: drop zero-copy block from EP overview
pggPL Sep 7, 2026
c7969b4
[Docs] MoE: shorten EpBuffer bullet
pggPL Sep 7, 2026
9e35df2
[Docs] MoE: merge PyTorch EP API and data-flow lists
pggPL Sep 7, 2026
dccd20c
[Docs] MoE: describe EP backward (PyTorch)
pggPL Sep 7, 2026
e27418c
[Docs] MoE: one-step dispatch figure; capacity sizing guidance
pggPL Sep 7, 2026
94331f7
[Docs] MoE: single-device example before expert parallelism
pggPL Sep 7, 2026
b9a77d7
[Docs] MoE: receive buffer block as nested bullets with overflow beha…
pggPL Sep 7, 2026
ee9f01a
[Docs] MoE: drop EP backward bullet
pggPL Sep 7, 2026
bf2dd4c
[Docs] MoE: larger row labels in layer figure
pggPL Sep 7, 2026
c41e6ad
[Docs] Fix MoE routing guidance and examples
pggPL Sep 7, 2026
e3c801d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 7, 2026
46978f0
[Docs] Fix RST in router and moe docstrings so the API pages build wi…
pggPL Sep 8, 2026
1594431
Merge remote-tracking branch 'upstream/main' into docs_moe
pggPL Sep 8, 2026
6ce06cd
[Docs] MoE: mask padded receive slots before combine in the PyTorch E…
pggPL Sep 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/_static/css/diagram-colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,38 @@ html[data-theme="dark"] .subtitle,
html[data-theme="dark"] .memory-label { fill: #e0e0e0; }
html[data-theme="dark"] .connector { stroke: #bdbdbd; }

/* mixture_of_experts diagrams */
html[data-theme="dark"] .small-label,
html[data-theme="dark"] .tiny-label,
html[data-theme="dark"] .row-label,
html[data-theme="dark"] .rank-label { fill: #bdbdbd; }
html[data-theme="dark"] .grid-title,
html[data-theme="dark"] .brace-label,
html[data-theme="dark"] .row-label-l,
html[data-theme="dark"] .row-label-r,
html[data-theme="dark"] .mono { fill: #e0e0e0; }
html[data-theme="dark"] .expert-e0 { fill: #10375c; stroke: #64b5f6; }
html[data-theme="dark"] .expert-e1 { fill: #1e4620; stroke: #81c784; }
html[data-theme="dark"] .expert-e2 { fill: #5c3a10; stroke: #ffb74d; }
html[data-theme="dark"] .expert-e3 { fill: #5c1f38; stroke: #f48fb1; }
html[data-theme="dark"] .stage,
html[data-theme="dark"] .grouped,
html[data-theme="dark"] .a2a,
html[data-theme="dark"] .fused-mlp { fill: #3a2f5c; stroke: #b39ddb; }
html[data-theme="dark"] .moe-op { fill: #10375c; stroke: #64b5f6; }
html[data-theme="dark"] .act,
html[data-theme="dark"] .sel { fill: #1e4620; stroke: #81c784; }
html[data-theme="dark"] .linear,
html[data-theme="dark"] .param,
html[data-theme="dark"] .hbm,
html[data-theme="dark"] .cell,
html[data-theme="dark"] .box { fill: #2b2b2b; stroke: #9e9e9e; }
html[data-theme="dark"] .unsel,
html[data-theme="dark"] .pad { fill: #1f1f1f; stroke: #616161; }
html[data-theme="dark"] .soft-arrow,
html[data-theme="dark"] .brace { stroke: #bdbdbd; }
html[data-theme="dark"] .skip,
html[data-theme="dark"] .farrow { stroke: #b39ddb; }

/* fine_grained_quantization diagrams */
html[data-theme="dark"] .fmt-mxfp8 { fill: #10375c; stroke: #64b5f6; }
Expand Down
28 changes: 28 additions & 0 deletions docs/api/jax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,31 @@ Modules
:members: __call__

.. autoapifunction:: transformer_engine.jax.flax.extend_logical_axis_rules


Mixture of Experts
------------------
Router, routing kernels, and grouped dense for MoE layers. See
:doc:`Mixture of Experts <../features/mixture_of_experts/mixture_of_experts>` for an overview.

.. autoapifunction:: transformer_engine.jax.router.fused_topk_with_score_function

.. autoapifunction:: transformer_engine.jax.router.fused_moe_aux_loss

.. autoapifunction:: transformer_engine.jax.permutation.token_dispatch

.. autoapifunction:: transformer_engine.jax.permutation.token_combine

.. autoapifunction:: transformer_engine.jax.permutation.sort_chunks_by_index

.. autoapifunction:: transformer_engine.jax.dense.grouped_dense

.. autoapifunction:: transformer_engine.jax.moe.moe

.. autoapifunction:: transformer_engine.jax.ep.ep_bootstrap

.. autoapifunction:: transformer_engine.jax.ep.ep_finalize

.. autoapifunction:: transformer_engine.jax.ep.ep_dispatch

.. autoapifunction:: transformer_engine.jax.ep.ep_combine
28 changes: 28 additions & 0 deletions docs/api/pytorch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,44 @@ Recipe availability
Mixture of Experts (MoE) functions
----------------------------------

See :doc:`Mixture of Experts <../features/mixture_of_experts/mixture_of_experts>` for an overview of
how these functions fit together. ``GroupedLinear`` (the grouped GEMM used for the
expert layers) is documented above with the other modules.

.. autoapifunction:: transformer_engine.pytorch.moe_permute

.. autoapifunction:: transformer_engine.pytorch.moe_permute_with_probs

.. autoapifunction:: transformer_engine.pytorch.moe_permute_and_pad_with_probs

.. autoapifunction:: transformer_engine.pytorch.moe_unpermute

.. autoapifunction:: transformer_engine.pytorch.moe_sort_chunks_by_index

.. autoapifunction:: transformer_engine.pytorch.moe_sort_chunks_by_index_with_probs

.. autoapifunction:: transformer_engine.pytorch.router.fused_topk_with_score_function

.. autoapifunction:: transformer_engine.pytorch.router.fused_compute_score_for_moe_aux_loss

.. autoapifunction:: transformer_engine.pytorch.router.fused_moe_aux_loss

Expert parallelism
~~~~~~~~~~~~~~~~~~

NCCL-based dispatch and combine for experts sharded across ranks. See
:doc:`Expert parallelism <../features/mixture_of_experts/mixture_of_experts>`.

.. autoapifunction:: transformer_engine.pytorch.ep.ep_bootstrap

.. autoapifunction:: transformer_engine.pytorch.ep.ep_finalize

.. autoapiclass:: transformer_engine.pytorch.ep.EpBuffer

.. autoapifunction:: transformer_engine.pytorch.ep.ep_dispatch

.. autoapifunction:: transformer_engine.pytorch.ep.ep_combine


Communication-computation overlap
---------------------------------
Expand Down
33 changes: 33 additions & 0 deletions docs/features/mixture_of_experts/grouped_linear_jax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# See LICENSE for license information.

# START_GROUPED_LINEAR_JAX
import jax.numpy as jnp
from transformer_engine.jax import dense as te_dense

# x: [sum(group_sizes), hidden_size], expert-contiguous tokens
# kernel: [num_experts, hidden_size, ffn_hidden_size], stacked per-expert weights
# bias: [num_experts, ffn_hidden_size], stacked per-expert biases
# group_sizes: [num_experts] int array; group_sizes[i] is the number of routed
# tokens for expert i
split_indices = jnp.cumsum(group_sizes)[:-1]
x_by_expert = jnp.split(x, split_indices, axis=0)

# Baseline: one matmul per expert.
loop_out = jnp.concatenate(
[x_i @ kernel_i + bias_i for x_i, kernel_i, bias_i in zip(x_by_expert, kernel, bias)],
axis=0,
)

# Transformer Engine: one grouped dense call. group_sizes is a device array.
# On Blackwell, BF16 and MXFP8 inputs without bias run as a single grouped GEMM
# with the group sizes kept on the device; other cases launch one GEMM per
# expert and copy group_sizes to the host first.
grouped_out = te_dense.grouped_dense(
x,
kernel,
group_sizes=group_sizes,
bias=bias,
)
# END_GROUPED_LINEAR_JAX
47 changes: 47 additions & 0 deletions docs/features/mixture_of_experts/grouped_linear_pytorch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# See LICENSE for license information.

# START_GROUPED_LINEAR_PYTORCH
import torch
import transformer_engine.pytorch as te

# x: [sum(m_splits), hidden_size], expert-contiguous tokens
# m_splits: list[int] of length num_experts; m_splits[i] is the number
# of routed tokens for expert i
# torch_experts: list[torch.nn.Linear] of length num_experts, one per expert
# (used only by the baseline loop below)
x_by_expert = torch.split(x, m_splits, dim=0)

# Baseline: one Linear call per expert.
loop_out = torch.cat(
[expert(x_i) for expert, x_i in zip(torch_experts, x_by_expert)],
dim=0,
)

# Transformer Engine: one grouped linear call. By default one GEMM per expert
# is launched; m_splits is read on the host.
grouped_linear = te.GroupedLinear(
num_experts,
hidden_size,
ffn_hidden_size,
bias=True,
params_dtype=torch.bfloat16,
).cuda()
grouped_out = grouped_linear(x, m_splits)

# Single grouped GEMM with the token counts on the device (no host sync,
# CUDA-graph capturable): opt in with use_grouped_tensor=True and pass
# m_splits as a CUDA int64 tensor. Falls back to per-expert GEMMs when the
# recipe / GPU / cuBLAS version does not support it.
grouped_linear = te.GroupedLinear(
num_experts,
hidden_size,
ffn_hidden_size,
bias=True,
params_dtype=torch.bfloat16,
use_grouped_tensor=True,
).cuda()
m_splits_dev = torch.tensor(m_splits, dtype=torch.int64, device="cuda")
grouped_out = grouped_linear(x, m_splits_dev)
# END_GROUPED_LINEAR_PYTORCH
21 changes: 21 additions & 0 deletions docs/features/mixture_of_experts/grouped_mlp_pytorch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# See LICENSE for license information.

# START_GROUPED_MLP_PYTORCH
import transformer_engine.pytorch as te

# Build the expert MLP from the operation-based API: two grouped linear layers
# with a scaled GLU activation in between. FC1 produces 2 * ffn_hidden_size
# features (gate and value) for the GLU.
expert_mlp = te.ops.Sequential(
te.ops.GroupedLinear(num_experts, hidden_size, 2 * ffn_hidden_size),
te.ops.ScaledSwiGLU(), # or ScaledClampedQGeGLU; ScaledSReLU for the unary variant
te.ops.GroupedLinear(num_experts, ffn_hidden_size, hidden_size),
)

# When this sequence runs under a block-scaled recipe (MXFP8 or NVFP4) on a
# Blackwell (SM100) GPU with NVTE_CUTEDSL_FUSED_GROUPED_MLP=1, the operation
# fuser transparently replaces the three ops with a single fused grouped-MLP
# kernel (GroupedMLP_CuTeGEMMGLU). No code change is needed to opt in.
# END_GROUPED_MLP_PYTORCH
148 changes: 148 additions & 0 deletions docs/features/mixture_of_experts/img/grouped_linear.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading