Repository navigation
Wire deterministic SyntheticMultimodalDataSource into Grain multimodal input pipeline - #6587
hengtaoguo wants to merge 1 commit into
Conversation
7838830 to
ba2a635
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
🤖 Hi @hengtaoguo, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
There was a problem hiding this comment.
📋 Review Summary
Verdict: Spec partially met; multimodal synthetic training works as intended, but eval batch sizing and host expansion have latent defects and the eval iterator is untested.
Top issues:
- [Bug] When
eval_per_device_batch_sizediffers fromper_device_batch_size,_make_synthetic_multimodal_iteratorassertsglobal_batch_size_to_load_evalbut discards it, whilevision_sft_preprocessing_pipelinebatches strictly byglobal_batch_size_to_load(see inline comment ongrain_data_processing.py). → Pass the resolved eval batch size into the pipeline or validate that eval and train batch sizes match. - [Bug] Clamping
expansion_loading_factor_for_grain=1on eval breaksMultiHostDataLoadIteratorwhenexpansion_factor_real_data > 1, leaving hosts with unconcatenated, undersized batches (see inline comment ongrain_data_processing.py). → Passconfig.expansion_factor_real_datadirectly, or assertexpansion_factor_real_data <= 1for multimodal data sincePlaceHolderDataIteratorlacks media keys. - [Tests]
make_synthetic_multimodal_eval_iteratoris untested because all unit tests seteval_interval=0and assertassertIsNone(see inline comment onsynthetic_multimodal_data_test.py). → Add a unit test witheval_interval > 0verifying the eval iterator produces valid batches with theseed + 1offset.
Inferred spec & validation
- Sources: PR #6587 description, PR #6515 (
SyntheticMultimodalDataSource), code before/after insrc/maxtext/input_pipeline/. - Problem:
SyntheticMultimodalDataSourcewas not wired intocreate_data_iteratorwhendataset_type=syntheticanduse_multimodal=true, preventing reproducible multimodal SFT training benchmarks without external data files.
| Spec item | Implementation | Validating test |
|---|---|---|
R1 (stated): When dataset_type="synthetic" and synthetic_modalities(config) is non-empty, create_data_iterator returns multimodal iterators backed by SyntheticMultimodalDataSource sharded via strided slice across hosts |
✅ met | synthetic_multimodal_data_test.py::SyntheticMultimodalIteratorTest.test_create_data_iterator_qwen3_vl_shapes_and_determinism ✅ |
R2 (stated): When dataset_type="synthetic" and no media modality is active, fallback to SyntheticDataIterator is preserved |
✅ met | synthetic_multimodal_data_test.py::SyntheticMultimodalIteratorTest.test_zero_images_falls_back_to_text_synthetic_iterator ✅ |
R3 (stated): Skip protobuf ParseFeatures/NormalizeFeatures when dataset_type="synthetic", retaining in-memory synthetic features via KeepFeatures |
✅ met | synthetic_multimodal_data_test.py::SyntheticMultimodalIteratorTest.test_create_data_iterator_qwen3_vl_shapes_and_determinism ✅ |
R4 (stated): Return independent multimodal eval iterator when eval_interval > 0 with seed + 1 offset |
expansion_factor_real_data > 1) |
❌ none (eval_interval=0 in all unit tests) |
C1 (stated): Deterministic row generation per host across varying worker counts (grain_worker_count=0, 2) |
✅ preserved | synthetic_multimodal_data_test.py::SyntheticMultimodalIteratorTest.test_create_data_iterator_qwen3_vl_shapes_and_determinism ✅ |
| C2 (inferred): Evaluation data does not duplicate training data for corresponding step indices | ✅ preserved (seed = config.data_shuffle_seed + 1) |
❌ none |
C3 (inferred): Proper batch sizing and multi-host data loading when expansion_factor_real_data > 1 or eval_per_device_batch_size != per_device_batch_size |
❌ violated | ❌ none |
| global_batch_size = config.global_batch_size_to_load if is_training else config.global_batch_size_to_load_eval | ||
| assert global_batch_size % global_mesh.size == 0, "Batch size should be divisible by number of global devices." |
There was a problem hiding this comment.
🟠 global_batch_size checks global_batch_size_to_load_eval for eval, but vision_sft_preprocessing_pipeline derives its batch size strictly from get_local_batch_size(config) which uses config.global_batch_size_to_load. If eval_per_device_batch_size is configured differently from per_device_batch_size, the assertion validates global_batch_size_to_load_eval while the iterator emits batches sized for training, causing a shape mismatch in the eval step.
There was a problem hiding this comment.
Good catch — added an is_training flag to get_local_batch_size and threaded it through vision_sft_preprocessing_pipeline so eval uses global_batch_size_to_load_eval. Fixed in 73b8d53.
| return multihost_dataloading.MultiHostDataLoadIterator( | ||
| dataloader, | ||
| global_mesh, | ||
| generate_padding_batch=(config.generate_padding_batch_train if is_training else config.generate_padding_batch_eval), |
There was a problem hiding this comment.
🟠 Setting expansion_loading_factor_for_grain=1 when not is_training breaks eval when expansion_factor_real_data > 1. input_pipeline_interface.py reduces process_indices_eval to jax.process_count() // expansion_factor_real_data and get_local_batch_size divides the batch size by expansion_factor_real_data, so clamping to 1 leaves each loading host yielding an undersized batch without micro-batch concatenation. Pass config.expansion_factor_real_data directly, or assert expansion_factor_real_data <= 1 for multimodal data since PlaceHolderDataIterator lacks media keys.
| generate_padding_batch=(config.generate_padding_batch_train if is_training else config.generate_padding_batch_eval), | |
| expansion_loading_factor_for_grain=config.expansion_factor_real_data, |
There was a problem hiding this comment.
Good catch — passing config.expansion_factor_real_data directly for eval as well now. Fixed in 73b8d53.
| self.assertIsNone(eval_iter_a) | ||
|
|
||
| for _ in range(2): | ||
| batch_a = next(train_iter_a) |
There was a problem hiding this comment.
🟠 make_synthetic_multimodal_eval_iterator is untested. Every test case runs with eval_interval=0 and asserts assertIsNone(eval_iter_a). Add a test with eval_interval > 0 asserting that eval_iter is instantiated, yields batches with the expected multimodal keys/shapes, and verifies that its content differs from train_iter (confirming the data_shuffle_seed + 1 offset).
There was a problem hiding this comment.
Added test_eval_iterator_uses_eval_batch_size_and_offset_seed covering eval batch shape, determinism, and the seed + 1 offset. Fixed in 73b8d53.
ba2a635 to
73b8d53
Compare
Description
Wires PR #6515's
SyntheticMultimodalDataSourceinto MaxText's Grain multimodal SFT pipeline whendataset_type=syntheticanduse_multimodal=true, while preserving the existing text-onlySyntheticDataIteratorfallback when no media modality is enabled. Each synthetic row is a pure function of(seed, index)and is deterministically sharded across hosts via strided slicing, establishing a reproducible multimodal performance baseline (PR 1) before adding packing and bucketing in follow-up PRs.src/maxtext/input_pipeline/input_pipeline_interface.py: Routedataset_type == "synthetic"tomake_synthetic_multimodal_{train,eval}_iteratorwhensynthetic_modalities(config)is non-empty; fall back toSyntheticDataIteratorotherwise.src/maxtext/input_pipeline/grain_data_processing.py: Addmake_synthetic_multimodal_{train,eval}_iteratorbacked bySyntheticMultimodalDataSource([shard_index::shard_count]) piped intovision_sft_preprocessing_pipeline.src/maxtext/input_pipeline/data_processing_utils.py: SkipParseFeatures/NormalizeFeatureswhenconfig.dataset_type == "synthetic".tests/unit/synthetic_multimodal_data_test.py: AddSyntheticMultimodalIteratorTestfor Qwen3-VL shapes, determinism (grain_worker_count=0, 2), seed sensitivity, and[0, 0]text-only fallback.Baseline MFU (
qwen3-vl-2b, TPU v4-8 / 4 chips, from scratch,image_size_for_vit=768, 1 image/sample, steps 4–14 steady-state):0.351 s64.445,844.223.43%*Decoder-only FLOPs over full ViT+Decoder step time (
64.44 / 275TPU v4 BF16 peak); MaxText currently logsVision encoder TFLOPs calculation not implemented for model qwen3-vl-2b, counting as 0 for now.Tests
grain_worker_count=0, 2):qwen3-vl-2bbaseline (TPU v4-8):grain_worker_count=0, 2) and identical Step 0 loss (370.937) andtotal_weightsacross steps 0–2 (5571, 5564, 5580) across two fresh TPU runs.Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.skip-ci-testsso only CPU/lint/docs checks run during review; a bot removes it after 2 approvals on a 1-commit PR to run TPU/GPU suites, or remove it yourself / ask a maintainer on fork PRs to run them sooner. On TPU7X, only the TPU tests that the PR adds or modifies run; add therun-tpu7xlabel to run the full TPU7X suite.)