Refactor multi-domain PyGrain dataset mixtures to use MapDataset.mix - #5037
Draft
snehalv2002 wants to merge 1 commit into
Draft
Refactor multi-domain PyGrain dataset mixtures to use MapDataset.mix#5037snehalv2002 wants to merge 1 commit into
snehalv2002 wants to merge 1 commit into
Conversation
- Mix ArrayRecord datasets via grain.MapDataset.mix instead of IterDataset.mix - Eliminate thread pool explosion (reduces active thread pools from 35xW to 1xW) - Resolve host CPU RAM memory growth and container OOM crashes - Enable grain_use_elastic_iterator=True for dataset mixtures in types.py - Add 35-domain benchmark profiling harness and unit tests
There was a problem hiding this comment.
Code Review
This pull request enables support for dataset mixtures when using the elastic iterator (grain_use_elastic_iterator=True). It refactors the input pipeline in grain_data_processing.py to mix datasets at the MapDataset level rather than the IterDataset level, ensuring that only a single thread pool is used and iterator state is preserved. Additionally, it introduces a benchmarking harness (benchmark_data_mixture.py), a mixture configuration generator, and unit tests to validate these changes. There are no review comments provided, so I have no further feedback to offer.
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
Refactors multi-domain dataset mixtures in MaxText's PyGrain data loader (
get_datasets()insrc/maxtext/input_pipeline/grain_data_processing.py) to mix at thegrain.MapDatasetlevel (grain.MapDataset.mix) instead of converting each dataset component to anIterDatasetprior to mixing.Problem Being Solved & Context
When scaling multi-domain dataset mixtures (e.g., 35 domains in ArrayRecord format) on large Cloud TPU clusters (e.g. 512-chip Cloud TPU v6e / 64 hosts), stock MaxText suffered from:
_apply_mapdataset_transforms()on every domain individually beforegrain.IterDataset.mix(), instantiating.to_iter_dataset()reader thread pools per worker process (grain_use_elastic_iterator=Truewas previously forbidden for dataset mixtures becauseget_datasets()returned anIterDatasetrather than aMapDataset.Why This is a Good Solution
get_datasets()now returns a pureMapDataset,grain_use_elastic_iterator=Truecan now be used with multi-domain dataset mixtures.Implementation Details
src/maxtext/input_pipeline/grain_data_processing.py:MapDatasets.grain.MapDataset.mix(dataset_list, weights).to_iter_dataset()once at the top level for the entire mixture (or returns theMapDatasetdirectly ifelastic=True).src/maxtext/configs/types.py:grain_use_elastic_iterator=Truewhengrain_train_mixture_config_pathor semicolon-separatedgrain_train_filesare set.tests/unit/grain_data_processing_test.py:GrainArrayRecordProcessingWithMixtureConfigAndElasticIteratorTestto verify mixtures withgrain_use_elastic_iterator=True.tests/benchmark_data_mixture.pyandtests/generate_mixture_config.py.Shortcomings & Future Improvements
grain_worker_countdynamically on a restored checkpoint using standardmp_prefetchstill encounters worker queue indexing constraints in PyGrain (grain._src.python.dataset.transformations.interleave). Full bidirectional worker elasticity (grain_use_elastic_iterator=True.Tests
Tested extensively on remote TPU v5p ($W \in {2, 4, 8}$ :
maxtext-single-host-3-v5p-8) using a 35-domain ArrayRecord C4 mixture over 200 steps across worker countsIterDataset.mix(Baseline)MapDataset.mix(This PR)Commands to Reproduce Benchmarks
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.