Software DevelopmentOfficial · huggingface

Trl Training skill for Claude

Post-train LLMs with TRL (Transformers Reinforcement Learning) — SFT, DPO, GRPO, KTO, and reward-model training.

When Claude uses it

Use when writing or debugging training code with the TRL Python API or the trl CLI.

Trl Training SKILL.md

The full skill file from huggingface/skills (Apache-2.0).

TRL

Each method pairs a *Trainer class with a *Config dataclass. Configs extend transformers.TrainingArguments, so all of its arguments work in any trainer config.

TrainerDataset type
SFTTrainerlanguage modeling or prompt-completion
DPOTrainerpreference (chosen/rejected pairs)
GRPOTrainerprompt-only + reward function(s)
DistillationTrainerprompt-only + a teacher model (on-policy distillation)
KTOTrainerunpaired preference (per-sample bool label)
RewardTrainerpreference (chosen/rejected pairs); trains a scalar reward model, not a policy

Many more trainers (OnlineDPO, ORPO, CPO, GKD, …) live in trl.experimental with unstable APIs: https://huggingface.co/docs/trl/experimental_overview

from datasets import load_dataset
from trl import SFTConfig, SFTTrainer

trainer = SFTTrainer(
    model="Qwen/Qwen2.5-0.5B",  # model ID or a PreTrainedModel instance
    args=SFTConfig(output_dir="Qwen2.5-0.5B-SFT"),
    train_dataset=load_dataset("trl-lib/Capybara", split="train"),
)
trainer.train()

Pass model as a string and route loading kwargs through model_init_kwargs (e.g. {"dtype": "bfloat16", "attn_implementation": "kernels-community/flash-attn2"}) instead of calling from_pretrained yourself. The tokenizer/processor is inferred from the model; pass processing_class only when it differs. For LoRA, pass peft_config=LoraConfig(...).

Dataset formats

Conversational: {"messages": [{"role": ..., "content": ...}]} (language modeling) or {"prompt": [...], "completion": [...]}. The chat template is applied automatically — never apply it yourself. Extra columns are allowed; GRPO forwards them to reward functions. Reference: https://huggingface.co/docs/trl/dataset_formats

SFT: the fields that matter

SFTConfig(
    max_length=1024,        # truncation length; None disables truncation
    packing=True,           # pack sequences into max_length blocks: fewer pad tokens, higher throughput
    padding_free=True,      # flatten batch, no padding; requires FlashAttention; implied by packing
    use_liger_kernel=True,  # fused Liger kernels, reduces peak memory
    assistant_only_loss=True,  # loss only on assistant turns (conversational datasets)
)

GRPO: online RL

def reward_len(completions, **kwargs):
    return [-abs(20 - len(c[0]["content"])) for c in completions]

trainer = GRPOTrainer(
    model="Qwen/Qwen2.5-0.5B-Instruct",
    reward_funcs=reward_len,  # or a list; rewards are summed
    args=GRPOConfig(output_dir="Qwen2.5-0.5B-GRPO", max_completion_length=512),
    train_dataset=load_dataset("trl-lib/DeepMath-103K", split="train"),
)

Reward functions are called with keyword arguments prompts, completions, completion_ids, trainer_state, plus every extra dataset column — accept **kwargs for the ones you ignore. Return list[float], one reward per completion. With conversational data, completions is a list of message lists, not strings.

The generation batch is per_device_train_batch_size × num_processes × steps_per_generation (or set generation_batch_size directly) and must be divisible by num_generations (default 8). Generation is the usual bottleneck — enable vLLM with use_vllm=True: vllm_mode="colocate" shares the training GPUs (size with vllm_gpu_memory_utilization); vllm_mode="server" uses a separate trl vllm-serve --model <model_id>.

AsyncGRPOTrainer (trl.experimental.async_grpo) implements the same algorithm with generation decoupled from training: a background worker streams completions from a vLLM server while the training loop consumes them, so the two overlap instead of alternating.

CLI

Flags mirror the config fields: trl sft --model_name_or_path Qwen/Qwen2.5-0.5B --dataset_name trl-lib/Capybara. YAML via --config; distributed presets via --accelerate_config zero3 (Python scripts: accelerate launch train.py).

How to install Trl Training

Claude Code

Copy the skill into your personal skills folder (or into .claude/skills/ inside a project):

npx degit huggingface/skills/skills/trl-training#main ~/.claude/skills/trl-training

Codex

npx degit huggingface/skills/skills/trl-training#main ~/.codex/skills/trl-training

Claude.ai and Claude Desktop

Download the skill folder from GitHub, zip it, and upload it under Settings → Capabilities → Skills.

Frequently asked questions

+What does the Trl Training skill do?

Post-train LLMs with TRL (Transformers Reinforcement Learning) — SFT, DPO, GRPO, KTO, and reward-model training. Use when writing or debugging training code with the TRL Python API or the trl CLI.

+How do I install Trl Training in Claude Code?

Copy the skill folder into ~/.claude/skills/trl-training, for example with "npx degit huggingface/skills/skills/trl-training#main ~/.claude/skills/trl-training". Claude Code loads it automatically and uses it when a task matches.

+Does Trl Training work with ChatGPT or Codex?

Yes. Trl Training uses the open SKILL.md format. In Codex, put the folder in ~/.codex/skills/trl-training. In Claude.ai, zip the folder and upload it under Settings → Capabilities → Skills.

+Is Trl Training free?

Trl Training is published on GitHub by huggingface under the Apache-2.0 license, which allows free use.

Related software development skills

  1. Code Review

    Review the changes since a fixed point (commit, branch, tag, or merge-base) along two axes: Standards (does the code follow this repo's…

    mattpocock/skills★ 327k
  2. Using Agent Skills

    Discovers and invokes agent skills. Use when starting a session, or when you need to decide which skill or workflow applies to the piece of…

    addyosmani/agent-skills★ 119k
  3. Build

    Fully automate a coding task with make-plan, do, and babysit.

    thedotmack/claude-mem★ 118k
  4. Address Sanitizer

    Official

    Builds and runs code under AddressSanitizer to catch buffer overflows, use-after-free, and other memory errors during fuzzing or tests.

    trailofbits/skills★ 8.3k
  5. Adjudicate Regression

    Official

    Use when deciding whether source and live reproduction evidence establish a new regression or an exclusion.

    trailofbits/skills★ 8.3k
  6. Atheris

    Official

    Sets up and runs Atheris, the coverage-guided Python fuzzer built on libFuzzer.

    trailofbits/skills★ 8.3k
  7. Code Improver

    Official

    Runs an autonomous review-and-fix improvement loop over any code target — a skill, plugin, module, or directory — using a reviewer the user…

    trailofbits/skills★ 8.3k
  8. Code Maturity Assessor

    Official

    Systematic code maturity assessment using Trail of Bits' 9-category framework.

    trailofbits/skills★ 8.3k
  9. Codeql

    Official

    Scans a codebase for security vulnerabilities using CodeQL's interprocedural data flow and taint tracking analysis.

    trailofbits/skills★ 8.3k

See all software development skills →

More skills from huggingface

  1. Huggingface Papers

    Official

    Look up and read Hugging Face paper pages in markdown, and use the papers API for structured metadata such as authors, linked…

    huggingface/skills★ 11k
  2. Hf Cli

    Official

    Hugging Face Hub CLI (`hf`) for downloading, uploading, and managing models, datasets, spaces, buckets, repos, papers, jobs, and more on…

    huggingface/skills★ 11k
  3. Hf Cloud Aws Context Discovery

    Official

    Discover the user's local AWS context (active profile, region, account ID, caller identity) at the start of any AWS task.

    huggingface/skills★ 11k

All skills by huggingface →

Give your whole team an AI agent with skills

Cody runs managed AI agents your team can message in Slack, Teams, WhatsApp and the web, with 50+ business integrations, scheduled tasks and memory. No terminal required.