Huggingface Llm Trainerのロゴ

Huggingface Llm Trainer

コミュニティ
waybarrios
huggingface-llm-trainer

Hugging Face JobsでTRLまたはUnslothを使い、SFT、DPO、GRPO、報酬モデル、GGUF変換などの言語モデルのトレーニングやファインチューニングを行います。クラウドでのLLMトレーニングに使用してください。ビジョンタスクにはhuggingface-vision-trainerを使用してください。

Add to TypingMind

概要

公開者waybarrios
リポジトリopencode-power-pack
スキル名huggingface-llm-trainer
スター
535
フォーク
43
同梱ファイル
18
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 18個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    waybarriosがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Huggingface Llm Trainer」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/waybarrios/opencode-power-pack/tree/main/skills/huggingface-llm-trainer
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/waybarrios/opencode-power-pack.git /tmp/opencode-power-pack
mkdir -p .claude/skills
cp -r /tmp/opencode-power-pack/skills/huggingface-llm-trainer .claude/skills/huggingface-llm-trainer
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでHuggingface Llm Trainerを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にHuggingface Llm Trainerを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Huggingface Llm Trainerは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

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

See references/training_methods.md for method overviews and selection guidance.

When to Use Unsloth

Use Unsloth (references/unsloth.md) instead of standard TRL when GPU memory is limited (~60% less VRAM), speed matters (~2x faster), training large models (>13B), or training Vision-Language Models (Unsloth has FastVisionModel support). See scripts/unsloth_sft_example.py for a production-ready training script.

Key Directives

  1. Submit jobs via hf jobs uv run (CLI) or the hf_jobs() MCP tool if the Hugging Face MCP server is configured — pass the training script inline, don't save to a local file unless the user explicitly requests it. If the user asks to "train a model" or "fine-tune", create the training script AND submit the job immediately.
  2. Always include Trackio for real-time monitoring — use scripts/ templates.
  3. Provide job details after submission: job ID, monitoring URL, estimated time; note the user can request status checks later.
  4. Use example scripts as templates: scripts/train_sft_example.py, scripts/train_dpo_example.py, etc.

Local Script Execution

Repository scripts use PEP 723 inline dependencies. Run them with uv run:

bash
uv run scripts/estimate_cost.py --help
uv run scripts/dataset_inspector.py --help

Prerequisites Checklist

Account & Authentication:

  • Hugging Face account with Pro/Team/Enterprise plan (Jobs require a paid plan); authenticated login.
  • HF_TOKEN for Hub push is CRITICAL — the training environment is ephemeral, so results are lost unless pushed to the Hub. Token must have write permissions. Pass secrets={"HF_TOKEN": "$HF_TOKEN"} in the job config.

Dataset Requirements:

  • Must exist on the Hub or be loadable via datasets.load_dataset().
  • Format must match the training method (SFT: messages/text/prompt-completion; DPO: chosen/rejected; GRPO: prompt-only). Always validate unknown datasets first (see Dataset Validation 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; minimum recommended 1-2 hours. The job fails and loses all progress if the timeout is exceeded.
  • Hub push must be enabled: push_to_hub=True, hub_model_id="username/model-name", secrets={"HF_TOKEN": "$HF_TOKEN"}.

Asynchronous Jobs

Training jobs run in the background and can take hours. After submitting: report the job ID, monitoring URL, and estimated time; wait for the user to request status checks rather than polling. Initial logs can take 30-60 seconds to appear.

Quick Start

Sequence length: TRL config classes use max_length (not max_seq_length). Default is max_length=1024 (truncates from right) — override higher for longer context, lower under memory constraints, or None for vision models (to avoid cutting image tokens).

Approach 1: UV Scripts (default choice)

UV scripts use PEP 723 inline dependencies for clean, self-contained training:

python
hf_jobs("uv", {
    "script": """
# /// script
# dependencies = ["trl>=0.12.0", "peft>=0.7.0", "trackio"]
# ///
from datasets import load_dataset
from peft import LoraConfig
from trl import SFTTrainer, SFTConfig
import trackio

dataset = load_dataset("trl-lib/Capybara", split="train")
dataset_split = dataset.train_test_split(test_size=0.1, seed=42)

trainer = SFTTrainer(
    model="Qwen/Qwen2.5-0.5B",
    train_dataset=dataset_split["train"],
    eval_dataset=dataset_split["test"],
    peft_config=LoraConfig(r=16, lora_alpha=32),
    args=SFTConfig(
        output_dir="my-model", push_to_hub=True, hub_model_id="username/my-model",
        num_train_epochs=3, eval_strategy="steps", eval_steps=50,
        report_to="trackio", project="my_project", run_name="my_run",
    ),
)
trainer.train()
trainer.push_to_hub()
""",
    "flavor": "a10g-large",
    "timeout": "2h",
    "secrets": {"HF_TOKEN": "$HF_TOKEN"},
})

The script parameter accepts inline code or a publicly-accessible/Hub/GitHub/Gist URL — local file paths do not work (jobs run in isolated containers with no access to the local filesystem). To use a local script, upload it to the Hub first (hf upload ...) and reference its resolved URL.

Approach 2: TRL Maintained Scripts

Run TRL's battle-tested example scripts directly from a URL, passing CLI-style script_args (--model_name_or_path, --dataset_name, --output_dir, --push_to_hub, --hub_model_id). Available at https://github.com/huggingface/trl/tree/main/examples/scripts.

Approach 3: HF Jobs CLI

When no hf_jobs-style tool is available, use the hf jobs CLI directly. Flags must come before the script URL, the subcommand order is hf jobs uv run (not run uv), and use --secrets (plural):

bash
hf jobs uv run \
  --flavor a10g-large --timeout 2h --secrets HF_TOKEN \
  "https://huggingface.co/user/repo/resolve/main/train.py"

Check status: hf jobs ps, hf jobs logs <job-id>, hf jobs inspect <job-id>, hf jobs cancel <job-id>.

Approach 4: TRL Jobs Package

uvx trl-jobs sft --model_name Qwen/Qwen2.5-0.5B --dataset_name trl-lib/Capybara gives pre-configured defaults, automatic Trackio integration, and automatic Hub push — best for terminal-only, quick local experimentation. Repository: https://github.com/huggingface/trl-jobs.

Hardware Selection

Model SizeRecommended HardwareCost (approx/hr)
<1B paramst4-small~$0.75
1-3B paramst4-medium, l4x1~$1.50-2.50
3-7B paramsa10g-small, a10g-large~$3.50-5.00
7-13B paramsa10g-large, a100-large (LoRA)~$5-10
13B+ paramsa100-large, a10g-largex2 (LoRA)~$10-20

Use LoRA/PEFT for models >7B; multi-GPU is handled automatically by TRL/Accelerate. See references/hardware_guide.md for full specs.

Saving Results to the Hub

The Jobs environment is ephemeral — everything is deleted when the job ends. Set push_to_hub=True and hub_model_id="username/model-name" in the training config, and pass secrets={"HF_TOKEN": "$HF_TOKEN"} in the job submission. See references/hub_saving.md for troubleshooting.

Timeout Management

Default is 30 minutes — too short for real training. Set explicitly ("timeout": "2h", formats: "90m", "2h", seconds as integer) with a 20-30% buffer for loading/checkpointing/Hub push. Guideline: quick demo 10-30min, development 1-2h, production (3-7B) 4-6h. On timeout the job is killed immediately and unsaved progress is lost.

Choosing a Base Model

Use scripts/hf_benchmarks.py to find top-performing models for a task, keeping size/hardware constraints in mind: uv run scripts/hf_benchmarks.py search --query ocr then uv run scripts/hf_benchmarks.py leaderboard <benchmark-id>.

Cost Estimation

Offer to estimate cost when parameters are known (hardware, dataset size, epochs), with scripts/estimate_cost.py:

bash
uv run scripts/estimate_cost.py --model meta-llama/Llama-2-7b-hf --dataset trl-lib/Capybara --hardware a10g-large --dataset-size 16000 --epochs 3

Example Training Scripts

Production-ready templates: scripts/train_sft_example.py, scripts/train_dpo_example.py, scripts/train_grpo_example.py, scripts/unsloth_sft_example.py (Unsloth, faster/less VRAM). Pass their content inline or use as templates.

Monitoring with Trackio

Add trackio to dependencies and configure report_to="trackio", run_name="meaningful_name". Defaults: space ID {username}/trackio, minimal config (hyperparameters + model/dataset info), a Project Name to group runs. Apply the user's preferences instead when specified. See references/trackio_guide.md for grouping runs across experiments.

Dataset Validation

Validate BEFORE launching GPU training — 50%+ of training failures are format mismatches, and DPO is especially strict about column names (prompt, chosen, rejected). Validation on CPU costs ~$0.01 and takes <1 minute vs. wasting $1-10 and 30-60 minutes on a failed GPU job.

Always validate unknown/custom datasets and any DPO dataset; skip validation only for well-known TRL datasets (trl-lib/ultrachat_200k, trl-lib/Capybara, etc.). Use the Hub-hosted dataset inspector script (--dataset name --split train); output markers are ✓ READY, ✗ NEEDS MAPPING (includes copy-paste mapping code), or ✗ INCOMPATIBLE.

Converting Models to GGUF

Convert trained models to GGUF for llama.cpp/Ollama/LM Studio/local inference — supports 4/5/8-bit quantization, typically 2-8GB for 7B models vs. 14GB unquantized. See references/gguf_conversion.md for the complete conversion script, quantization options, and troubleshooting.

Common Training Patterns

See references/training_patterns.md: quick demo, production with checkpoints, multi-GPU, DPO, GRPO.

Common Failure Modes

  • Out of memory: reduce per_device_train_batch_size (increase gradient_accumulation_steps to compensate, target effective batch size ~128), enable gradient_checkpointing=True, or upgrade hardware.
  • Dataset misformatted: validate first with the dataset inspector, apply the suggested mapping code.
  • Job timeout: check actual runtime via logs, increase timeout with a 30% buffer, or reduce num_train_epochs/dataset size; save checkpoints (save_strategy="steps", hub_strategy="every_save") so partial progress survives.
  • Hub push failures: confirm secrets={"HF_TOKEN": "$HF_TOKEN"}, push_to_hub=True, hub_model_id, write permissions, and that the target repo exists (or hub_private_repo=True).
  • Missing dependencies: add them to the PEP 723 header.

See references/troubleshooting.md for the complete guide.

Resources

References: references/training_methods.md, training_patterns.md, unsloth.md, gguf_conversion.md, trackio_guide.md, hardware_guide.md, hub_saving.md, troubleshooting.md, local_training_macos.md.

Scripts: scripts/train_sft_example.py, train_dpo_example.py, train_grpo_example.py, unsloth_sft_example.py, estimate_cost.py, convert_to_gguf.py, hf_benchmarks.py.

External: TRL docs, TRL Jobs training guide, TRL Jobs package, HF Jobs docs, UV scripts guide.

Key Takeaways

  1. Submit scripts inline — no file saving required unless the user asks.
  2. Jobs are asynchronous — don't poll; let the user check status when ready.
  3. Always set a timeout above the default 30min (1-2h minimum).
  4. Always enable Hub push — the environment is ephemeral.
  5. Include Trackio for real-time monitoring.
  6. Offer cost estimation when parameters are known.
  7. Default to UV scripts (Approach 1) or the TRL maintained scripts (Approach 2); fall back to the hf jobs CLI (Approach 3) when no job-submission tool is available.
  8. Validate dataset format before training, especially for DPO.
  9. Choose hardware for model size; use LoRA for models >7B.

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Huggingface Llm Trainer」では何ができますか?

Hugging Face JobsでTRLまたはUnslothを使い、SFT、DPO、GRPO、報酬モデル、GGUF変換などの言語モデルのトレーニングやファインチューニングを行います。クラウドでのLLMトレーニングに使用してください。ビジョンタスクにはhuggingface-vision-trainerを使用してください。

TypingMindでHuggingface Llm Trainerを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Huggingface Llm Trainerはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにHuggingface Llm Trainerをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/waybarrios/opencode-power-pack/tree/main/skills/huggingface-llm-trainerを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Huggingface Llm Trainerを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Huggingface Llm Trainerで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもHuggingface Llm Trainerを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Huggingface Llm Trainer」は無料ですか?

はい。waybarriosがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇