Skip to content

[JAX] Fix partitioning issues in LayerNorm and LayerNormMLP layers #1743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jberchtold-nvidia
Copy link
Collaborator

@jberchtold-nvidia jberchtold-nvidia commented May 1, 2025

Description

Fixes two issues occurring in MaxText integration with TE. 1) NaNs caused on multi-gpu usage of the LayerNormMLP layer 2) Partitioning shape mismatch errors caused by using TE's LayerNorm layer with TP>1

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

  • Add additional shape checks on TE/JAX cpp extension for dact to ensure we pass the correct shapes after partitioning and don't implicitly assume dz and x are the same shape.
  • In the dact primitive, make dz always use the same partitioning as x. In combination with the checks above, this prevents NaNs from running dact on dz and x partitioned differently leading to out of bounds reads.
  • In the norm primitive, make the input x not partition along the TP axis. This prevents partitioning shape errors we were encountering where x was partitioned along TP but the norm output wasn't.

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 jberchtold-nvidia changed the title [Draft] Enforce input sharding of norm primitive does not shard hidden dim [JAX] Fix MaxText integration issues in partitioning with LayerNorm and LayerNormMLP layers May 2, 2025
@jberchtold-nvidia jberchtold-nvidia force-pushed the dev/jberchtold/fix-issues-for-maxtext-integration branch from 5350e48 to 1260f07 Compare May 2, 2025 21:43
@jberchtold-nvidia jberchtold-nvidia marked this pull request as ready for review May 2, 2025 21:43
@jberchtold-nvidia jberchtold-nvidia requested a review from phu0ngng May 2, 2025 21:43
@jberchtold-nvidia
Copy link
Collaborator Author

/te-ci L0

@phu0ngng phu0ngng changed the title [JAX] Fix MaxText integration issues in partitioning with LayerNorm and LayerNormMLP layers [JAX] Fix partitioning issues in LayerNorm and LayerNormMLP layers May 3, 2025
Comment on lines 278 to 282
NVTE_CHECK(act_len == 1 || act_len == 2,
"The value of the activation dimension (axis=-2) must be 1 for non-gated or 2 for "
"gated activation, got ",
act_len);
checkDActShapes(input_buf, act_input_buf, output_buf);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should be able to check all of these requirements in the Primitive, in the abstract() or/and lowering().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I guess checking in the abstract will enforce the full shape and the sharded shape as we call the abstract again on the inner sharded primitive

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved this check to the abstract function in python and confirmed it still catches the issue when the partitioning fix isn't applied

@jberchtold-nvidia
Copy link
Collaborator Author

/te-ci L0

Copy link
Collaborator

@phu0ngng phu0ngng left a comment

Choose a reason for hiding this comment

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

LGTM

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.

2 participants