opensi·si

The examples/ directory contains a collection of self-contained examples that demonstrate how to use the TRL library for various applications. Each example lives in its own…

Example Overview

The examples/ directory contains a collection of self-contained examples that demonstrate how to use the TRL library for various applications. Each example lives in its own folder named after the method and the task it demonstrates (e.g. grpo_wordle, sft_gpt_oss_chess), and holds everything the example needs: scripts, notebooks, prompts, chat templates, and evaluation code.

Basic single-trainer training scripts are not examples: they live in trl/scripts and are exposed through the command line interface (trl sft, trl dpo, trl grpo, …). Each trainer's documentation page also contains a complete runnable snippet.

Shared resources sit at the root of examples/:

  • examples/accelerate_configs: 🤗 Accelerate configuration files for multi-GPU, DeepSpeed ZeRO, FSDP, and context-parallel setups, used by many examples.
  • examples/datasets: the scripts used to generate the trl-lib datasets used across the examples.

Getting Started

Install TRL and additional dependencies as follows:

pip install --upgrade trl[quantization]

Check for additional optional dependencies here. Notebook-based examples are self-contained and can run on free Colab; script-based examples run on single-GPU, multi-GPU, or DeepSpeed setups (see Distributed Training below).

Index

표 (48행)
Example Description Open in Colab
async_distillation_math Async on-policy distillation on GSM8K with experimental.async_distillation.AsyncDistillationTrainer: the teacher is served over HTTP with vLLM, including a multi-teacher (MOPD) variant that fuses the math, code and instruction-following experts released with Open-MOPD.
async_grpo_harbor AsyncGRPO training on a Harbor task suite through any installed coding agent (mini-swe-agent, opencode, claude-code, ...) served over OpenEnv: the agent owns its own loop in a sandbox and TRL trains on the token ids and logprobs recorded by the capture proxy.
async_grpo_math Asynchronous GRPO on GSM8K with experimental.async_grpo.AsyncGRPOTrainer, decoupling generation (vLLM server) from training, including a LoRA variant that syncs only the adapter to the vLLM server.
dpo_reduce_hallucinations DPO fine-tuning of a Vision Language Model to reduce hallucinations using the openbmb/RLAIF-V-Dataset dataset.
gold_chatbot_arena General Online Logit Distillation (GOLD) of a Qwen2 teacher into a Llama 3.2 student (cross-tokenizer) on chatbot_arena_completions with experimental.gold.GOLDTrainer, with full-training and LoRA variants.
gold_qwen3_vl General Online Logit Distillation (GOLD) of Qwen3-VL-8B into smaller VLM students with experimental.gold.GOLDTrainer, covering same-family (JSD loss) and cross-family (ULD loss) distillation.
grpo_2048 GRPO with tool calling to teach a model to play the 2048 game.
grpo_browsergym GRPO with the BrowserGym OpenEnv environment, with LLM and VLM variants.
grpo_carla GRPO with the CARLA autonomous-driving OpenEnv environment, with LLM and VLM variants (multimodal camera-image tool responses).
grpo_catch GRPO with the Catch (OpenSpiel) OpenEnv environment.
grpo_continuous_batching GRPO with transformers' continuous batching engine for faster generation on large batches with variable completion lengths.
grpo_echo Minimal GRPO training with the Echo OpenEnv environment.
grpo_harbor GRPO training against a Harbor task suite with a pluggable base agent (bash / jupyter / terminal_notes harnesses). See the Harbor Integration guide.
grpo_ministral3_vl GRPO Ministral 3 with QLoRA on free Colab.
grpo_multi_env Multi-environment GRPO training: Wordle + Catch OpenEnv environments in the same training run.
grpo_qlora GRPO using QLoRA on free Colab.
grpo_qwen3_vl GRPO Qwen3-VL with QLoRA on free Colab.
grpo_rnj_1_instruct GRPO on rnj-1-instruct with QLoRA on Colab to add reasoning capabilities.
grpo_seta GRPO training against the SETA ORS environment on the openreward.ai catalog. See the OpenReward Integration guide.
grpo_sql_agent GRPO to train an agent that answers questions by querying a SQL database (script and notebook; not runnable on free Colab due to OOM).
grpo_sudoku GRPO to play Sudoku on an OpenEnv environment (script and notebook).
grpo_visual_math GRPO fine-tuning of a multimodal model for reasoning using the lmms-lab/multimodal-open-r1-8k-verified dataset.
grpo_wordle GRPO to play Wordle (TextArena) on an OpenEnv environment (script and notebook).
gspo_math GSPO via the GRPOTrainer for math reasoning on the AI-MO/NuminaMath-TIR dataset.
gspo_visual_math GSPO via the GRPOTrainer to fine-tune a multimodal model for reasoning using the lmms-lab/multimodal-open-r1-8k-verified dataset.
mpo_visual_preferences MPO via the DPOTrainer to align a multimodal model based on preferences using the HuggingFaceH4/rlaif-v_formatted dataset and a set of loss weights.
online_dpo_visual_math Online DPO fine-tuning of a Vision Language Model with experimental.online_dpo.OnlineDPOTrainer.
rloo_math RLOO with the RLOOTrainer for math reasoning on the AI-MO/NuminaMath-TIR dataset with vLLM.
rloo_visual_math RLOO fine-tuning of a multimodal model for reasoning using the lmms-lab/multimodal-open-r1-8k-verified dataset.
sdft_privileged_context Self-distillation fine-tuning with experimental.sdft.SDFTTrainer, distilling privileged (teacher-only) context into the model.
sdpo_math SDPO with experimental.sdpo.SDPOTrainer using verifiable math rewards and optional environment feedback on openai/gsm8k.
sft_beam LoRA SFT of reflection/Beam-1.0-501B-A23B on one 8xB300 node with SFTTrainer, sharded at load time by transformers' DistributedConfig (expert parallelism with token dispatch).
sft_diffusion_gemma SFT of the DiffusionGemma block-diffusion language model on GSM8K by extending the SFTTrainer with a block-diffusion objective.
sft_gemma3 SFT of Gemma 3 on the Codeforces COTS dataset.
sft_gemma3_vision SFT of Gemma 3 on vision to text tasks.
sft_gpt_oss_chess Full fine-tuning of openai/gpt-oss-20b on chess puzzles with SFTTrainer: TRL loads its MXFP4 experts dequantized, and the fine-tuned experts are quantized back to MXFP4 to serve like the original.
sft_ministral3_vl SFT Ministral 3 with QLoRA on free Colab.
sft_mistral_large_4 LoRA SFT of mistralai/Mistral-Large-4-1T-A52B on top of its FP8 weights on one 8xB300 node with SFTTrainer, sharded at load time by transformers' DistributedConfig (expert parallelism with token dispatch).
sft_nemotron_3 SFT of NVIDIA Nemotron 3 models (script and LoRA notebook).
sft_qlora SFT using QLoRA on free Colab.
sft_qwen3_8b_1m_context SFT of Qwen3-8B on 1,048,576-token sequences with context parallelism, on one 8xH100 node.
sft_qwen3_vl SFT Qwen3-VL with QLoRA on free Colab.
tail_sft_gsm8k TailSFT on GSM8K by extending SFTTrainer with initial-policy loss filtering.
sft_muse_spark_open LoRA SFT of meta-models/Muse-Spark-Open-816B-A42B on 8 nodes with SFTTrainer, sharded at load time by transformers' DistributedConfig (expert parallelism with token dispatch).
sft_tool_calling Teaching tool calling to a model without native tool-calling support using SFT with QLoRA (script, chat template, and notebook).
sft_visual_chat SFT of a Vision Language Model in a chat setting. Only tested with LLaVA 1.5, LLaVA 1.6, and Llama-3.2-11B-Vision-Instruct; users may see unexpected behaviour in other model architectures.
xtoken X-Token off-policy cross-tokenizer knowledge distillation with experimental.gold.GOLDTrainer, including projection-matrix preparation.

Distributed Training

You can run the example scripts on multiple GPUs with 🤗 Accelerate:

accelerate launch --config_file=examples/accelerate_configs/multi_gpu.yaml --num_processes {NUM_GPUS} path_to_script.py --all_arguments_of_the_script

For DeepSpeed ZeRO-{1,2,3}:

accelerate launch --config_file=examples/accelerate_configs/deepspeed_zero{1,2,3}.yaml --num_processes {NUM_GPUS} path_to_script.py --all_arguments_of_the_script

Adjust NUM_GPUS and --all_arguments_of_the_script as needed.

Source and license

Source: TRL documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.