feat: add DispatchDataLoader for custom iterable dataloaders#4045
Open
KrishVenky wants to merge 2 commits into
Open
feat: add DispatchDataLoader for custom iterable dataloaders#4045KrishVenky wants to merge 2 commits into
KrishVenky wants to merge 2 commits into
Conversation
Closes huggingface#2975. Adds DispatchDataLoader, a lightweight wrapper that makes any Python iterable usable with Accelerator.prepare() without requiring it to be a torch.utils.data.DataLoader. - data_loader.py: new DispatchDataLoader class with device placement - utils/dataclasses.py: custom_classes field on DataLoaderConfiguration - accelerator.py: _prepare_one recognises DispatchDataLoader and custom_classes - __init__.py: exports DispatchDataLoader - tests/test_data_loader.py: 8 new tests, 39/39 passing
3c7f0ae to
dd43451
Compare
Forwards unknown attribute access to the wrapped iterable, matching the pattern used by DataLoaderAdapter. Raises AttributeError cleanly when the attribute does not exist on the wrapped object either. Adds two tests covering delegation and missing-attribute behaviour.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2975
Adds
DispatchDataLoader, a lightweight wrapper that makes any Python iterable usable withAccelerator.prepare()without requiring it to be atorch.utils.data.DataLoader. Also addscustom_classestoDataLoaderConfigurationso the Accelerator can auto-detect and wrap user-defined iterable types.What does this PR do?
Implements the feature requested in #2975 ("barebones dataloader for any iterable"):
DispatchDataLoader(data_loader.py): wraps any iterable, calls__iter__on each pass, and applies automatic device placement viasend_to_device. Exported from the top-levelacceleratepackage.DataLoaderConfiguration.custom_classes(utils/dataclasses.py): a tuple of class types. When set,Accelerator.prepare()detects instances of those classes and wraps them inDispatchDataLoaderautomatically._prepare_one(accelerator.py): recognisesDispatchDataLoaderdirectly, and wrapscustom_classesinstances.Usage: