Skip to content

[DRAFT][JAX] Optimize MoE block - #3354

Draft
jberchtold-nvidia wants to merge 46 commits into
NVIDIA:mainfrom
jberchtold-nvidia:jberchtold/moeblock-debug
Draft

[DRAFT][JAX] Optimize MoE block#3354
jberchtold-nvidia wants to merge 46 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
This reverts commit 97ba329.

This is no longer necessary with
"--xla_gpu_experimental_max_unroll_factor=8". The performance of the
previous approach is fixed with the previous JAX code and this XLA flag
…oeblock-debug

# Conflicts:
#	tests/jax/test_te_ep_moe.py
#	transformer_engine/jax/moe.py
@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 substantially optimizes the JAX MoE path by combining FC1 projections, adding distributed grouped-quantize/GEMM partitioning, expanding EP diagnostics and receive-capacity handling, and adding distributed coverage. It also changes the exported Flax MoE parameter layout without checkpoint migration.

  • Reworks JAX MoE forward/backward execution and expert-parallel sharding.
  • Adds grouped quantization and grouped GEMM custom partitioning for DP/FSDP/EP layouts.
  • Adds EP handle tracing and cache-update diagnostics.
  • Expands single- and multi-process distributed MoE/grouped-GEMM tests.

Confidence Score: 4/5

The Flax MoE checkpoint incompatibility should be addressed before merging so existing parameter and optimizer states remain restorable.

The changed module replaces two previously exported parameter leaves with a differently named, differently shaped leaf and provides no migration path, causing old checkpoints to fail when applied.

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

Important Files Changed

Filename Overview
transformer_engine/jax/moe.py Rewrites the MoE custom-VJP and distributed grouped-FFN path; inspected gradient and sharding branches were internally consistent.
transformer_engine/jax/flax/moe.py Combines FC1 parameters into wi, breaking restoration of parameter and optimizer trees created with wi_0 and wi_1.
transformer_engine/jax/cpp_extensions/gemm.py Adds custom partitioning and local-shape derivation for grouped GEMM across supported DP/FSDP/EP axes.
transformer_engine/jax/cpp_extensions/quantization.py Preserves logical grouped tensor ranks and adds sharding-aware MXFP8 scale carriers and partitioning.
transformer_engine/common/ep/ep_backend.cpp Adds handle-update tracking and opt-in diagnostics without an established default-path security failure.
tests/jax/test_te_ep_moe.py Greatly expands MoE numerical and distributed coverage but does not cover restoration of the previous Flax parameter tree.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Input tokens] --> B[Gate and top-k routing]
  B --> C[EP prepare and dispatch]
  C --> D[Grouped FC1 quantize and GEMM]
  D --> E[Activation and grouped FC2 GEMM]
  E --> F[EP combine]
  F --> G[MoE output]
Loading

Reviews (1): 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant