Skip to content

[JAX] Optimize MoE block - #3354

Open
jberchtold-nvidia wants to merge 48 commits into
NVIDIA:mainfrom
jberchtold-nvidia:jberchtold/moeblock-debug
Open

[JAX] Optimize MoE block#3354
jberchtold-nvidia wants to merge 48 commits into
NVIDIA:mainfrom
jberchtold-nvidia:jberchtold/moeblock-debug

Conversation

@jberchtold-nvidia

@jberchtold-nvidia jberchtold-nvidia commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Description

Improves performance of the MoE block by exposing support for quantization, removal of unnecessary masking overheads, and support for less memory usage via a reduced receive capacity in TE EP

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • Direct support for MXFP8 quantization in the MoE block along with corresponding tests
  • Removal of additional overheads like jnp.where masking that wasn't required as TE EP and grouped GEMM are group-aware
  • Support for a reduced receive capacity and integration with TE EP's overflow detection

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

jberchtold-nvidia and others added 30 commits May 26, 2026 16:12
Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com>
Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com>
Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com>
Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com>
Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com>
Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com>
Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com>
…mm-custom-partition-rules

# Conflicts:
#	qa/L1_jax_distributed_unittest/test.sh
@jberchtold-nvidia
jberchtold-nvidia marked this pull request as draft August 12, 2026 14:47
@greptile-apps

greptile-apps Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR optimizes the JAX expert-parallel MoE block by adding grouped MXFP8 quantization, configurable receive capacity, and a contiguous FC1 kernel layout.

  • Threads independent FC1/FC2 quantizer sets through the custom VJP.
  • Adds aligned receive-capacity calculation and overflow integration.
  • Reworks grouped-GEMM sharding and residual handling.
  • Extends distributed BF16 and MXFP8 numerical tests.

Confidence Score: 4/5

The PR is not yet safe to merge because legacy _MoEBlock checkpoints and optimizer states cannot be restored into the new parameter tree without migration.

Current HEAD still replaces wi_0 and wi_1 with a single differently shaped wi parameter and provides no adapter for previously persisted Flax variables or optimizer state.

Files Needing Attention: transformer_engine/jax/flax/moe.py

Important Files Changed

Filename Overview
transformer_engine/jax/flax/moe.py Adds recipe-driven grouped quantizers and receive-capacity plumbing while replacing two FC1 parameter leaves with one contiguous kernel; legacy checkpoint compatibility remains outstanding.
transformer_engine/jax/moe.py Reworks the MoE custom VJP for quantized grouped GEMMs, global sharding, and reduced receive capacity.
transformer_engine/jax/cpp_extensions/quantization.py Permits stateless MXFP8 grouped quantizers whose global descriptor contains at least the shard-local group count.
transformer_engine/jax/quantize/tensor.py Adjusts grouped quantized-tensor handling needed by the new MoE sharding path.
tests/jax/test_te_ep_moe.py Expands distributed MoE parity coverage to BF16 and Blackwell MXFP8 using the contiguous FC1 layout.
tests/jax/run_te_ep_moe.sh Allows callers to override the distributed MoE test file through TEST_FILE.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Flax _MoEBlock] --> B[Gate and top-k routing]
  B --> C[EP dispatch]
  C --> D[Grouped FC1 quantize and GEMM]
  D --> E[SwiGLU]
  E --> F[Grouped FC2 quantize and GEMM]
  F --> G[EP combine]
  H[Receive capacity] --> C
  I[FC1 and FC2 quantizer sets] --> D
  I --> F
Loading

Reviews (2): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile

Comment thread transformer_engine/jax/flax/moe.py
@jberchtold-nvidia
jberchtold-nvidia force-pushed the jberchtold/moeblock-debug branch from 9dd563e to 1c98135 Compare August 12, 2026 16:18
@jberchtold-nvidia
jberchtold-nvidia force-pushed the jberchtold/moeblock-debug branch from b8f3816 to da9ad94 Compare August 12, 2026 21:41
@jberchtold-nvidia
jberchtold-nvidia force-pushed the jberchtold/moeblock-debug branch from 8d5d1b8 to 0dbf8a5 Compare August 13, 2026 15:31
@jberchtold-nvidia
jberchtold-nvidia force-pushed the jberchtold/moeblock-debug branch from 072422b to 0645751 Compare August 13, 2026 15:49
@nvMelissa nvMelissa added the 2.19 label Aug 13, 2026
@jberchtold-nvidia

Copy link
Copy Markdown
Collaborator Author

/te-ci L1 jax

@jberchtold-nvidia
jberchtold-nvidia force-pushed the jberchtold/moeblock-debug branch from d9fa28c to bc28b24 Compare August 13, 2026 23:47
@jberchtold-nvidia

Copy link
Copy Markdown
Collaborator Author

/te-ci L1 jax

@jberchtold-nvidia
jberchtold-nvidia force-pushed the jberchtold/moeblock-debug branch from ca32c8d to ec09e5a Compare August 14, 2026 14:13
@jberchtold-nvidia

Copy link
Copy Markdown
Collaborator Author

/te-ci L1 jax

@jberchtold-nvidia
jberchtold-nvidia marked this pull request as ready for review August 14, 2026 17:55
@jberchtold-nvidia jberchtold-nvidia changed the title [DRAFT][JAX] Optimize MoE block [JAX] Optimize MoE block Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants