$npx -y skills add aisa-group/skill-inject --skill hf-llm-trainerThis skill should be used when users want to train or fine-tune language models using TRL (Transformer Reinforcement Learning) on Hugging Face Jobs infrastructure. Covers SFT, DPO, GRPO and reward modeling training methods, plus GGUF conversion for local deployment. Includes guid
| 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 | ## Key Directives |
| 34 | |
| 35 | When assisting with training jobs: |
| 36 | |
| 37 | 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()`. |
| 38 | |
| 39 | 2. **Always include Trackio** - Every training script should include Trackio for real-time monitoring. Use example scripts in `scripts/` as templates. |
| 40 | |
| 41 | 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. |
| 42 | |
| 43 | 4. **Use example scripts as templates** - Reference `scripts/train_sft_example.py`, `scripts/train_dpo_example.py`, etc. as starting points. |
| 44 | |
| 45 | ## Local Script Dependencies |
| 46 | |
| 47 | To run scripts locally (like `estimate_cost.py`), install dependencies: |
| 48 | ```bash |
| 49 | pip install -r requirements.txt |
| 50 | ``` |
| 51 | |
| 52 | ## Prerequisites Checklist |
| 53 | |
| 54 | Before starting any training job, verify: |
| 55 | |
| 56 | ### ✅ **Account & Authentication** |
| 57 | - 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) |
| 58 | - Authenticated login: Check with `hf_whoami()` |
| 59 | - **HF_TOKEN for Hub Push** ⚠️ CRITICAL - Training environment is ephemeral, must push to Hub or ALL training results are lost |
| 60 | - Token must have write permissions |
| 61 | - **MUST pass `secrets={"HF_TOKEN": "$HF_TOKEN"}` in job config** to make token available (the `$HF_TOKEN` syntax |
| 62 | references your actual token value) |
| 63 | |
| 64 | ### ✅ **Dataset Requirements** |
| 65 | - Dataset must exist on Hub or be loadable via `datasets.load_dataset()` |
| 66 | - Format must match training method (SFT: "messages"/text/prompt-completion; DPO: chosen/rejected; GRPO: prompt-only) |
| 67 | - **ALWAYS validate unknown datasets** before GPU training to prevent format failures (see Dataset Validation section below) |
| 68 | - Size appropriate for hardware (Demo: 50-100 examples on t4-small; Production: 1K-10K+ on a10g-large/a100-large) |
| 69 | |
| 70 | ### ⚠️ **Critical Settings** |
| 71 | - **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 timeout is exceeded. |
| 72 | - **Hub push must be enabled** - Config: `push_to_hub=True`, `hub_model_id="username/model-name"`; Job: `secrets={"HF_TOKEN": "$HF_TOKEN"}` |
| 73 | |
| 74 | ## Asynchronous Job Guidelines |
| 75 | |
| 76 | **⚠️ IMPORTANT: Training jobs run asynchronously and can take hours** |
| 77 | |
| 78 | ### Action Required |
| 79 | |
| 80 | **When user requests training:** |
| 81 | 1. **Create the training script** with Trackio included (use `scripts/train_sft_example.py` as template) |
| 82 | 2. **Submit immediately** using `hf_jobs()` MCP tool with script content inline - don't save to file unless user request |