Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/pytorch/rl/llms.txt

Use this file to discover all available pages before exploring further.

TorchRL is distributed as a PyPI package and as optional CUDA-specific wheels for users who need hardware-accelerated prioritized replay buffers. This page covers every supported install path — stable release, nightly builds, source checkouts, and CUDA wheels — along with the optional environment library dependencies and a quick smoke test to confirm everything is working.

Requirements

DependencyMinimum versionNotes
Python3.10+Earlier versions are not supported
PyTorch2.1+Install from pytorch.org before installing TorchRL
TensorDict0.13.xInstalled automatically as a dependency
TorchRL releases are synchronized with PyTorch releases. Always install PyTorch first from the PyTorch installation selector to ensure you get the build that matches your hardware (CPU, CUDA 11.x, CUDA 12.x, etc.), then install TorchRL on top.

Install TorchRL

The standard PyPI wheel is the right default for most users. It includes CPU-based prioritized replay buffers and all core TorchRL features.
pip install torchrl
Verify the install:
import torchrl
print(torchrl.__version__)  # 0.13.0

Optional Environment Dependencies

TorchRL’s core components have no dependencies beyond PyTorch and TensorDict. Environment library wrappers are guarded by optional extras — install only what you need.
# Hydra configuration, logging utilities, and development helpers
pip install "torchrl[utils]"

# Gymnasium continuous-control environments (MuJoCo, robotics tasks, etc.)
pip install "torchrl[gym_continuous]"

# Atari environments via Gymnasium
pip install "torchrl[atari]"

# Offline RL datasets and data loading helpers
pip install "torchrl[offline-data]"

# Multi-agent environment libraries (VMAS, PettingZoo, etc.)
pip install "torchrl[marl]"

# LLM post-training with vLLM backend (Linux only)
pip install "torchrl[llm-vllm]"

# LLM post-training with SGLang backend (Linux only)
pip install "torchrl[llm-sglang]"
If you only need specific environment libraries, you can also install them individually:
LibraryInstall command
Gymnasium (basic)pip install gymnasium
MuJoCo environmentspip install "gymnasium[mujoco]"
DM Controlpip install dm_control
Braxpip install brax
PettingZoopip install pettingzoo
VMASpip install vmas
Jumanjipip install jumanji
OpenSpielpip install open_spiel
Safety Gymnasiumpip install safety_gymnasium
Isaac LabSee the Isaac Lab documentation
Some optional libraries (Isaac Lab, robohive, vLLM, SGLang) have platform-specific requirements or need additional system packages. Consult the respective library’s documentation for complete setup instructions. vLLM and SGLang integrations are only supported on Linux.

Verifying the Installation

Run this smoke test to confirm TorchRL is installed correctly and the core components are functional:
import torch
from tensordict.nn import TensorDictModule
from torch import nn

from torchrl.envs import PendulumEnv, StepCounter, TransformedEnv
from torchrl.data import PrioritizedReplayBuffer

# 1. Check that the C++ extension loaded correctly.
rb = PrioritizedReplayBuffer(alpha=0.7, beta=0.5)
print("PrioritizedReplayBuffer OK")

# 2. Check a native environment + transform stack.
env = TransformedEnv(PendulumEnv(), StepCounter(max_steps=10))
rollout = env.rollout(max_steps=5)
assert rollout.batch_size == torch.Size([5])
print("Environment rollout OK — shape:", rollout.batch_size)

# 3. Check a policy module.
policy = TensorDictModule(
    nn.Sequential(nn.LazyLinear(32), nn.Tanh(), nn.Linear(32, 1), nn.Tanh()),
    in_keys=["observation"],
    out_keys=["action"],
)
out = policy(env.reset())
print("Policy forward pass OK — action shape:", out["action"].shape)

print("\nTorchRL installation verified successfully.")
Expected output:
PrioritizedReplayBuffer OK
Environment rollout OK — shape: torch.Size([5])
Policy forward pass OK — action shape: torch.Size([1])

TorchRL installation verified successfully.
If you see undefined symbol errors when importing torchrl._torchrl, the C++ extension was compiled against a different PyTorch version than the one currently installed. Reinstall TorchRL after ensuring your PyTorch version matches, or consult the versioning issues guide.

Build docs developers (and LLMs) love