Skip to content

Commit ffe3240

Browse files
committed
[Common][PyTorch] Add MoE EP communication/GEMM overlap ops (FusedMoE) with in-call weight gradients for BF16 and MXFP8
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
1 parent 0f65420 commit ffe3240

38 files changed

Lines changed: 6985 additions & 79 deletions

‎3rdparty/nccl-extensions‎

‎docs/api/pytorch.rst‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,20 @@ NCCL-based dispatch and combine for experts sharded across ranks. See
129129

130130
``MoeDispatch`` and ``MoeCombine`` can wrap the local expert operations in a
131131
``transformer_engine.pytorch.ops.Sequential``. They share an ``EpConfig`` and
132-
an ``EpBuffer``; the guide shows how to connect the per-expert counts and
133-
routing weights through the sequence's extra-tensor channels.
132+
an ``EpBuffer``. A buffer holds the routing state of one call until its backward has run, so
133+
several calls in flight (for example pipeline microbatches) each need their own ``EpBuffer`` and
134+
op instance. The guide shows how to connect the per-expert counts and routing weights through the
135+
sequence's extra-tensor channels. ``moe_overlap_supported`` tells whether such a sequence runs as
136+
one fused op.
134137

135138
.. autoapiclass:: transformer_engine.pytorch.ops.MoeDispatch
136139

137140
.. autoapiclass:: transformer_engine.pytorch.ops.MoeCombine
138141

142+
.. autoapifunction:: transformer_engine.pytorch.ops.moe_overlap_supported
143+
144+
.. autoapifunction:: transformer_engine.pytorch.ops.moe_overlap_unsupported_reason
145+
139146
.. autoapiclass:: transformer_engine.pytorch.ep.EpConfig
140147

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

‎docs/envvars.rst‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,27 @@ General
161161
``WARN`` emits a warning explaining why CuTeDSL kernels are unavailable and falls back to CUDA kernels. ``ERROR`` raises an error and fails instead.
162162
Only effective when the CuTeDSL backend is enabled (see :envvar:`NVTE_ENABLE_CUTEDSL_BACKEND`).
163163

164+
.. envvar:: NVTE_MOE_OVERLAP
165+
166+
:Type: ``str`` (directory)
167+
:Default: unset (overlap off)
168+
:Description: Directory of the CuTeDSL grouped GEMMs that overlap the NCCL EP dispatch and
169+
combine with the expert GEMMs (``ep_gemm.h``, used by the fused
170+
:class:`transformer_engine.pytorch.ops.MoeDispatch` expert MLP). The overlap is
171+
off unless this is set together with ``NVTE_ENABLE_CUTEDSL_BACKEND=1``; then
172+
``ep_bootstrap`` defaults to 24 communication SMs unless ``max_num_sms`` is
173+
given. Otherwise the unfused ops run. The directory is the ``gemm/`` tree of
174+
the EPCompOverlap kernel sources (with ``blackwell/``, ``rubin/`` and
175+
``utils/``); its modules are imported by name and their version is not checked.
176+
177+
.. envvar:: NVTE_EP_OVERLAP_COMBINE_CHUNK_COLS
178+
179+
:Type: ``int``
180+
:Default: 1024 when it divides the hidden size, else the whole row
181+
:Description: Hidden columns of the overlapped combine per readiness flag (see
182+
:envvar:`NVTE_MOE_OVERLAP`). The hidden size or a multiple of 1024 dividing it.
183+
Smaller values let the combine start earlier but cost more flags to set and poll.
184+
164185
.. envvar:: NVTE_GROUPED_TENSOR_HANDLE_POOL_SIZE_MB
165186

166187
:Type: ``int`` (positive integer)

0 commit comments

Comments
 (0)