Skip to content

[JAX] Fix GEMM partitioning to reduce over nested contracting mesh axes - #3429

Merged
phu0ngng merged 4 commits into
NVIDIA:mainfrom
phu0ngng:jax/fix_gemm_partitioning
Aug 28, 2026
Merged

[JAX] Fix GEMM partitioning to reduce over nested contracting mesh axes#3429
phu0ngng merged 4 commits into
NVIDIA:mainfrom
phu0ngng:jax/fix_gemm_partitioning

Conversation

@phu0ngng

Copy link
Copy Markdown
Collaborator

Description

Please include a brief summary of the changes, relevant motivation and context.

Fixes # (issue)

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

Please list the changes introduced in this PR:

  • Change A
  • Change B

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

Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR updates JAX GEMM partition inference to reduce across every mesh axis shared by both operands’ contracting dimensions while gathering non-shared axes. It also adds CPU-based partitioning tests for Megatron TP, sequence-parallel TP, and compatibility cases.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
transformer_engine/jax/cpp_extensions/gemm.py Extends contracting-axis handling from scalar specifications to nested tuples and retains only axes participating in the reduction.
tests/jax/test_gemm_partitioning.py Adds CPU mesh tests for nested contracting-axis reductions and fixes the previously reported default-backend mesh dependency by selecting CPU devices explicitly.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  L[LHS contracting axes] --> I[Shared-axis intersection]
  R[RHS contracting axes] --> I
  I --> REDUCE[Reduction specification]
  L --> FILTER[Retain shared axes]
  R --> FILTER
  FILTER --> GEMM[Partitioned GEMM]
  GEMM --> REDUCE
Loading

Reviews (3): Last reviewed commit: "Merge branch 'main' into jax/fix_gemm_pa..." | Re-trigger Greptile

Comment thread tests/jax/test_gemm_partitioning.py Outdated
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
@xiaopoc

xiaopoc commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Tested this PR on DeepSeek-V3 with 32 H100 GPUs using TP8, DP4, EP16, FSDP2, and ETP1. The previous global WGrad buffer/all-gather disappeared, HLO now shows WGrad reduce-scatter over the tensor axis, and the training loss decreases normally. This fixes the issue I observed, thanks.

@xiaopoc xiaopoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Verified in the test described in my comment above.

@jberchtold-nvidia jberchtold-nvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, thanks! Left a couple small comments and a question

Comment thread tests/jax/test_gemm_partitioning.py
Comment thread tests/jax/test_gemm_partitioning.py Outdated
Comment thread transformer_engine/jax/cpp_extensions/gemm.py
Comment thread transformer_engine/jax/cpp_extensions/gemm.py Outdated
Comment thread tests/jax/test_gemm_partitioning.py Outdated
…ding cases

Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
@phu0ngng

Copy link
Copy Markdown
Collaborator Author

/te-ci L1 JAX

@jberchtold-nvidia jberchtold-nvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@phu0ngng
phu0ngng merged commit 609584a into NVIDIA:main Aug 28, 2026
11 of 16 checks passed
@phu0ngng
phu0ngng deleted the jax/fix_gemm_partitioning branch August 28, 2026 15:42
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.

3 participants