Agent Native

trl-training

This skill enables agents to post-train large language models using TRL (Transformers Reinforcement Learning) library, supporting supervised fine-tuning…

by Hugging FaceOfficial publisherNot reviewed

Identity proven by GitHub's verified organisation badge (huggingface)

Agents
Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode, claude.ai and API
License
Apache-2.0 (permissive)
Pin
c3ff942pinned Oct 9, 2026
Context cost
about 990 tokenswhen the skill loads
GitHub stars
11,150on huggingface/skills
Scripts
None found

What it does

“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.”
The author's description, from SKILL.md

Generated summary from the skill's own text

This skill enables agents to post-train large language models using TRL (Transformers Reinforcement Learning) library, supporting supervised fine-tuning, preference optimization, and online reinforcement learning methods. The agent can write and debug training code using TRL's Trainer classes and configuration system, with support for multiple dataset formats and optimization techniques like LoRA and Flash Attention.

When to use it

  • Implementing supervised fine-tuning or preference-based model training pipelines
  • Debugging TRL trainer configurations and dataset format issues
  • Setting up online reinforcement learning with reward functions and vLLM
  • Training reward models or using experimental training algorithms

When not to

  • Inferencing or deploying already-trained models in production
  • Training models without access to appropriate datasets or compute resources

Install

These commands install from the publisher's repository and need no account.

skills CLI

npx skills add huggingface/skills --skill trl-training

Installs from the repository's default branch, which may have changed since the commit we checked.

GitHub CLI 2.90 or later

gh skill install huggingface/skills trl-training@c3ff942be3e07116b475253f0a8fc4f54682c1a8

Installs the commit we checked (c3ff942).

Copy by hand

Download the folder at c3ff942 and put it in .claude/skills/trl-training for Claude Code and in .agents/skills/trl-training for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode.

Skill folder on GitHub at c3ff942

Claude Code plugin

/plugin install huggingface-skills@claude-plugins-official

The publisher's plugin in Claude's official marketplace. It may hold more than this skill, and we have not pinned it.

Copy for your agent

A prompt for any coding agent. It installs this skill from GitHub at the pinned commit, copies the files as they are, and runs nothing unless you ask.

Prompt

Install the agent skill "trl-training" by Hugging Face.

Source, pinned to commit c3ff942be3e07116b475253f0a8fc4f54682c1a8:
https://github.com/huggingface/skills/tree/c3ff942be3e07116b475253f0a8fc4f54682c1a8/skills/trl-training

1. Download that folder at exactly this commit. Do not use the default branch.
2. Copy every file unchanged, keeping the folder structure, into .claude/skills/trl-training/ for Claude Code and .agents/skills/trl-training/ for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode. Create the folders if they do not exist.
3. Do not edit the files, and do not run any script in the folder unless I ask you to.
4. When you are done, list the files you copied and where you put them.

Listing and checks: https://www.agentnative.dev/skills/hugging-face/trl-training

SKILL.md at the pin

---
name: trl-training
description: 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.
license: Apache-2.0
metadata:
  author: huggingface
  documentation: https://huggingface.co/docs/trl
---

# 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.

| Trainer | Dataset type |
|---|---|
| `SFTTrainer` | language modeling or prompt-completion |
| `DPOTrainer` | preference (chosen/rejected pairs) |
| `GRPOTrainer` | prompt-only + reward function(s) |
| `DistillationTrainer` | prompt-only + a teacher model (on-policy distillation) |
| `KTOTrainer` | unpaired preference (per-sample bool label) |
| `RewardTrainer` | preference (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

```python
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

```python
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

```python
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`).

From huggingface/skills at c3ff942, shown as plain text under its license: Apache-2.0 (permissive). The license text is in skills/trl-training/SKILL.md.

View SKILL.md on GitHub at c3ff942

Files

1 file, 4.3 KB in total. Each file has a sha256 in the pin's manifest; the first 12 characters are shown.

Skill folder on GitHub at c3ff942

More from Hugging Face

  • hf-cloud-aws-context-discovery

    This skill reads the user's local AWS configuration to discover their active profile, region, account ID, and caller identity before any AWS work begins.

    Claude Code, Codex, Cursor +4 · about 830 tokens · pinned 6 days ago

  • hf-cloud-python-env-setup

    Sets up an isolated Python environment for SageMaker and AWS work with the correct Python version (3.10, 3.11, or 3.12) and current boto3 and awscli.

    Contains scripts

    Claude Code, Codex, Cursor +3 · about 1.5K tokens · pinned 6 days ago

  • hf-cloud-sagemaker-deployment-planner

    This skill helps users plan and execute deployments of machine learning models to Amazon SageMaker by gathering requirements, selecting appropriate deployment…

    Claude Code, Codex, Cursor +4 · about 1.9K tokens · pinned 6 days ago

  • hf-cloud-sagemaker-iam-preflight

    This skill validates or creates an AWS IAM execution role before deploying SageMaker endpoints, training jobs, or models.

    Contains scripts

    Claude Code, Codex, Cursor +3 · about 1.6K tokens · pinned 6 days ago

  • hf-cloud-sagemaker-production-defaults

    Deploys SageMaker endpoints with production defaults: autoscaling based on traffic, CloudWatch alarms for latency and errors, and consistent tagging.

    Contains scripts

    Claude Code, Codex, Cursor +3 · about 6.7K tokens · pinned 6 days ago

  • hf-cloud-serving-image-selection

    This skill helps select the correct SageMaker serving container image for model deployments and retrieves its current URI from AWS's Deep Learning Containers…

    Contains scripts

    Claude Code, Codex, Cursor +3 · about 4.3K tokens · pinned 6 days ago

All AI and agents skills
  • mcp-builder

    This skill guides agents through building Model Context Protocol (MCP) servers that connect LLMs to external services via well-designed tools.

    by SnykOfficial publisher

    Contains scripts

    Claude Code, Codex, Cursor +3 · about 2.2K tokens · pinned 6 days ago

  • claude-settings-audit

    This skill analyzes a repository to detect its tech stack, build tools, and service integrations, then generates recommended Claude Code settings.json…

    by SentryOfficial publisher

    Claude Code · about 2.9K tokens · pinned 6 days ago

  • agents

    Build voice AI agents with natural conversation capabilities using ElevenLabs platform.

    by ElevenLabsOfficial publisher

    Contains scripts

    Claude Code, Codex, Cursor +3 · about 6.4K tokens · pinned 6 days ago

  • agent-observability-eval-bootstrap

    Generates evaluators from production LLM traces by analyzing patterns and quality dimensions.

    by DatadogOfficial publisher

    Claude Code · about 24.5K tokens · pinned 6 days ago

  • iris-development

    This skill integrates with Redis Agent Memory, a managed service on Redis Cloud that provides persistent memory for AI agents.

    by RedisOfficial publisher

    Claude Code, Codex, Cursor +4 · about 970 tokens · pinned 6 days ago

  • Letta Conversations API

    Enables managing multiple isolated message threads on a single Letta agent through the Conversations API.

    by LettaOfficial publisher

    Contains scripts

    Claude Code, Codex, Cursor +3 · about 1.6K tokens · pinned 6 days ago

Open roles at Hugging Face

The skills listed here are third-party software, collected from public GitHub repositories as a catalog of recent skills and provided as is. Agent Native does not write or control them and is not responsible for any harm, loss or damage caused by installing or using them. Labels and checks describe what we saw at one commit and are not a guarantee. Read a skill's files before you run it. Terms of use