SequentialReadingService¶
- class torchdata.dataloader2.SequentialReadingService(*reading_services)¶
- checkpoint() bytes¶
ReadingServiceserializes the internal states. Called inDataLoader2.state_dict.
- finalize() None¶
ReadingServicecleans up internal states and fully shuts down the service. Called inDataLoader2’sshutdownand__del__.
- finalize_iteration() None¶
ReadingServiceends service after an epoch is finished. Called when the iterator ofDataLoader2is depleted.
- 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.
- restore(datapipe, serialized_state: bytes) Union[IterDataPipe, MapDataPipe]¶
ReadingServiceadaptsDataPipegraph based on the serialized state. Called once in creatingDataLoader2iterator at first time. Counterpart ofinitialize, which adaptDataPipegraph from scratch.- Parameters:
datapipe – original
DataPipegraph before adapted byReadingServiceserialized_state – The serialized state of internal state used to restore the state of the adapted
DataPipegraph.
- Returns:
Adapted
DataPipegenerated from the serialized state.