TorchRec Features Overview
In the section above we’ve learned how to use embedding tables, one of the foundations of
modern recommendation systems! These tables represent entities and
relationships, such as users, pages, posts, etc. Given that these
entities are always increasing, a hash function is typically applied
to make sure the IDs are within the bounds of a certain embedding table.
However, in order to represent a vast amount of entities and reduce hash
collisions, these tables can become quite massive (think about the number of ads
for example). In fact, these tables can become so massive that they
won’t be able to fit on 1 GPU, even with 80G of memory.
In order to train models with massive embedding tables, sharding these
tables across GPUs is required, which then introduces a whole new set of
problems and opportunities in parallelism and optimization. Luckily, we have
the TorchRec library <https://docs.pytorch.org/torchrec/overview.html>`__ that has encountered, consolidated, and addressed
many of these concerns. TorchRec serves as a library that provides
primitives for large scale distributed embeddings.
Next, we will explore the major features of the TorchRec
library. We will start with torch.nn.Embedding and will extend that to
custom TorchRec modules, explore distributed training environment with
generating a sharding plan for embeddings, look at inherent TorchRec
optimizations, and extend the model to be ready for inference in C++.
Below is a quick outline of what this section consists of:
TorchRec Modules and Data Types
Distributed Training, Sharding, and Optimizations
Let’s begin with importing TorchRec:
This section goes over TorchRec Modules and data types including such
entities as EmbeddingCollection and EmbeddingBagCollection,
JaggedTensor, KeyedJaggedTensor, KeyedTensor and more.