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)
PinMemory¶
- class torchdata.datapipes.iter.PinMemory(source_datapipe, device=None, pin_memory_fn=<function pin_memory_fn>)¶
Prefetches one element from the source DataPipe and moves it to pinned memory (functional name:
pin_memory
). When used withMultiProcessingReadingService
, this DataPipe would be kept in the main process to prevent duplicated CUDA context creation.- Parameters:
source_datapipe – IterDataPipe from which samples are moved to pinned memory.
device – The device to pin samples.
pin_memory_fn – Optional callable function to move data to pinned memory. A
pin_memory_fn
to handle general objects is provided by default.
Example
>>> from torchdata.datapipes.iter import IterableWrapper >>> dp = IterableWrapper(file_paths).open_files().readlines().map(tokenize_fn).pin_memory()