### Installation Output Log Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/sharding/sharding.ipynb Example output showing successful installation of TorchRec dependencies. ```text Looking in indexes: https://download.pytorch.org/whl/cu121 Requirement already satisfied: torch in /usr/local/lib/python3.10/dist-packages (2.5.1+cu121) Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.10/dist-packages (from torch) (1.13.1) Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch) (3.3) Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch) (12.1.105) Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.10/dist-packages (from torch) (4.13.2) Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch) (2024.6.1) Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch) (3.1.6) Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch) (12.1.105) Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch) (12.1.105) Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /usr/local/lib/python3.10/dist-packages (from torch) (12.1.3.1) Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch) (12.1.105) Requirement already satisfied: nvidia-cudnn-cu12==9.1.0.70 in /usr/local/lib/python3.10/dist-packages (from torch) (9.1.0.70) Requirement already satisfied: triton==3.1.0 in /usr/local/lib/python3.10/dist-packages (from torch) (3.1.0) Requirement already satisfied: nvidia-nccl-cu12==2.21.5 in /usr/local/lib/python3.10/dist-packages (from torch) (2.21.5) Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /usr/local/lib/python3.10/dist-packages (from torch) (11.0.2.54) Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /usr/local/lib/python3.10/dist-packages (from torch) (12.1.0.106) Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch) (3.13.1) Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /usr/local/lib/python3.10/dist-packages (from torch) (10.3.2.106) Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /usr/local/lib/python3.10/dist-packages (from torch) (11.4.5.107) Requirement already satisfied: nvidia-nvjitlink-cu12 in /usr/local/lib/python3.10/dist-packages (from nvidia-cusolver-cu12==11.4.5.107->torch) (12.1.105) Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy==1.13.1->torch) (1.3.0) Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch) (3.0.2) WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv Looking in indexes: https://download.pytorch.org/whl/cu121 Requirement already satisfied: fbgemm_gpu in /usr/local/lib/python3.10/dist-packages (1.0.0+cu121) Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from fbgemm_gpu) (2.2.5) WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv Requirement already satisfied: torchmetrics in /usr/local/lib/python3.10/dist-packages (1.0.3) Requirement already satisfied: lightning-utilities>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from torchmetrics) (0.14.3) Requirement already satisfied: torch>=1.8.1 in /usr/local/lib/python3.10/dist-packages (from torchmetrics) (2.5.1+cu121) Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from torchmetrics) (25.0) Requirement already satisfied: numpy>1.20.0 in /usr/local/lib/python3.10/dist-packages (from torchmetrics) (2.2.5) Requirement already satisfied: typing_extensions in /usr/local/lib/python3.10/dist-packages (from lightning-utilities>=0.7.0->torchmetrics) (4.13.2) Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from lightning-utilities>=0.7.0->torchmetrics) (59.6.0) Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch>=1.8.1->torchmetrics) (3.13.1) ``` -------------------------------- ### Build and Serve Docs Locally Source: https://github.com/meta-pytorch/torchrec/blob/main/docs/README.md Run these commands to build the documentation and start a local HTTP server for preview. Ensure you are in the 'docs' directory and have installed the necessary requirements. ```bash cd docs pip3 install -r requirements.txt make html python3 -m http.server 8082 --bind :: ``` ```bash make html python3 -m http.server 8082 --bind :: ``` -------------------------------- ### Complete Recommendation Pipeline Example Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/INTEGRATION_GUIDE.md A full example demonstrating a recommendation pipeline that combines retrieval and ranking using TorchRec. This script requires PyTorch and Faiss to be installed. ```python #!/usr/bin/env python3 """ Complete recommendation pipeline combining retrieval and ranking. """ import torch import faiss from torchrec.modules.embedding_configs import EmbeddingBagConfig from torchrec.modules.embedding_modules import EmbeddingBagCollection from torchrec.sparse.jagged_tensor import KeyedJaggedTensor ``` -------------------------------- ### Install Cloud CLI Tools Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/README.md Install command-line interface tools for AWS, Azure, and GCP. ```bash # AWS pip install awscli boto3 # Azure pip install azure-cli # GCP pip install google-cloud-sdk ``` -------------------------------- ### Run Simple TorchRec Example Source: https://github.com/meta-pytorch/torchrec/blob/main/docs/source/setup-torchrec.md A basic Python script demonstrating the creation and forward pass of an EmbeddingBagCollection with KeyedJaggedTensor. This example verifies a successful TorchRec installation. ```python import torch import torchrec from torchrec.sparse.jagged_tensor import JaggedTensor, KeyedJaggedTensor ebc = torchrec.EmbeddingBagCollection( device="cpu", tables=[ torchrec.EmbeddingBagConfig( name="product_table", embedding_dim=16, num_embeddings=4096, feature_names=["product"], pooling=torchrec.PoolingType.SUM, ), torchrec.EmbeddingBagConfig( name="user_table", embedding_dim=16, num_embeddings=4096, feature_names=["user"], pooling=torchrec.PoolingType.SUM, ) ] ) product_jt = JaggedTensor( values=torch.tensor([1, 2, 1, 5]), lengths=torch.tensor([3, 1]) ) user_jt = JaggedTensor(values=torch.tensor([2, 3, 4, 1]), lengths=torch.tensor([2, 2])) # Q1: How many batches are there, and which values are in the first batch for product_jt and user_jt? kjt = KeyedJaggedTensor.from_jt_dict({"product": product_jt, "user": user_jt}) print("Call EmbeddingBagCollection Forward: ", ebc(kjt)) ``` -------------------------------- ### Install eksctl Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/aws/README.md Install the eksctl command-line tool, a simple CLI for provisioning and managing EKS clusters. ```bash curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp sudo mv /tmp/eksctl /usr/local/bin ``` -------------------------------- ### Run TorchRec Quickstart Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/README.md Commands to build and run the TorchRec quickstart locally using Docker or deploy it to a Kubernetes cluster. ```bash # Build and run locally (single GPU) cd quickstart && docker build -t torchrec-quickstart . && docker run --gpus all torchrec-quickstart train_torchrec_quickstart.py # Or deploy to Kubernetes (multi-GPU, multi-node) kubectl apply -f quickstart/kubernetes_job.yaml ``` -------------------------------- ### Run TorchRec Example Script Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/prediction/README.md Execute the main example script for TorchRec inference. ```bash python3 predict_using_torchrec.py ``` -------------------------------- ### Install PyTorch Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/prediction/README.md Install the PyTorch library, a fundamental dependency for TorchRec. ```bash pip install torch torchvision ``` -------------------------------- ### Execute TorchRec Example Script Source: https://github.com/meta-pytorch/torchrec/blob/main/docs/source/setup-torchrec.md Command to run the saved TorchRec Python example script from the terminal. This confirms the installation and basic functionality. ```bash python torchrec_example.py ``` -------------------------------- ### Activate Virtual Environment and Run Example Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/prediction/README.md Activate a Python virtual environment before running the TorchRec example script. ```bash source your_venv/bin/activate python predict_using_torchrec.py ``` -------------------------------- ### Install TorchRec Source: https://github.com/meta-pytorch/torchrec/blob/main/torchrec/distributed/planner/Planner_Introduction.ipynb Installs the nightly build of TorchRec. ```python # install torchrec !pip3 install torchrec-nightly ``` -------------------------------- ### Run Profiling Example with Sorted ZCH Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/zch/Readme.md Execute the main script to run the profiling example using the sorted ZCH technique. ```bash python main.py ``` -------------------------------- ### Install ZCH Benchmarking Dependencies Source: https://github.com/meta-pytorch/torchrec/blob/main/torchrec/distributed/benchmark/benchmark_zch/Readme.md Commands to install PyTorch, FBGEMM-GPU, TorchRec, and the generative recommenders library. ```bash # Install torch and fbgemm_gpu following instructions in https://docs.pytorch.org/FBGEMM/fbgemm_gpu/development/InstallationInstructions.html pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu126/ pip install --pre fbgemm-gpu --index-url https://download.pytorch.org/whl/nightly/cu126/ # Install torchrec pip install torchrec --index-url https://download.pytorch.org/whl/nightly/cu126 # Install generative recommenders git clone https://github.com/meta-recsys/generative-recommenders.git cd generative-recommenders pip install -e . ``` -------------------------------- ### Install TorchRec Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/prediction/README.md Install the TorchRec library, which provides specialized modules for recommendation systems. ```bash pip install torchrec ``` -------------------------------- ### Install TorchRec and Dependencies Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/ray/README.md Installs the required packages for TorchRec, TorchX, and Ray. ```bash pip install --pre torchrec -f https://download.pytorch.org/whl/torchrec/index.html pip install torchx-nightly pip install "ray[default]" -qqq ``` -------------------------------- ### Torchx Job Output Example Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/bert4rec/README.MD Example log output from a Torchx job, showing scheduling, progress, and warnings. ```text torchx 2022-03-23 05:38:40 INFO Log files located in: /tmp/torchx_fby9w0w9/torchx/bert4rec_main-txq11m6736w20c/bert4rec_main/0 local_cwd://torchx/bert4rec_main-txq11m6736w20c torchx 2022-03-23 05:38:40 INFO Waiting for the app to finish... bert4rec_main/0 WARNING: bert4rec_main/0 ***************************************** bert4rec_main/0 Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed. bert4rec_main/0 ***************************************** bert4rec_main/0 [2]:Filtering triplets bert4rec_main/0 [7]:Filtering triplets bert4rec_main/0 [4]:Filtering triplets bert4rec_main/0 [6]:Filtering triplets bert4rec_main/0 [3]:Filtering triplets bert4rec_main/0 [5]:Filtering triplets bert4rec_main/0 [2]:Densifying index bert4rec_main/0 [7]:Densifying index bert4rec_main/0 [4]:Densifying index bert4rec_main/0 [6]:Densifying index bert4rec_main/0 [3]:Densifying index bert4rec_main/0 [5]:Densifying index bert4rec_main/0 [1]:Filtering triplets bert4rec_main/0 [0]:Filtering triplets bert4rec_main/0 [1]:Densifying index bert4rec_main/0 [0]:Densifying index bert4rec_main/0 [2]:Splitting bert4rec_main/0 [2]: bert4rec_main/0 [6]:Splitting bert4rec_main/0 [6]: bert4rec_main/0 [7]:Splitting bert4rec_main/0 [7]: bert4rec_main/0 [4]:Splitting bert4rec_main/0 [4]: bert4rec_main/0 [3]:Splitting bert4rec_main/0 [3]: bert4rec_main/0 [5]:Splitting bert4rec_main/0 [5]: bert4rec_main/0 [1]:Splitting bert4rec_main/0 [1]: ``` -------------------------------- ### Run Profiling Example with Custom Parameters Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/zch/Readme.md Run the MPZCH profiling example with custom batch size, number of iterations, and embeddings per table. ```bash python main.py --use_mpzch --batch_size 8 --num_iters 100 --num_embeddings_per_table 1000 ``` -------------------------------- ### Run Profiling Example with MPZCH Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/zch/Readme.md Execute the main script with the --use_mpzch flag to run the profiling example using the MPZCH technique. ```bash python main.py --use_mpzch ``` -------------------------------- ### Install TorchRec and Dependencies Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/sharding/sharding.ipynb Use these commands to install the required packages from the PyTorch index. ```bash !pip3 install --pre torch --index-url https://download.pytorch.org/whl/cu121 -U !pip3 install fbgemm_gpu --index-url https://download.pytorch.org/whl/cu121 !pip3 install torchmetrics !pip3 install torchrec --index-url https://download.pytorch.org/whl/cu121 ``` -------------------------------- ### Install NVIDIA GPU Drivers Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/gcp/README.md Deploy the NVIDIA driver installer daemonset to the GKE cluster nodes. ```bash # Install NVIDIA GPU device drivers kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/container-engine-accelerators/master/nvidia-driver-installer/cos/daemonset-preloaded.yaml ``` -------------------------------- ### Install TorchX with Kubernetes Support Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/gcp/README.md Install TorchX with the necessary Kubernetes integration. This command ensures all dependencies for running on Kubernetes are included. ```bash pip install torchx[kubernetes] ``` -------------------------------- ### Install TorchRec and dependencies Source: https://github.com/meta-pytorch/torchrec/blob/main/Torchrec_Introduction.ipynb Use these commands to install the necessary packages, including PyTorch, FBGEMM, and TorchRec, from the nightly wheels. ```bash !pip3 install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu121 -U !pip3 install fbgemm_gpu --index-url https://download.pytorch.org/whl/nightly/cu121 !pip3 install torchmetrics==1.0.3 !pip3 install torchrec --index-url https://download.pytorch.org/whl/nightly/cu121 ``` -------------------------------- ### Activate Conda Environment and Run Example Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/prediction/README.md Activate a specific conda environment before running the TorchRec example script. ```bash conda activate your_environment_name python predict_using_torchrec.py ``` -------------------------------- ### E2E Example for RecMetricModule Source: https://github.com/meta-pytorch/torchrec/blob/main/torchrec/metrics/README.md Demonstrates the end-to-end usage of RecMetricModule with NE and Throughput metrics. Call update() for each batch and compute() to get the final metrics. ```python task = RecTaskInfo( name="task_name", label_name="label", prediction_name="prediction", weight_name="weight", ) metrics_config = MetricsConfig( rec_tasks=[task], rec_metrics={ RecMetricEnum.NE: RecMetricDef( rec_tasks=[task], window_size=10_000_000 ), }, throughput_metric=ThroughputDef(), state_metrics=[], ) batch_size = 128 metric_module = generate_metric_module( RecMetricModule, metrics_config=metrics_config, batch_size=batch_size, world_size=64, my_rank=0, state_metrics_mapping={}, device=torch.device("cpu"), ) n_batches = 10 for _ in range(n_batches): model_output = gen_test_batch( label_name=task.label_name, prediction_name=task.prediction_name, weight_name=task.weight_name, batch_size=batch_size, ) metric_module.update(model_output) metrics_result = metric_module.compute() ``` ```python {'ne-task_name|lifetime_ne': tensor([0.8873], dtype=torch.float64), 'ne-task_name|window_ne': tensor([0.6875], dtype=torch.float64), 'throughput-throughput|total_examples': tensor(1400)} ``` -------------------------------- ### Create Filestore Instance Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/gcp/README.md Provisions a High Scale SSD Filestore instance for high-performance data access. ```bash # Create Filestore instance (High Scale tier for best performance) gcloud filestore instances create torchrec-filestore \ --zone us-central1-a \ --tier HIGH_SCALE_SSD \ --file-share name=torchrec_data,capacity=10TB \ --network name=default ``` -------------------------------- ### Install PyTorch and TorchRec Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/prediction/README.md Install specific versions of PyTorch and TorchRec to ensure compatibility. This is useful if you encounter installation issues. ```bash pip install torch==2.0.0 torchvision==0.15.0 pip install torchrec==0.5.0 ``` -------------------------------- ### Configure Spot Instances in eksctl Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/aws/README.md Example configuration for enabling spot instances in EKS using eksctl. This allows for significant cost savings on GPU compute nodes. ```yaml # In eksctl config, add spot instances managedNodeGroups: - name: gpu-spot-nodes instanceTypes: ["p4d.24xlarge"] spot: true minSize: 0 maxSize: 4 ``` -------------------------------- ### Install Multiprocess Library Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/sharding/sharding.ipynb Installs the multiprocess package using pip. ```bash !pip3 install multiprocess ``` -------------------------------- ### Execute Recommendation Inference Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/INTEGRATION_GUIDE.md Example usage showing how to instantiate the pipeline and generate recommendations for a specific user. ```python if __name__ == "__main__": # Create pipeline pipeline = create_pipeline( retrieval_checkpoint_dir="./retrieval/checkpoints", ranking_checkpoint_path="./golden_training/checkpoints/model.pt", ) # Generate recommendations for a user user_features = KeyedJaggedTensor( keys=["user_id"], values=torch.tensor([12345]), lengths=torch.tensor([1]), ) user_dense = torch.randn(1, 13) # 13 dense features recommendations = pipeline.recommend(user_features, user_dense) print(f"Recommended items: {recommendations}") ``` -------------------------------- ### Install TorchRec Dependencies Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/README.md Install the required PyTorch, TorchRec, and FBGEMM-GPU packages. ```bash pip install torch torchrec fbgemm-gpu ``` -------------------------------- ### Upload Training Data to Azure Blob Storage Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/azure/README.md Sets up a storage account and container to host the training dataset. ```bash # Create storage account az storage account create \ --name torcrecstorage \ --resource-group torchrec-rg \ --location eastus2 \ --sku Standard_LRS # Create container az storage container create --name criteo-data --account-name torcrecstorage # Upload dataset az storage blob upload-batch \ --destination criteo-data \ --source ./criteo_data \ --account-name torcrecstorage ``` -------------------------------- ### Provision Cloud Infrastructure for Training Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/quickstart/README.md Commands to create GPU-enabled clusters on major cloud providers. ```bash eksctl create cluster --name torchrec-cluster \ --node-type p4d.24xlarge \ --nodes 2 \ --region us-east-1 ``` ```bash az aks create --resource-group mygroup \ --name torchrec-cluster \ --node-vm-size Standard_ND96asr_v4 \ --node-count 2 ``` ```bash gcloud container clusters create torchrec-cluster \ --machine-type a2-highgpu-8g \ --num-nodes 2 \ --accelerator type=nvidia-tesla-a100,count=8 ``` -------------------------------- ### Install TorchRec Dependencies Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/retrieval/README.md Install the necessary packages including PyTorch, FAISS, and TorchRec. ```bash # Install dependencies conda install -c conda-forge pytorch faiss-gpu pip install torchx torchrec ``` -------------------------------- ### Install TorchRec on Colab Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/sharding/uvm.ipynb Installs Miniconda, PyTorch with CUDA support, and the TorchRec library. ```bash # install conda to make installying pytorch with cudatoolkit 11.3 easier. !wget https://repo.anaconda.com/miniconda/Miniconda3-py37_4.9.2-Linux-x86_64.sh !chmod +x Miniconda3-py37_4.9.2-Linux-x86_64.sh !bash ./Miniconda3-py37_4.9.2-Linux-x86_64.sh -b -f -p /usr/local # install pytorch with cudatoolkit 11.3 !conda install pytorch cudatoolkit=11.3 -c pytorch-nightly -y # install torchrec !pip3 install torchrec-nightly ``` -------------------------------- ### Test TorchRec Installation Source: https://github.com/meta-pytorch/torchrec/blob/main/README.MD Commands to verify the installation using TorchX for distributed execution. ```bash 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 ``` -------------------------------- ### Training Progress Visualization Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/prediction/README.md Example output showing training progress over epochs, including loss values and a visual progress bar. ```text Epoch 1: Loss: 2.5432 ████░░░░░░░░░░░░░░░░░░░░░░░░░░ Epoch 2: Loss: 1.8721 ████████░░░░░░░░░░░░░░░░░░░░░░ Epoch 3: Loss: 1.2345 ████████████░░░░░░░░░░░░░░░░░░ Epoch 4: Loss: 0.8234 ████████████████░░░░░░░░░░░░░░ Epoch 5: Loss: 0.5123 ████████████████████░░░░░░░░░░ ... Epoch 10: Loss: 0.1234 ████████████████████████████████ ✓ ``` -------------------------------- ### Install FBGEMM-GPU Source: https://github.com/meta-pytorch/torchrec/blob/main/README.MD Commands to install the FBGEMM-GPU library required for optimized RecSys kernels. ```bash 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 ``` -------------------------------- ### Build TorchRec Docker container Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/cloud_deployment/quickstart/README.md Build a Docker image for the TorchRec quickstart environment. ```bash # Build the container docker build -t torchrec-quickstart . ``` -------------------------------- ### Install NumPy Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/prediction/README.md Install the NumPy library, often used for numerical operations in conjunction with PyTorch. ```bash pip install numpy ``` -------------------------------- ### Initialize Distributed Communication Backend Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/sharding/sharding.ipynb Sets up environment variables for distributed communication. Ensure MASTER_ADDR and MASTER_PORT are correctly configured for your environment. ```python import os import copy import torch import torchrec import multiprocess from torchrec.distributed.types import ShardingEnv os.environ["MASTER_ADDR"] = "localhost" os.environ["MASTER_PORT"] = "10000" ``` -------------------------------- ### Initialize Sharding Topology and Planner Source: https://github.com/meta-pytorch/torchrec/blob/main/torchrec/distributed/planner/Planner_Introduction.ipynb Sets up a 2-GPU topology and generates an initial sharding plan for a model using the EmbeddingShardingPlanner. ```python topology_2gpu = Topology( world_size=2, compute_device="cuda" ) planner = EmbeddingShardingPlanner( topology=topology_2gpu, debug=True, ) sharding_plan = planner.plan(small_toy_model, sharders=[EmbeddingBagCollectionSharder()]) ``` -------------------------------- ### Install Requirements and TorchRec Source: https://github.com/meta-pytorch/torchrec/blob/main/README.MD Commands to install Python dependencies and the TorchRec package in development mode. ```bash pip install -r requirements.txt ``` ```bash python setup.py install develop ``` -------------------------------- ### Implement Real-time Serving with Caching Source: https://github.com/meta-pytorch/torchrec/blob/main/examples/INTEGRATION_GUIDE.md Cache retrieval results in Redis to optimize re-ranking performance. ```python # Cache retrieval results, re-rank on the fly cached_candidates = redis.get(f"candidates:{user_id}") if cached_candidates is None: cached_candidates = retrieval_model(user_kjt) redis.set(f"candidates:{user_id}", cached_candidates, ttl=3600) scores = ranking_model(dense, sparse) ```