Add custom mesh and logical rule support#3438
Merged
copybara-service[bot] merged 1 commit intomainfrom Mar 19, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
e8b2fd0 to
3a762a3
Compare
3a762a3 to
47b22db
Compare
gobbleturk
reviewed
Mar 18, 2026
gobbleturk
reviewed
Mar 18, 2026
gobbleturk
reviewed
Mar 18, 2026
gobbleturk
reviewed
Mar 18, 2026
gobbleturk
reviewed
Mar 18, 2026
gobbleturk
reviewed
Mar 18, 2026
gobbleturk
requested changes
Mar 18, 2026
Collaborator
gobbleturk
left a comment
There was a problem hiding this comment.
I love the idea of increased visibility and sharability!
2b2826a to
77b676e
Compare
77b676e to
cf5ac08
Compare
cf5ac08 to
307bc11
Compare
gobbleturk
approved these changes
Mar 19, 2026
Collaborator
gobbleturk
left a comment
There was a problem hiding this comment.
Let the sharding sharing begin!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces the ability to define and use customized physical meshes and logical axis rules in MaxText via external YAML configuration files. This enhances flexibility for complex parallelism strategies, such as those required for large scale MoE setups.
Key Changes
Configuration Enhancements
custom_mesh_and_rulefield tobase.yml.src/maxtext/configs/types.pyto automatically loadmesh_axes,logical_axis_rules, anddata_shardingfrom specified YAML files located insrc/maxtext/configs/custom_mesh_and_rule/.pure-fsdp.ymland a complexds3-large-pp.yml.Robust Utility Functions
src/maxtext/utils/max_utils.pyfor safer access to mesh properties:get_mesh_axes_size: Returns the size of a physical axis or 1 if it doesn't exist.get_logical_rule_contents: Safely retrieves physical axes corresponding to a logical name.Code Refactoring for Mesh Flexibility
src/maxtext/layers/attention_op.py,src/maxtext/utils/sharding.py, andsrc/maxtext/utils/train_utils.pyto use the new utility functions. This ensures the model can compile even when standard axes (likedataorfsdp) are absent or redefined in a custom mesh.Tests
Added
tests/unit/custom_mesh_and_rule_test.pyto verify successful compilation using the new custom mesh flags for both FSDP and multi-axis configurations.Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.