Shortcuts

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)

OnlineReader

class torchdata.datapipes.iter.OnlineReader(source_datapipe: IterDataPipe[str], *, timeout: Optional[float] = None, skip_on_error: bool = False, **kwargs: Optional[Dict[str, Any]])

Takes file URLs (can be HTTP URLs pointing to files or URLs to GDrive files), and yields tuples of file URL and IO stream (functional name: read_from_remote).

Parameters:
  • source_datapipe – a DataPipe that contains URLs

  • timeout – timeout in seconds for HTTP request

  • skip_on_error – whether to skip over urls causing problems, otherwise an exception is raised

  • **kwargs – a Dictionary to pass optional arguments that requests takes. For the full list check out https://docs.python-requests.org/en/master/api/

Example:

from torchdata.datapipes.iter import IterableWrapper, OnlineReader

file_url = "https://raw.githubusercontent.com/pytorch/data/main/LICENSE"
online_reader_dp = OnlineReader(IterableWrapper([file_url]))
reader_dp = online_reader_dp.readlines()
it = iter(reader_dp)
path, line = next(it)
print((path, line))

Output:

('https://raw.githubusercontent.com/pytorch/data/main/LICENSE', b'BSD 3-Clause License')

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources