allow grain to read tfds config - #4949
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for automatically constructing TFDS TFRecord paths when using the Grain dataset type with grain_file_type="tfrecord". It updates configuration validation to allow fallback parameters (dataset_path, dataset_name, and splits) when explicit grain files are not provided, implements the path construction logic, and adds corresponding unit tests. The review feedback suggests robustly handling potential trailing whitespace in dataset_path to avoid malformed paths, and simplifying the evaluation iterator configuration check by directly accessing config.hf_path instead of using getattr.
994d59a to
1667679
Compare
1667679 to
ef1040f
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
bvandermoon
left a comment
There was a problem hiding this comment.
LGTM but please double check the contruct_tfds_tfrecoerd_path comment before merging
| def construct_tfds_tfrecord_path(dataset_path: str, dataset_name: str, split: str) -> str: | ||
| """Constructs a glob for TFRecords in the standard TFDS prepared-data layout.""" | ||
| dataset_dir = dataset_name.strip().strip("/").replace(":", "/") | ||
| path = f"{dataset_path.strip().rstrip('/')}/{dataset_dir}/*-{split}.tfrecord-*" | ||
| max_logging.log(f"Automatically constructed Grain TFRecord path from TFDS configuration: {path}") | ||
| return path |
There was a problem hiding this comment.
Could you double-check the glob pattern logic here? I checked this with Gemini and there is a concern around if \* is present. Is that something that could be present in the file (it looks like it might be in one of the tests you added)
Here is the quote from Gemini:
"""
In Python file globbing (unlike Regular Expressions), the * is the wildcard itself and shouldn't be escaped. Leaving literal backslashes in the string might cause downstream file parsers to look for a file literally containing a backslash and fail to find the dataset.
"""
Description
This change makes it easier for existing TFDS users to migrate to the Grain TFRecord pipeline. Previously, flags
dataset_nameanddataset_pathare only used by the tfds pipeline, while grain usesgrain_train_filesgrain_eval_files. For migration, user needs to constructgrain_train_filesfor the tfds dataset. After this PR, the file path is auto-constructed.For example, a user is using:
To migrate to grain, only these config changes:
In addition, this PR adds clear migration instructions to tfds users.
Tests
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.