• Stars
    star
    1,059
  • Rank 42,013 (Top 0.9 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created about 3 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A PyTorch repo for data loading and utilities to be shared by the PyTorch domain libraries.

TorchData (see note below on current status)

Why TorchData? | Install guide | What are DataPipes? | Beta Usage and Feedback | Contributing | Future Plans

⚠️ As of July 2023, we have paused active development on TorchData and have paused new releases. We have learnt a lot from building it and hearing from users, but also believe we need to re-evaluate the technical design and approach given how much the industry has changed since we began the project. During the rest of 2023 we will be re-evaluating our plans in this space. Please reach out if you suggestions or comments (please use #1196 for feedback).

torchdata is a library of common modular data loading primitives for easily constructing flexible and performant data pipelines.

This library introduces composable Iterable-style and Map-style building blocks called DataPipes that work well out of the box with the PyTorch's DataLoader. These built-in DataPipes have the necessary functionalities to reproduce many different datasets in TorchVision and TorchText, namely loading files (from local or cloud), parsing, caching, transforming, filtering, and many more utilities. To understand the basic structure of DataPipes, please see What are DataPipes? below, and to see how DataPipes can be practically composed together into datasets, please see our examples.

On top of DataPipes, this library provides a new DataLoader2 that allows the execution of these data pipelines in various settings and execution backends (ReadingService). You can learn more about the new version of DataLoader2 in our full DataLoader2 documentation. Additional features are work in progres, such as checkpointing and advanced control of randomness and determinism.

Note that because many features of the original DataLoader have been modularized into DataPipes, their source codes live as standard DataPipes in pytorch/pytorch rather than torchdata to preserve backward-compatibility support and functional parity within torch. Regardless, you can to them by importing them from torchdata.

Why composable data loading?

Over many years of feedback and organic community usage of the PyTorch DataLoader and Dataset, we've found that:

  1. The original DataLoader bundled too many features together, making them difficult to extend, manipulate, or replace. This has created a proliferation of use-case specific DataLoader variants in the community rather than an ecosystem of interoperable elements.
  2. Many libraries, including each of the PyTorch domain libraries, have rewritten the same data loading utilities over and over again. We can save OSS maintainers time and effort rewriting, debugging, and maintaining these commonly used elements.

These reasons inspired the creation of DataPipe and DataLoader2, with a goal to make data loading components more flexible and reusable.

Installation

Version Compatibility

The following is the corresponding torchdata versions and supported Python versions.

torch torchdata python
master / nightly main / nightly >=3.8, <=3.11
2.0.0 0.6.0 >=3.8, <=3.11
1.13.1 0.5.1 >=3.7, <=3.10
1.12.1 0.4.1 >=3.7, <=3.10
1.12.0 0.4.0 >=3.7, <=3.10
1.11.0 0.3.0 >=3.7, <=3.10

Colab

Follow the instructions in this Colab notebook. The notebook also contains a simple usage example.

Local pip or conda

First, set up an environment. We will be installing a PyTorch binary as well as torchdata. If you're using conda, create a conda environment:

conda create --name torchdata
conda activate torchdata

If you wish to use venv instead:

python -m venv torchdata-env
source torchdata-env/bin/activate

Install torchdata:

Using pip:

pip install torchdata

Using conda:

conda install -c pytorch torchdata

You can then proceed to run our examples, such as the IMDb one.

From source

pip install .

If you'd like to include the S3 IO datapipes and aws-sdk-cpp, you may also follow the instructions here

In case building TorchData from source fails, install the nightly version of PyTorch following the linked guide on the contributing page.

From nightly

The nightly version of TorchData is also provided and updated daily from main branch.

Using pip:

pip install --pre torchdata --extra-index-url https://download.pytorch.org/whl/nightly/cpu

Using conda:

conda install torchdata -c pytorch-nightly

What are DataPipes?

Early on, we observed widespread confusion between the PyTorch Dataset which represented reusable loading tooling (e.g. TorchVision's ImageFolder), and those that represented pre-built iterators/accessors over actual data corpora (e.g. TorchVision's ImageNet). This led to an unfortunate pattern of siloed inheritance of data tooling rather than composition.

DataPipe is simply a renaming and repurposing of the PyTorch Dataset for composed usage. A DataPipe takes in some access function over Python data structures, __iter__ for IterDataPipes and __getitem__ for MapDataPipes, and returns a new access function with a slight transformation applied. For example, take a look at this JsonParser, which accepts an IterDataPipe over file names and raw streams, and produces a new iterator over the filenames and deserialized data:

import json

class JsonParserIterDataPipe(IterDataPipe):
    def __init__(self, source_datapipe, **kwargs) -> None:
        self.source_datapipe = source_datapipe
        self.kwargs = kwargs

    def __iter__(self):
        for file_name, stream in self.source_datapipe:
            data = stream.read()
            yield file_name, json.loads(data, **self.kwargs)

    def __len__(self):
        return len(self.source_datapipe)

You can see in this example how DataPipes can be easily chained together to compose graphs of transformations that reproduce sophisticated data pipelines, with streamed operation as a first-class citizen.

Under this naming convention, Dataset simply refers to a graph of DataPipes, and a dataset module like ImageNet can be rebuilt as a factory function returning the requisite composed DataPipes. Note that the vast majority of built-in features are implemented as IterDataPipes, we encourage the usage of built-in IterDataPipe as much as possible and convert them to MapDataPipe only when necessary.

DataLoader2

A new, light-weight DataLoader2 is introduced to decouple the overloaded data-manipulation functionalities from torch.utils.data.DataLoader to DataPipe operations. Besides, certain features can only be achieved with DataLoader2, such as like checkpointing/snapshotting and switching backend services to perform high-performant operations.

Please read the full documentation here.

Tutorial

A tutorial of this library is available here on the documentation site. It covers four topics: using DataPipes, working with DataLoader, implementing DataPipes, and working with Cloud Storage Providers.

There is also a tutorial available on how to work with the new DataLoader2.

Usage Examples

We provide a simple usage example in this Colab notebook. It can also be downloaded and executed locally as a Jupyter notebook.

In addition, there are several data loading implementations of popular datasets across different research domains that use DataPipes. You can find a few selected examples here.

Frequently Asked Questions (FAQ)

What should I do if the existing set of DataPipes does not do what I need?

You can implement your own custom DataPipe. If you believe your use case is common enough such that the community can benefit from having your custom DataPipe added to this library, feel free to open a GitHub issue. We will be happy to discuss!

What happens when the Shuffler DataPipe is used with DataLoader?

In order to enable shuffling, you need to add a Shuffler to your DataPipe line. Then, by default, shuffling will happen at the point where you specified as long as you do not set shuffle=False within DataLoader.

What happens when the Batcher DataPipe is used with DataLoader?

If you choose to use Batcher while setting batch_size > 1 for DataLoader, your samples will be batched more than once. You should choose one or the other.

Why are there fewer built-in MapDataPipes than IterDataPipes?

By design, there are fewer MapDataPipes than IterDataPipes to avoid duplicate implementations of the same functionalities as MapDataPipe. We encourage users to use the built-in IterDataPipe for various functionalities, and convert it to MapDataPipe as needed.

How is multiprocessing handled with DataPipes?

Multi-process data loading is still handled by the DataLoader, see the DataLoader documentation for more details. As of PyTorch version >= 1.12.0 (TorchData version >= 0.4.0), data sharding is automatically done for DataPipes within the DataLoader as long as a ShardingFilter DataPipe exists in your pipeline. Please see the tutorial for an example.

What is the upcoming plan for DataLoader?

DataLoader2 is in the prototype phase and more features are actively being developed. Please see the README file in torchdata/dataloader2. If you would like to experiment with it (or other prototype features), we encourage you to install the nightly version of this library.

Why is there an Error saying the specified DLL could not be found at the time of importing portalocker?

It only happens for people who runs torchdata on Windows OS as a common problem with pywin32. And, you can find the reason and the solution for it in the link.

Contributing

We welcome PRs! See the CONTRIBUTING file.

Beta Usage and Feedback

We'd love to hear from and work with early adopters to shape our designs. Please reach out by raising an issue if you're interested in using this tooling for your project.

License

TorchData is BSD licensed, as found in the LICENSE file.

More Repositories

1

pytorch

Tensors and Dynamic neural networks in Python with strong GPU acceleration
Python
78,312
star
2

examples

A set of examples around pytorch in Vision, Text, Reinforcement Learning, etc.
Python
21,700
star
3

vision

Datasets, Transforms and Models specific to Computer Vision
Python
15,495
star
4

tutorials

PyTorch tutorials.
Jupyter Notebook
7,713
star
5

captum

Model interpretability and understanding for PyTorch
Python
4,482
star
6

ignite

High-level library to help with training and evaluating neural networks in PyTorch flexibly and transparently.
Python
4,443
star
7

serve

Serve, optimize and scale PyTorch models in production
Java
3,969
star
8

text

Models, data loaders and abstractions for language processing, powered by PyTorch
Python
3,426
star
9

ELF

ELF: a platform for game research with AlphaGoZero/AlphaZero reimplementation
C++
3,340
star
10

glow

Compiler for Neural Network hardware accelerators
C++
3,116
star
11

torchtune

A Native-PyTorch Library for LLM Fine-tuning
Python
2,946
star
12

botorch

Bayesian optimization in PyTorch
Jupyter Notebook
2,920
star
13

audio

Data manipulation and transformation for audio signal processing, powered by PyTorch
Python
2,355
star
14

TensorRT

PyTorch/TorchScript/FX compiler for NVIDIA GPUs using TensorRT
Python
2,340
star
15

xla

Enabling PyTorch on XLA Devices (e.g. Google TPU)
C++
2,301
star
16

rl

A modular, primitive-first, python-first PyTorch library for Reinforcement Learning.
Python
1,768
star
17

torchrec

Pytorch domain library for recommendation systems
Python
1,683
star
18

tnt

A lightweight library for PyTorch training tools and utilities
Python
1,606
star
19

opacus

Training PyTorch models with differential privacy
Jupyter Notebook
1,582
star
20

QNNPACK

Quantized Neural Network PACKage - mobile-optimized implementation of quantized neural network operators
C
1,506
star
21

android-demo-app

PyTorch android examples of usage in applications
Java
1,392
star
22

functorch

functorch is JAX-like composable function transforms for PyTorch.
Jupyter Notebook
1,363
star
23

hub

Submission to https://pytorch.org/hub/
Python
1,360
star
24

FBGEMM

FB (Facebook) + GEMM (General Matrix-Matrix Multiplication) - https://code.fb.com/ml-applications/fbgemm/
C++
1,050
star
25

torchdynamo

A Python-level JIT compiler designed to make unmodified PyTorch programs faster.
Python
945
star
26

extension-cpp

C++ extensions in PyTorch
Python
924
star
27

cpuinfo

CPU INFOrmation library (x86/x86-64/ARM/ARM64, Linux/Windows/Android/macOS/iOS)
C
913
star
28

executorch

On-device AI across mobile, embedded and edge for PyTorch
C++
891
star
29

translate

Translate - a PyTorch Language Library
Python
811
star
30

benchmark

TorchBench is a collection of open source benchmarks used to evaluate PyTorch performance.
Python
759
star
31

elastic

PyTorch elastic training
Python
725
star
32

torcharrow

High performance model preprocessing library on PyTorch
Python
625
star
33

ios-demo-app

PyTorch iOS examples
Swift
578
star
34

kineto

A CPU+GPU Profiling library that provides access to timeline traces and hardware performance counters.
HTML
578
star
35

tensordict

TensorDict is a pytorch dedicated tensor container.
Python
577
star
36

PiPPy

Pipeline Parallelism for PyTorch
Python
538
star
37

tvm

TVM integration into PyTorch
C++
450
star
38

contrib

Implementations of ideas from recent papers
Python
388
star
39

ort

Accelerate PyTorch models with ONNX Runtime
Python
346
star
40

builder

Continuous builder and binary build scripts for pytorch
Shell
319
star
41

accimage

high performance image loading and augmenting routines mimicking PIL.Image interface
C
318
star
42

torchx

TorchX is a universal job launcher for PyTorch applications. TorchX is designed to have fast iteration time for training/research and support for E2E production ML pipelines when you're ready.
Python
284
star
43

extension-ffi

Examples of C extensions for PyTorch
Python
254
star
44

nestedtensor

[Prototype] Tools for the concurrent manipulation of variably sized Tensors.
Jupyter Notebook
251
star
45

tensorpipe

A tensor-aware point-to-point communication primitive for machine learning
C++
237
star
46

pytorch.github.io

The website for PyTorch
HTML
211
star
47

hydra-torch

Configuration classes enabling type-safe PyTorch configuration for Hydra apps
Python
197
star
48

cppdocs

PyTorch C++ API Documentation
HTML
186
star
49

torcheval

A library that contains a rich collection of performant PyTorch model metrics, a simple interface to create new metrics, a toolkit to facilitate metric computation in distributed training and tools for PyTorch model evaluations.
Python
177
star
50

workshops

This is a repository for all workshop related materials.
Jupyter Notebook
172
star
51

multipy

torch::deploy (multipy for non-torch uses) is a system that lets you get around the GIL problem by running multiple Python interpreters in a single C++ process.
C++
164
star
52

torchsnapshot

A performant, memory-efficient checkpointing library for PyTorch applications, designed with large, complex distributed workloads in mind.
Python
125
star
53

java-demo

Jupyter Notebook
119
star
54

rfcs

PyTorch RFCs (experimental)
110
star
55

torchdistx

Torch Distributed Experimental
Python
109
star
56

extension-script

Example repository for custom C++/CUDA operators for TorchScript
Python
109
star
57

csprng

Cryptographically secure pseudorandom number generators for PyTorch
Batchfile
97
star
58

pytorch_sphinx_theme

PyTorch Sphinx Theme
CSS
91
star
59

test-infra

This repository hosts code that supports the testing infrastructure for the main PyTorch repo. For example, this repo hosts the logic to track disabled tests and slow tests, as well as our continuation integration jobs HUD/dashboard.
TypeScript
61
star
60

maskedtensor

MaskedTensors for PyTorch
Python
38
star
61

add-annotations-github-action

A GitHub action to run clang-tidy and annotate failures
JavaScript
13
star
62

probot

PyTorch GitHub bot written in probot
TypeScript
11
star
63

ci-hud

HUD for CI activity on `pytorch/pytorch`, provides a top level view for jobs to easily discern regressions
JavaScript
10
star
64

ossci-job-dsl

Jenkins job definitions for OSSCI
Groovy
9
star
65

pytorch-integration-testing

Testing downstream libraries using pytorch release candidates
Makefile
5
star
66

torchhub_testing

Repo to test torchhub. Nothing to see here.
4
star
67

dr-ci

Diagnose and remediate CI jobs
Haskell
2
star
68

pytorch-ci-dockerfiles

Scripts for generating docker images for PyTorch CI
2
star
69

labeler-github-action

GitHub action for labeling issues and pull requests based on conditions
TypeScript
1
star