Implement continuous stream chunking for pre-tokenized C4 MLPerf dataset - #5095
Implement continuous stream chunking for pre-tokenized C4 MLPerf dataset#5095snehalv2002 wants to merge 1 commit into
Conversation
Aligns the pre-tokenized C4 MLPerf input pipeline with the MLCommons DeepSeek-V3 reference specification: - Flatten token streams into contiguous 4096 chunks across document boundaries with 0% padding waste. - Set monotonic position IDs (0, 1, ..., 4095). - Use uniform segment IDs (1s) to allow unrestricted causal cross-document attention. - Ensure 100% token participation in loss calculation (eod_mask_loss=False). - Fix legacy format_fn issue where token 1 (quotation mark in Llama-3 vocabulary) was masked from loss. - Add comprehensive unit and integration tests verifying token 0 preservation, boundary handling, and end-to-end model forward/loss computation. BUG=555814868
There was a problem hiding this comment.
Code Review
This pull request introduces continuous stream chunking for pre-tokenized datasets in the MLPerf input pipeline, adding functions to flatten, chunk, and format token streams with monotonic position IDs and uniform segmentations to minimize padding waste. It also includes a comprehensive set of unit tests. The feedback suggests optimizing the tensor shifting operation in format_continuous_stream_fn using tf.concat, shuffling the dataset before chunking to improve data mixing, and removing or mocking the external GCS dependency in the unit tests to prevent CI flakiness.
| """ | ||
| targets_raw = tf.cast(x["targets"], tf.int32) | ||
| inputs = targets_raw | ||
| targets = _shift_left_and_pad(targets_raw, eos_id) |
There was a problem hiding this comment.
Using _shift_left_and_pad on a 1D tensor of fixed size is highly inefficient because it converts the tensor to a RaggedTensor and performs multiple complex operations. Since targets_raw is a 1D tensor of fixed size max_target_length, we can shift it left much more efficiently using tf.concat.
| targets = _shift_left_and_pad(targets_raw, eos_id) | |
| targets = tf.concat([targets_raw[1:], [eos_id]], axis=0) |
| train_ds = chunk_token_stream(train_ds, feature_key="targets", sequence_length=max_target_length) | ||
| train_ds = train_ds.shuffle(shuffle_buffer_size, seed=data_shuffle_seed) |
There was a problem hiding this comment.
Shuffling is currently performed after chunking the token stream. Since the input stream is flattened from unshuffled documents, consecutive chunks will be highly correlated (belonging to the same or consecutive documents). Shuffling with a small buffer size of 128 after chunking does not provide sufficient global mixing. Shuffling the dataset of documents before chunking ensures that the continuous stream is constructed from randomized documents, leading to much better data mixing and model convergence.
| train_ds = chunk_token_stream(train_ds, feature_key="targets", sequence_length=max_target_length) | |
| train_ds = train_ds.shuffle(shuffle_buffer_size, seed=data_shuffle_seed) | |
| train_ds = train_ds.shuffle(shuffle_buffer_size, seed=data_shuffle_seed) | |
| train_ds = chunk_token_stream(train_ds, feature_key="targets", sequence_length=max_target_length) |
| def test_real_gcs_dataset_loading(self): | ||
| """Integration test verifying loading and stream chunking from real GCS MLPerf TFDS dataset.""" | ||
| try: | ||
| builder = tfds.builder_from_directory("gs://mlperf-6-submission-us-central1/tfds-fixed-reshard/c4/en/3.0.5") | ||
| raw_ds = builder.as_dataset(split="validation[:16]") | ||
| except Exception as e: | ||
| self.skipTest(f"GCS bucket not accessible in this environment: {e}") |
There was a problem hiding this comment.
The unit test test_real_gcs_dataset_loading attempts to load a real dataset from a GCS bucket (gs://mlperf-6-submission-us-central1/...). Unit tests should be self-contained and not depend on external network resources or GCP credentials, as this can cause flakiness, slow execution, or failures in offline/restricted CI environments. Consider moving this integration test to a separate integration test suite, or mocking the GCS/TFDS builder calls to avoid real network requests during unit test execution.
Aligns the pre-tokenized C4 MLPerf input pipeline with the MLCommons DeepSeek-V3 reference specification:
BUG=555814868
Description
Start with a short description of what the PR does and how this is a change from
the past.
The rest of the description includes relevant details and context, examples:
If the change fixes a bug or a Github issue, please include a link, e.g.,:
FIXES: b/123456
FIXES: #123456
You can also provide a comma-separated list. If you don't want to close a bug but
simply to reference it, use BUGS, e.g.:
BUGS: b/123456
Notice 1: Once all tests pass, the "pull ready" label will automatically be assigned.
This label is used for administrative purposes. Please do not add it manually.
Notice 2: For external contributions, our settings currently require an approval from a MaxText maintainer to trigger CI tests.
Tests
Please describe how you tested this change, and include any instructions and/or
commands to reproduce.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.