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.

Metadata

Release files for torchrec 1.9.1

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.1
File
torchrec-1.9.1-py315-none-any.whl Python 3.15 none any Details
torchrec-1.9.1-py314-none-any.whl Python 3.14 none any Details
torchrec-1.9.1-py313-none-any.whl Python 3.13 none any Details
torchrec-1.9.1-py312-none-any.whl Python 3.12 none any Details
torchrec-1.9.1-py311-none-any.whl Python 3.11 none any Details
torchrec-1.9.1-py310-none-any.whl Python 3.10 none any Details

Total release size: 8.3 MB

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

Download URL torchrec-1.9.1-py315-none-any.whl
Size 1.4 MB
Tags Python 3.15
SHA-256 checksum
How to use checksums
68bf3cb238c10fe1864d90b0f3ebca9fe4f41ffb5a5791762196cca411c0fcd9
BLAKE2b-256 checksum
How to use checksums
465effb3572814f8fb38bc2f332b6df2045e9ee9be4948314cdf97a543e6876e
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.1-py314-none-any.whl

Download URL torchrec-1.9.1-py314-none-any.whl
Size 1.4 MB
Tags Python 3.14
SHA-256 checksum
How to use checksums
10cfac03f903be26f3e37339c870287d408a926b1e399c18e395ed14a1a54807
BLAKE2b-256 checksum
How to use checksums
441de3943deac6d39b4e3aef0778172a292e8c056823f1bdcaeca936dca32d2c
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.1-py313-none-any.whl

Download URL torchrec-1.9.1-py313-none-any.whl
Size 1.4 MB
Tags Python 3.13
SHA-256 checksum
How to use checksums
2b0d5e8ecf1b87a7a7117595d6b080b3299c2c594c9d72b136a9a295b46b978c
BLAKE2b-256 checksum
How to use checksums
190006a4ff2436e437dbe9b0fd8a2a6dd7c05acaceac4cad73a031814925c7fd
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.1-py312-none-any.whl

Download URL torchrec-1.9.1-py312-none-any.whl
Size 1.4 MB
Tags Python 3.12
SHA-256 checksum
How to use checksums
3a94416c92781451a219e3be7f2c169b72a65d0ce081c4307bc5623c16d1e8d6
BLAKE2b-256 checksum
How to use checksums
3702d77ef69c2c2abe95e11502aa1fe68af58f6590740c950699599bf746258e
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.1-py311-none-any.whl

Download URL torchrec-1.9.1-py311-none-any.whl
Size 1.4 MB
Tags Python 3.11
SHA-256 checksum
How to use checksums
5937438c697e4f705b651d95c6995b761ae3639ebd38c748dbd964750ff2ea54
BLAKE2b-256 checksum
How to use checksums
db3edffbee6da6e63d76faed3a062fd7339031bdebc279f711b171f8af9d93e7
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.1-py310-none-any.whl

Download URL torchrec-1.9.1-py310-none-any.whl
Size 1.4 MB
Tags Python 3.10
SHA-256 checksum
How to use checksums
82f4d6e570cfc313783fa710ee4a2c2118976b56693489a4370c46a57ced3a1f
BLAKE2b-256 checksum
How to use checksums
91c9861b5d868b59d7c8b9bd57e3897640cc845fa27ec022ff73b2dee8927242
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