Attention
June 2024 Status Update: Removing DataPipes and DataLoader V2
We are re-focusing the torchdata repo to be an iterative enhancement of torch.utils.data.DataLoader. We do not plan on continuing development or maintaining the [DataPipes] and [DataLoaderV2] solutions, and they will be removed from the torchdata repo. We’ll also be revisiting the DataPipes references in pytorch/pytorch. In release torchdata==0.8.0 (July 2024) they will be marked as deprecated, and in 0.9.0 (Oct 2024) they will be deleted. Existing users are advised to pin to torchdata==0.8.0 or an older version until they are able to migrate away. Subsequent releases will not include DataPipes or DataLoaderV2. Please reach out if you suggestions or comments (please use this issue for feedback)
InProcessReadingService¶
- class torchdata.dataloader2.InProcessReadingService(prefetch_cnt: int = 0, init_fn: Optional[Callable[[Union[IterDataPipe, MapDataPipe], WorkerInfo], Union[IterDataPipe, MapDataPipe]]] = None, reset_fn: Optional[Callable[[Union[IterDataPipe, MapDataPipe], WorkerInfo, SeedGenerator], Union[IterDataPipe, MapDataPipe]]] = None)¶
Default ReadingService to serve the
DataPipegraph in the main process, and apply graph settings like determinism control to the graph.- Parameters:
prefetch_cnt – (int, 0 by default): Number of data will be prefetched in the main process.
init_fn – (Callable, optional): Custom function to be called when the main process starts to iterate over
DataPipegraph.reset_fn – (Callable, optional): Custom function to be called at the beginning of each epoch with
DataPipe,WorkerInfoandSeedGeneratoras the expected arguments.
- initialize(datapipe: Union[IterDataPipe, MapDataPipe]) Union[IterDataPipe, MapDataPipe]¶
ReadingServicetakes aDataPipegraph, adapts it into a newDataPipegraph based on the custom need. Called once in creatingDataLoader2iterator at first time. Prior to calling this method, theReadingServiceobject must be picklable.- Parameters:
datapipe – Original
DataPipegraph.- Returns:
An adapted or a new
DataPipegraph.
- initialize_iteration(seed_generator: SeedGenerator, iter_reset_fn: Optional[Callable[[Union[IterDataPipe, MapDataPipe]], Union[IterDataPipe, MapDataPipe]]] = None) Optional[Callable[[Union[IterDataPipe, MapDataPipe]], Union[IterDataPipe, MapDataPipe]]]¶
ReadingServicespins up service for an epoch. Called at the beginning of every time gettingDataLoader2iterator.- Parameters:
seed_generator – SeedGenerator object created and managed by DataLoader2. As the single source of randomness, it will govern the determinism for all of random operations with the graph of DataPipes.
iter_reset_fn – Optional reset function from the prior
ReadingServciewhenSequentialReadingServicechains multipleReadingServices
- Returns:
A new
iter_reset_fnto be used by subseqeuentReadingService
Example
MultiProcessingReadingService starts setting worker seeds per process and prefetching items from the graph.