Skip to content

[JAX] Add JAX SiTU fallback to MoEBlock - #3928

Open
pggPL wants to merge 19 commits into
NVIDIA:mainfrom
pggPL:jax_moe_situ
Open

pggPL wants to merge 19 commits into
NVIDIA:mainfrom
pggPL:jax_moe_situ

Conversation

@pggPL

@pggPL pggPL commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Follow-up to NVIDIA/TransformerEngine#3873, now merged into main. Add a pure JAX SiTU-GLU fallback to MoEBlock for BF16 and configurations where the cuDNN Frontend fusions do not apply. No group-aware activation kernels are added.

Eligible MXFP8 configurations continue using cuDNN SiTU-GLU/dGLU fusion. With use_cudnn_fusion=False, or when fusion is unavailable, evaluate both soft caps in FP32 using JAX between the existing grouped GEMMs and compute both branch gradients with jax.vjp. Device expert counts mask inactive values and gradients, including NaN-filled receive-buffer tails. Activation output keeps the projection dtype, and fallback MXFP8 quantization remains separate. Ineligible fusion requests warn and fall back using the existing MoE policy.

Validation below applies to the preceding head 2a9e329. After updating to main (a6393d0), validated 59 focused cases on RTX 5880 Ada, using the actual shared parameter and tensor classes, existing activation/VJP routines and complete per-shard forward/backward source. This includes existing default/custom parameter-forwarding tests with mocked cuDNN, fusion selection for SM89/100/103/107, FP32/FP16/BF16 activation and gradient checks, inactive/empty capacity, dynamic counts, vmap/rematerialization, and forward/backward composition with early/late routing weights, biases and SwiGLU controls. Native grouped GEMM/quantization are JAX test doubles in the backward harness; this is not a full TE/EP or fused-cuDNN GPU integration result. Also passed 48 existing adapter compatibility cases on CPU, full JAX/common Python lint (10.00/10), pre-commit, source license and diff checks. Distributed SiTU cases are prepared in the existing MoE suite; full Blackwell/NCCL/EP and Kimi-K3 training were not rerun. The latest FP32 GLU forward/recomputation update (7cacedb5) has passed Python syntax, static precision-path and git diff checks only. Its GPU/pre-commit rerun is pending: workstation access currently times out.

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

  • Match native PyTorch GLU precision: compute the fallback activation product and its early-weighting recomputation in FP32, then cast to the projection dtype; the shared backward already uses FP32 intermediates. Align the pure-JAX numerical reference.
  • Add SiTU gate/up operations to the shared activation converter and reuse _jax_act_lu / _jax_quantize_dact_dbias in MoE, with capacity masking at the call sites.
  • Reuse the activation string and shared ActivationParams plumbing introduced in NVIDIA/TransformerEngine#3873.
  • Allow SiTU with disabled or unsupported cuDNN fusion, retaining existing eligible fusion selection.
  • Preserve projection dtypes, early routing-weight gradients, grouped GEMMs and grouped quantization.
  • Cover fallback behavior and update the existing API, distributed numerical tests and documentation.

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

pggPL and others added 19 commits November 16, 2026 11:45
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>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Reuse the upstream SiTU activation string and ActivationParams container. Keep eligible cuDNN fusion and use masked JAX activation operations with a VJP for unfused execution.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Define SiTU gate and up operations in the existing parameter-aware activation converter. Use one masked gated-activation helper and VJP for SiTU and SwiGLU, and move fallback documentation from the API index to the moe parameters.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Remove _apply_ffn_activation and call the existing JAX activation and VJP routines. Keep receive-capacity masking at the MoE call sites and exercise the actual forward/backward composition.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…FN fallback tests

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 marked this pull request as ready for review November 24, 2026 20:40
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Summary

Adds a JAX SiTU-GLU fallback between the existing grouped GEMMs.

  • JAX MoEBlock runs SiTU-GLU when cuDNN fusion is unavailable.

No actionable issues were found. No runtime tests were run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[MoE call] --> B{cuDNN fusion eligible?}
  B -->|Yes| C[Fused grouped GEMM and SiTU]
  B -->|No| D[Grouped FC1 GEMM]
  D --> E[Mask unused rows]
  E --> F[FP32 JAX SiTU]
  F --> G[Cast to projection dtype]
  G --> H[Separate grouped quantization]
  C --> I[Grouped FC2 GEMM]
  H --> I
  I --> J[Combine expert outputs]
Loading

Reviews (1) · Last reviewed commit: "[JAX] Simplify SiTU fallback unit tests" · Reviewed by Greptile

This branch has not been deployed

No deployments
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