Skip to main content

TorchRec

TorchRec is a PyTorch domain library built to provide common sparsity and parallelism primitives needed for large-scale recommender systems (RecSys). TorchRec allows training and inference of models with large embedding tables sharded across many GPUs and powers many production RecSys models at Meta.

External Presence

TorchRec has been used to accelerate advancements in recommendation systems, some examples:

Introduction

To begin learning about TorchRec, check out:

TorchRec Features

  • Parallelism primitives that enable easy authoring of large, performant multi-device/multi-node models using hybrid data-parallelism/model-parallelism.
  • Sharders to shard embedding tables with different strategies including data-parallel, table-wise, row-wise, table-wise-row-wise, column-wise, and table-wise-column-wise sharding.
  • Planner that can automatically generate optimized sharding plans for models.
  • Pipelined training overlapping dataloading device transfer (copy to GPU), inter-device communications (input_dist), and computation (forward, backward) for increased performance.
  • Optimized kernels for RecSys powered by FBGEMM.
  • Quantization support for reduced precision training and inference, along with optimizing a TorchRec model for C++ inference.
  • Common modules for RecSys.
  • RecSys datasets (criteo click logs and movielens)
  • Examples of end-to-end training such as the DLRM event prediction model trained on criteo click logs dataset.

Installation

Check out the Getting Started section in the documentation for recommended ways to set up Torchrec.

From Source

Generally, there isn't a need to build from source. For most use cases, follow the section above to set up TorchRec. However, to build from source and to get the latest changes, do the following:

  1. Install pytorch. See pytorch documentation.

    CUDA 12.6
    
    pip install torch --index-url https://download.pytorch.org/whl/nightly/cu126
    
    CUDA 12.8
    
    pip install torch --index-url https://download.pytorch.org/whl/nightly/cu128
    
    CUDA 12.9
    
    pip install torch --index-url https://download.pytorch.org/whl/nightly/cu129
    
    CPU
    
    pip install torch --index-url https://download.pytorch.org/whl/nightly/cpu
    
  2. Clone TorchRec.

    git clone --recursive https://github.com/meta-pytorch/torchrec
    cd torchrec
    
  3. Install FBGEMM.

    CUDA 12.6
    
    pip install fbgemm-gpu --index-url https://download.pytorch.org/whl/nightly/cu126
    
    CUDA 12.8
    
    pip install fbgemm-gpu --index-url https://download.pytorch.org/whl/nightly/cu128
    
    CUDA 12.9
    
    pip install fbgemm-gpu --index-url https://download.pytorch.org/whl/nightly/cu129
    
    CPU
    
    pip install fbgemm-gpu --index-url https://download.pytorch.org/whl/nightly/cpu
    
  4. Install other requirements.

    pip install -r requirements.txt
    
  5. Install TorchRec.

    python setup.py install develop
    
  6. Test the installation.

    GPU mode
    
    torchx run -s local_cwd dist.ddp -j 1x2 --gpu 2 --script test_installation.py
    
    CPU Mode
    
    torchx run -s local_cwd dist.ddp -j 1x2 --script test_installation.py -- --cpu_only
    

    See TorchX for more information on launching distributed and remote jobs.

  7. If you want to run a more complex example, please take a look at the torchrec DLRM example.

Contributing

See CONTRIBUTING.md for details about contributing to TorchRec!

Citation

If you're using TorchRec, please refer to BibTeX entry to cite this work:

@inproceedings{10.1145/3523227.3547387,
author = {Ivchenko, Dmytro and Van Der Staay, Dennis and Taylor, Colin and Liu, Xing and Feng, Will and Kindi, Rahul and Sudarshan, Anirudh and Sefati, Shahin},
title = {TorchRec: a PyTorch Domain Library for Recommendation Systems},
year = {2022},
isbn = {9781450392785},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3523227.3547387},
doi = {10.1145/3523227.3547387},
abstract = {Recommendation Systems (RecSys) comprise a large footprint of production-deployed AI today. The neural network-based recommender systems differ from deep learning models in other domains in using high-cardinality categorical sparse features that require large embedding tables to be trained. In this talk we introduce TorchRec, a PyTorch domain library for Recommendation Systems. This new library provides common sparsity and parallelism primitives, enabling researchers to build state-of-the-art personalization models and deploy them in production. In this talk we cover the building blocks of the TorchRec library including modeling primitives such as embedding bags and jagged tensors, optimized recommender system kernels powered by FBGEMM, a flexible sharder that supports a veriety of strategies for partitioning embedding tables, a planner that automatically generates optimized and performant sharding plans, support for GPU inference and common modeling modules for building recommender system models. TorchRec library is currently used to train large-scale recommender models at Meta. We will present how TorchRec helped Meta’s recommender system platform to transition from CPU asynchronous training to accelerator-based full-sync training.},
booktitle = {Proceedings of the 16th ACM Conference on Recommender Systems},
pages = {482–483},
numpages = {2},
keywords = {information retrieval, recommender systems},
location = {Seattle, WA, USA},
series = {RecSys '22}
}

License

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

Release files for torchrec 1.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for torchrec 1.9.0
File
torchrec-1.9.0-py315-none-any.whl Python 3.15 none any Details
torchrec-1.9.0-py314-none-any.whl Python 3.14 none any Details
torchrec-1.9.0-py313-none-any.whl Python 3.13 none any Details
torchrec-1.9.0-py312-none-any.whl Python 3.12 none any Details
torchrec-1.9.0-py311-none-any.whl Python 3.11 none any Details
torchrec-1.9.0-py310-none-any.whl Python 3.10 none any Details

Total release size: 7.9 MB

Release files / torchrec-1.9.0-py315-none-any.whl

Download URL torchrec-1.9.0-py315-none-any.whl
Size 1.3 MB
Tags Python 3.15
SHA-256 checksum
How to use checksums
26c4ef9c60ef377f3e51050290cdf77be7de25d34af263fed4aa3cc354056413
BLAKE2b-256 checksum
How to use checksums
a27bd4426b01f95c7c28a8cbaaa78f30deba53761b1a1b87872bf30833353ba0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.0rc2

Release files / torchrec-1.9.0-py314-none-any.whl

Download URL torchrec-1.9.0-py314-none-any.whl
Size 1.3 MB
Tags Python 3.14
SHA-256 checksum
How to use checksums
e5a3d315728dd849b35d0e3e4ff8d8155ce6b337dad3a70e4ccfd55b75749247
BLAKE2b-256 checksum
How to use checksums
c3016403c628636f99fe87559863d22fedb66f4aefce149e7328ad8b7acd4590
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / torchrec-1.9.0-py313-none-any.whl

Download URL torchrec-1.9.0-py313-none-any.whl
Size 1.3 MB
Tags Python 3.13
SHA-256 checksum
How to use checksums
ec315cc173695ec9a2daa50c6de5fcefe79b0b8c5a851e07e654ee6315e5e5f4
BLAKE2b-256 checksum
How to use checksums
03efd03ba77287d743265e40c42d3dbf6c8de6b3a491b347807051172d308b53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / torchrec-1.9.0-py312-none-any.whl

Download URL torchrec-1.9.0-py312-none-any.whl
Size 1.3 MB
Tags Python 3.12
SHA-256 checksum
How to use checksums
6f4d45b25583e76419f86421106f9eb145e2b57bfc2a54dd043b0bee384c7a2f
BLAKE2b-256 checksum
How to use checksums
5bc4132f38838e3787e5bdf926d95b48d93bf7cd3f679913d0eebe09bf9aa693
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / torchrec-1.9.0-py311-none-any.whl

Download URL torchrec-1.9.0-py311-none-any.whl
Size 1.3 MB
Tags Python 3.11
SHA-256 checksum
How to use checksums
95afe0c76ce599a2647b54fa4d3bd1597eed78afe7089573e312bf2a10981179
BLAKE2b-256 checksum
How to use checksums
5743b2c1f0f2d52f2537ae559622fc72bbfe864c7d5e4d0be670e05dba2b54ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / torchrec-1.9.0-py310-none-any.whl

Download URL torchrec-1.9.0-py310-none-any.whl
Size 1.3 MB
Tags Python 3.10
SHA-256 checksum
How to use checksums
306c7da9fb55a07311956e67f92cf7d5797173da3f939138f3f6fc02bc454307
BLAKE2b-256 checksum
How to use checksums
8e9c5861b5a58ce9e0c058527d582af93485b44327b64f4a2f6ef184bb74d2bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page