$npx -y skills add huggingface/skills --skill huggingface-llm-trainerTrain or fine-tune language and vision models using TRL (Transformer Reinforcement Learning) or Unsloth with Hugging Face Jobs infrastructure. Covers SFT, DPO, GRPO and reward modeling training methods, plus GGUF conversion for local deployment. Includes guidance on the TRL Jobs
| 1 | # TRL Training on Hugging Face Jobs |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Train language models using TRL (Transformer Reinforcement Learning) on fully managed Hugging Face infrastructure. No local GPU setup required—models train on cloud GPUs and results are automatically saved to the Hugging Face Hub. |
| 6 | |
| 7 | **TRL provides multiple training methods:** |
| 8 | - **SFT** (Supervised Fine-Tuning) - Standard instruction tuning |
| 9 | - **DPO** (Direct Preference Optimization) - Alignment from preference data |
| 10 | - **GRPO** (Group Relative Policy Optimization) - Online RL training |
| 11 | - **Reward Modeling** - Train reward models for RLHF |
| 12 | |
| 13 | **For detailed TRL method documentation:** |
| 14 | ```python |
| 15 | hf_doc_search("your query", product="trl") |
| 16 | hf_doc_fetch("https://huggingface.co/docs/trl/sft_trainer") # SFT |
| 17 | hf_doc_fetch("https://huggingface.co/docs/trl/dpo_trainer") # DPO |
| 18 | # etc. |
| 19 | ``` |
| 20 | |
| 21 | **See also:** `references/training_methods.md` for method overviews and selection guidance |
| 22 | |
| 23 | ## When to Use This Skill |
| 24 | |
| 25 | Use this skill when users want to: |
| 26 | - Fine-tune language models on cloud GPUs without local infrastructure |
| 27 | - Train with TRL methods (SFT, DPO, GRPO, etc.) |
| 28 | - Run training jobs on Hugging Face Jobs infrastructure |
| 29 | - Convert trained models to GGUF for local deployment (Ollama, LM Studio, llama.cpp) |
| 30 | - Ensure trained models are permanently saved to the Hub |
| 31 | - Use modern workflows with optimized defaults |
| 32 | |
| 33 | ### When to Use Unsloth |
| 34 | |
| 35 | Use **Unsloth** (`references/unsloth.md`) instead of standard TRL when: |
| 36 | - **Limited GPU memory** - Unsloth uses ~60% less VRAM |
| 37 | - **Speed matters** - Unsloth is ~2x faster |
| 38 | - Training **large models (>13B)** - memory efficiency is critical |
| 39 | - Training **Vision-Language Models (VLMs)** - Unsloth has `FastVisionModel` support |
| 40 | |
| 41 | See `references/unsloth.md` for complete Unsloth documentation and `scripts/unsloth_sft_example.py` for a production-ready training script. |
| 42 | |
| 43 | ## Key Directives |
| 44 | |
| 45 | When assisting with training jobs: |
| 46 | |
| 47 | 1. **ALWAYS use `hf_jobs()` MCP tool** - Submit jobs using `hf_jobs("uv", {...})`, NOT bash `trl-jobs` commands. The `script` parameter accepts Python code directly. Do NOT save to local files unless the user explicitly requests it. Pass the script content as a string to `hf_jobs()`. If user asks to "train a model", "fine-tune", or similar requests, you MUST create the training script AND submit the job immediately using `hf_jobs()`. |
| 48 | |
| 49 | 2. **Always include Trackio** - Every training script should include Trackio for real-time monitoring. Use example scripts in `scripts/` as templates. |
| 50 | |
| 51 | 3. **Provide job details after submission** - After submitting, provide job ID, monitoring URL, estimated time, and note that the user can request status checks later. |
| 52 | |
| 53 | 4. **Use example scripts as templates** - Reference `scripts/train_sft_example.py`, `scripts/train_dpo_example.py`, etc. as starting points. |
| 54 | |
| 55 | ## Local Script Execution |
| 56 | |
| 57 | Repository scripts use PEP 723 inline dependencies. Run them with `uv run`: |
| 58 | ```bash |
| 59 | uv run scripts/estimate_cost.py --help |
| 60 | uv run scripts/dataset_inspector.py --help |
| 61 | ``` |
| 62 | |
| 63 | ## Prerequisites Checklist |
| 64 | |
| 65 | Before starting any training job, verify: |
| 66 | |
| 67 | ### ✅ **Account & Authentication** |
| 68 | - Hugging Face Account with [Pro](https://hf.co/pro), [Team](https://hf.co/enterprise), or [Enterprise](https://hf.co/enterprise) plan (Jobs require paid plan) |
| 69 | - Authenticated login: Check with `hf_whoami()` |
| 70 | - **HF_TOKEN for Hub Push** ⚠️ CRITICAL - Training environment is ephemeral, must push to Hub or ALL training results are lost |
| 71 | - Token must have write permissions |
| 72 | - **MUST pass `secrets={"HF_TOKEN": "$HF_TOKEN"}` in job config** to make token available (the `$HF_TOKEN` syntax |
| 73 | references your actual token value) |
| 74 | |
| 75 | ### ✅ **Dataset Requirements** |
| 76 | - Dataset must exist on Hub or be loadable via `datasets.load_dataset()` |
| 77 | - Format must match training method (SFT: "messages"/text/prompt-completion; DPO: chosen/rejected; GRPO: prompt-only) |
| 78 | - **ALWAYS validate unknown datasets** before GPU training to prevent format failures (see Dataset Validation section below) |
| 79 | - Size appropriate for hardware (Demo: 50-100 examples on t4-small; Production: 1K-10K+ on a10g-large/a100-large) |
| 80 | |
| 81 | ### ⚠️ **Critical Settings** |
| 82 | - **Timeout must exceed expected training time** - Default 30min is TOO SHORT for most training. Minimum recommended: 1-2 hours. Job fails and loses all progress if t |