Fix rank mismatch in MaxText synthetic data sharding#4122
Open
lukebaumann wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
* Change SyntheticDataIterator to use get_input_data_sharding instead of manual 1D sharding. * This ensures the sharding spec is 2D, matching the rank of the output tensors. * Fixes AssertionError: (1, 2) in JAX sharding validation on some JAX builds. * Remove unused PartitionSpec import in synthetic_data_processing.py. * Add unit test `tests/unit/synthetic_data_test.py` to verify synthetic data sharding.
c7f9815 to
91b79f9
Compare
NuojCheng
reviewed
Jun 9, 2026
| self.config = config | ||
| data_pspec = sharding.remove_size_one_mesh_axis(P(*config.data_sharding), mesh) | ||
| data_pspec_shardings = jax.tree_util.tree_map(lambda p: jax.sharding.NamedSharding(mesh, p), data_pspec) | ||
| data_pspec_shardings = sharding.get_input_data_sharding(config, mesh) |
Collaborator
There was a problem hiding this comment.
love you are using functions in sharding.py!
NuojCheng
reviewed
Jun 9, 2026
| "enable_checkpointing": False, | ||
| "dataset_type": "synthetic", | ||
| "model_name": "llama3.1-8b", | ||
| "max_target_length": 16, |
Collaborator
There was a problem hiding this comment.
could you add another testing instance using explicit sharding? Basically everything are same except adding shard_mode=explicit? Explicit sharding data pipeline has been broken but never get protected.
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 PR fixes a rank mismatch issue in MaxText synthetic data sharding during data loading.
Root Cause
SyntheticDataIteratorwas using the legacyconfig.data_shardingwhich resolved to a 1D sharding specP(('data', 'fsdp'))(after filtering). When applied to 2D output tensors of shape(batch, seq), JAX sharding validation failed withAssertionError: (1, 2)(rank mismatch) on JAX builds that strictly enforce this check.Solution
Modified
SyntheticDataIteratorto usesharding.get_input_data_sharding(config, mesh). This helper usesconfig.input_data_sharding_logical_axeswhich correctly resolves to a 2D sharding specP(('data', 'fsdp'), None), matching the rank of the output tensors.Also removed the unused
PartitionSpec as Pimport insynthetic_data_processing.py.Tests
Added a new unit test
tests/unit/synthetic_data_test.pywhich:SyntheticDataIteratorwith llama3.1-8b config.(8, 16)and sharding is exactlyP(('data', 'fsdp'), None).Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.