Environment:Huggingface Trl Python Core Dependencies
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Deep_Learning |
| Last Updated | 2026-02-06 17:00 GMT |
Overview
Python 3.10+ environment with transformers >= 4.56.2, accelerate >= 1.4.0, datasets >= 3.0.0, and PyTorch as the core runtime for all TRL trainers.
Description
This environment defines the mandatory runtime dependencies for the TRL library. Every trainer (SFT, DPO, GRPO, Reward, PPO, RLOO, and all experimental trainers) requires these packages at their specified minimum versions. The library is built on top of Hugging Face's transformers ecosystem and uses accelerate for distributed training orchestration and datasets for data loading.
Usage
Use this environment for any TRL training workflow. This is the base prerequisite that must be satisfied before any optional dependencies (vLLM, PEFT, DeepSpeed, quantization) can be layered on top.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux (Ubuntu 20.04+), macOS, Windows (WSL2) | Linux is the primary supported platform |
| Hardware | CPU or GPU | GPU (NVIDIA CUDA, AMD ROCm, Intel XPU) recommended for training |
| Python | >= 3.10 | Supports 3.10, 3.11, 3.12, 3.13 |
| Disk | 2GB+ for packages | Additional space needed for model weights and datasets |
Dependencies
System Packages
- `python` >= 3.10
- `pip` (latest)
Python Packages
- `transformers` >= 4.56.2
- `accelerate` >= 1.4.0
- `datasets` >= 3.0.0
- `packaging` > 20.0
- `torch` (PyTorch, version compatible with transformers)
- `numpy`
- `pandas`
Credentials
The following environment variables may be needed depending on usage:
- `HF_TOKEN`: Hugging Face API token for accessing gated models and datasets, and for pushing models to the Hub.
- `WANDB_API_KEY`: Weights & Biases API key for experiment tracking (optional).
Quick Install
# Install TRL with core dependencies
pip install trl
# Or install from source
pip install git+https://github.com/huggingface/trl.git
Code Evidence
Core dependencies from `pyproject.toml:30-35`:
requires-python = ">=3.10"
dependencies = [
"accelerate>=1.4.0",
"datasets>=3.0.0",
"packaging>20.0",
"transformers>=4.56.2",
]
Python version classifiers from `pyproject.toml:24-28`:
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13"
Hardware detection from `trl/scripts/env.py:42-47`:
if torch.cuda.is_available():
devices = [torch.cuda.get_device_name(i) for i in range(torch.cuda.device_count())]
elif torch.backends.mps.is_available():
devices = ["MPS"]
elif torch.xpu.is_available():
devices = [torch.xpu.get_device_name(i) for i in range(torch.xpu.device_count())]
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
requires-python >= 3.10 |
Python version too old | Upgrade to Python 3.10+ |
ImportError: transformers |
transformers not installed or version too old | pip install transformers>=4.56.2
|
ImportError: accelerate |
accelerate not installed | pip install accelerate>=1.4.0
|
Compatibility Notes
- NVIDIA GPUs (CUDA): Full support. Primary development platform.
- AMD GPUs (ROCm): Supported via PyTorch ROCm builds.
- Intel XPU: Supported via PyTorch XPU builds. Detected via
torch.xpu.is_available(). - Apple MPS: Detected but limited support for training.
- CPU: Supported for development and testing; not recommended for training.
Related Pages
- Implementation:Huggingface_Trl_TrlParser_SFTConfig
- Implementation:Huggingface_Trl_SFTTrainer_Init
- Implementation:Huggingface_Trl_DPOTrainer_Init_Train
- Implementation:Huggingface_Trl_GRPOTrainer_Init
- Implementation:Huggingface_Trl_RewardTrainer_Init_Train
- Implementation:Huggingface_Trl_PPOTrainer_Init