Skip to content

fix(types): expose PyTorch dataset compatibility - #8457

Open
uuzzrm wants to merge 1 commit into
huggingface:mainfrom
uuzzrm:codex/datasets-7500-torch-types
Open

fix(types): expose PyTorch dataset compatibility#8457
uuzzrm wants to merge 1 commit into
huggingface:mainfrom
uuzzrm:codex/datasets-7500-torch-types

Conversation

@uuzzrm

@uuzzrm uuzzrm commented Aug 9, 2026

Copy link
Copy Markdown

What does this PR do? Make Dataset and IterableDataset visible to static type checkers as compatible with PyTorch's dataset classes. The runtime behavior remains unchanged: - torch is only imported under TYPE_CHECKING for the new bases. - The existing runtime parent-class behavior for IterableDataset is preserved. - Dataset is not changed into a runtime subclass of torch.utils.data.Dataset. This addresses the typing gap described in #7500, so Pyright can accept both map-style and iterable datasets as torch.utils.data.DataLoader inputs, including dataset.with_format(torch). ## Testing - ruff check src/datasets/arrow_dataset.py src/datasets/iterable_dataset.py tests/test_arrow_dataset.py - ruff format --check src/datasets/arrow_dataset.py src/datasets/iterable_dataset.py tests/test_arrow_dataset.py - git diff --check - Focused import regression: passed - Pyright 1.1.411 with a minimal PyTorch type stub covering Dataset.__getitem__, IterableDataset, and DataLoader: 0 errors - Related Dataset and IterableDataset tests: 804 passed, 108 skipped; PyTorch-dependent cases could not run because PyTorch is not installed in the local environment Fixes #7500 The implementation was prepared with Codex assistance and reviewed against the repository contribution guidelines.

AI assistance

AI assistance was used for repository research, implementation, and test drafting. The diff and validation results are documented here for maintainer review.

Make Dataset and IterableDataset visible as PyTorch datasets to static type checkers without importing torch at runtime. Add a regression test for the optional dependency boundary.
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.

Make with_format correctly indicate that a Dataset is compatible with PyTorch's Dataset class

1 participant