Skip to content

Add single controller cache for grain. - #4870

Merged
sadikneipp merged 3 commits into
abhinavsing/snapshot-scalefrom
ksadi/cache-file-instructions-coordinator
Aug 13, 2026
Merged

Add single controller cache for grain.#4870
sadikneipp merged 3 commits into
abhinavsing/snapshot-scalefrom
ksadi/cache-file-instructions-coordinator

Conversation

@sadikneipp

@sadikneipp sadikneipp commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Cold storage would be accessed for metadata by each and every host at the iterator init before this change.

This change defines a way to init that metadata in the single controller and reuse it at the hosts. The core of the change is a new branch for create_dataset_from_pattern using the FileInstruction dataclass.

Validated for 50 step in v5e-32 capacity.

…rrayRecord datasets

Pre-resolves file globbing and extracts ArrayRecord FileInstruction headers once on the coordinator node.
Passes pre-extracted FileInstructions directly to worker sidecars via RemoteIteratorWrapper,
bypassing dynamic GCS globbing and file header reads on hundreds/thousands of worker hosts.
This avoids GCS API contention, prevents watchdog step-timebomb hangs at scale, and speeds up
initialization across worker hosts by over 100x.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces FileInstruction and extract_file_instructions to pre-resolve file paths and extract metadata on the coordinator, bypassing remote index discovery for Grain's ArrayRecordDataSource. It also updates the dataset creation logic to handle these pre-resolved instructions for both training and evaluation iterators, and adds a unit test suite. Feedback focuses on: 1) ensuring robust globbing when a list or tuple of patterns is passed to find_data_files; 2) reducing code duplication by unifying the mixture parsing logic in get_datasets; 3) parallelizing the sequential extraction of file instructions for both training and evaluation mixtures to avoid startup latency; and 4) importing FileInstruction and extract_file_instructions directly from the production module in the unit tests to avoid duplication and ensure the production code is properly tested.

Comment thread src/maxtext/input_pipeline/grain_data_processing.py Outdated
Comment thread src/maxtext/input_pipeline/grain_data_processing.py Outdated
Comment thread src/maxtext/input_pipeline/grain_data_processing.py
Comment thread src/maxtext/input_pipeline/grain_data_processing.py
Comment thread tests/unit/file_instruction_test.py Outdated
@sadikneipp sadikneipp changed the title feat(data): Cache FileInstruction metadata on coordinator for Grain A… Add single controller cache for grain. Aug 13, 2026
Sadi Kneipp added 2 commits August 13, 2026 05:46
- Recursively glob list/tuple of patterns in find_data_files.
- Deduplicate mixture branch logic in get_datasets.
- Parallelize extract_file_instructions across patterns using ThreadPoolExecutor for both train and eval iterators.
- Import FileInstruction and extract_file_instructions from production module in unit tests.
@sadikneipp
sadikneipp requested a review from suexu1025 as a code owner August 13, 2026 07:17
@sadikneipp
sadikneipp merged commit 296fec0 into abhinavsing/snapshot-scale Aug 13, 2026
16 of 19 checks passed
@sadikneipp
sadikneipp deleted the ksadi/cache-file-instructions-coordinator branch August 13, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant