huggingface-llm-trainer
它能做什么
这个技能在云端 GPU 上训练或微调 AI 语言模型。适合希望为自己的用途定制模型、又不想自行搭建本地 GPU 的人。
适用场景
- ✓当你想用自己的数据集微调语言模型时。
- ✓当你想使用 SFT、DPO、GRPO 或奖励建模等方法进行训练的时候。
- ✓当你想把训练好的模型转换为 GGUF 以便本地使用的时候。
技能链接
https://github.com/huggingface/skills/blob/main/skills/huggingface-llm-trainer/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请用我的客服示例微调一个小型语言模型,并把结果保存到我的 Hugging Face 账户。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会准备并检查数据集,选择硬件并估算成本。然后它编写训练脚本,在 Hugging Face Jobs 上运行,训练完成后把模型保存到 Hub。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
TRL Training on Hugging Face Jobs
Overview
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.
TRL provides multiple training methods:
- SFT (Supervised Fine-Tuning) - Standard instruction tuning
- DPO (Direct Preference Optimization) - Alignment from preference data
- GRPO (Group Relative Policy Optimization) - Online RL training
- Reward Modeling - Train reward models for RLHF
For detailed TRL method documentation:
hf_doc_search("your query", product="trl")
hf_doc_fetch("https://huggingface.co/docs/trl/sft_trainer") # SFT
hf_doc_fetch("https://huggingface.co/docs/trl/dpo_trainer") # DPO
# etc.
See also: references/training_methods.md for method overviews and selection guidance
When to Use This Skill
Use this skill when users want to:
- Fine-tune language models on cloud GPUs without local infrastructure
- Train with TRL methods (SFT, DPO, GRPO, etc.)
- Run training jobs on Hugging Face Jobs infrastructure
- Convert trained models to GGUF for local deployment (Ollama, LM Studio, llama.cpp)
- Ensure trained models are permanently saved to the Hub
- Use modern workflows with optimized defaults
When to Use Unsloth
Use Unsloth (references/unsloth.md) instead of standard TRL when:
- Limited GPU memory - Unsloth uses ~60% less VRAM
- Speed matters - Unsloth is ~2x faster
- Training large models (>13B) - memory efficiency is critical
- Training Vision-Language Models (VLMs) - Unsloth has
FastVisionModelsupport
See references/unsloth.md for complete Unsloth documentation and scripts/unsloth_sft_example.py for a production-ready training script.
Key Directives
When assisting with training jobs:
ALWAYS use
hf_jobs()MCP tool - Submit jobs usinghf_jobs("uv", {...}), NOT bashtrl-jobscommands. Thescriptparameter accepts Python code directly. Do NOT save to local files unless the user explicitly requests it. Pass the script content as a string tohf_jobs(). If user asks to "train a model", "fine-tune", or similar requests, you MUST create the training script AND submit the job immediately usinghf_jobs().Always include Trackio - Every training script should include Trackio for real-time monitoring. Use example scripts in
scripts/as templates.Provide job details after submission - After submitting, provide job ID, monitoring URL, estimated time, and note that the user can request status checks later.
Use example scripts as templates - Reference
scripts/train_sft_example.py,scripts/train_dpo_example.py, etc. as starting points.
Local Script Execution
Repository scripts use PEP 723 inline dependencies. Run them with uv run:
uv run scripts/estimate_cost.py --help
uv run scripts/dataset_inspector.py --help
Prerequisites Checklist
Before starting any training job, verify:
✅ Account & Authentication
- Hugging Face Account with Pro, Team, or Enterprise plan (Jobs require paid plan)
- Authenticated login: Check with
hf_whoami() - HF_TOKEN for Hub Push ⚠️ CRITICAL - Training environment is ephemeral, must push to Hub or ALL training results are lost
- Token must have write permissions
- MUST pass
secrets={"HF_TOKEN": "$HF_TOKEN"}in job config to make token available (the$HF_TOKENsyntax references your actual token value)
✅ Dataset Requirements
- Dataset must exist on Hub or be loadable via
datasets.load_dataset() - Format must match training method (SFT: "messages"/text/prompt-completion; DPO: chosen/rejected; GRPO: prompt-only)
- ALWAYS validate unknown datasets before GPU training to prevent format failures (see Dataset Validation section below)
- Size appropriate for hardware (Demo: 50-100 examples on t4-small; Production: 1K-10K+ on a10g-large/a100-large)
⚠️ Critical Settings
- 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.
- Hub push must be enabled - Config:
push_to_hub=True,hub_model_id="username/model-name"; Job:secrets={"HF_TOKEN": "$HF_TOKEN"}
Asynchronous Job Guidelines
**⚠️ IMPORTANT: Traini
常见问题
我需要本地 GPU 吗?
不需要。训练在托管的云端 GPU 上运行,因此无需设置本地 GPU。
训练好的模型会保留吗?
会。结果会自动保存到 Hugging Face Hub。
它会估算成本吗?
会。估算成本是选择训练任务硬件的一部分。
详情
作者的原始描述
Train 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 package, UV scripts with PEP 723 format, dataset preparation and validation, hardware selection, cost estimation, Trackio monitoring, Hub authentication, model selection/leaderboards and model persistence. Use for tasks involving cloud GPU training, GGUF conversion, or when users mention training on Hugging Face Jobs w
repo: huggingface/skills
热度
- GitHub 星标
- 11k
- 排名
- #11774
- 许可证
- Apache-2.0
- 更新时间
- 2026/10/30
评论
- …
同一仓库的更多技能
hf-cli
11k帮你的智能体使用 Hugging Face 命令行工具,下载、上传和管理模型、数据集、Spaces、仓库以及本地缓存。
hf-cloud-aws-context-discovery
11k帮你的智能体在进行任何云端工作之前,找到你的 AWS 配置文件、区域和账户信息,避免猜测该使用哪个账户。
hf-cloud-python-env-setup
11k帮你的智能体设置一个干净的 Python 环境,使用合适的 Python 版本和最新的库,然后再运行 SageMaker 或 AWS 自动化脚本。
hf-cloud-sagemaker-deployment-planner
11k帮你的智能体规划如何把模型部署到 Amazon SageMaker,在实时、无服务器、异步或批量托管之间进行选择,并使用合理的默认设置。