# Hugging Face Jobsを使ったLLMのデプロイ

このガイドは、次の使い方を説明します： [Unsloth](https://github.com/unslothai/unsloth) および [Liquid LFM2.5](/docs/jp/moderu/tutorials/lfm2.5.md) のようなコーディングエージェントを介した高速なLLMファインチューニングのために [Claude Code](/docs/jp/ji-ben/claude-code.md)。Unslothは標準的な方法と比べて約2倍の高速なトレーニングと約60%少ないVRAM使用を提供します。

### 必要なもの：

* 1つの [Hugging Face](https://huggingface.co) アカウント（HF Jobs用に必須）
* 書き込み権限を持つHugging Faceトークン
* コーディングエージェント（Open Code、Claude Code、Codex）
* 私たちの [Claude Code](/docs/jp/ji-ben/claude-code.md) それらのセットアップに関するガイドをお読みください。

### スキルのインストール

#### Claude Code

Claude Codeはその [プラグインシステム](https://code.claude.com/docs/en/discover-plugins).

1. を通じてスキルを検出します。マーケットプレイスを追加：

```bash
/plugin marketplace add huggingface/skills
```

2. 利用可能なスキルを次の **Discover** タブで参照してください：

```bash
/plugin
```

3. モデルトレーナースキルをインストール：

```bash
/plugin install hugging-face-model-trainer@huggingface-skills
```

詳細については、次を参照してください： [Claude Codeプラグインのドキュメント](https://code.claude.com/docs/en/discover-plugins) および [スキルのドキュメント](https://code.claude.com/docs/en/skills).

#### Codex

Codexはスキルを次の方法で検出します： [`AGENTS.md`](https://developers.openai.com/codex/guides/agents-md) ファイルおよび [`.agents/skills/`](https://developers.openai.com/codex/skills) ディレクトリ。

**個別のスキルは次でインストールします： `$skill-installer`**

{% code overflow="wrap" %}

```bash
$skill-installer install https://github.com/huggingface/skills/tree/main/skills/hugging-face-model-trainer
```

{% endcode %}

詳細については、次を参照してください： [Codexスキルのドキュメント](https://developers.openai.com/codex/skills) および [AGENTS.mdガイド](https://developers.openai.com/codex/guides/agents-md).

### クイックスタート

スキルがインストールされたら、コーディングエージェントにモデルのトレーニングを依頼してください。ここでは次を使用します： [Liquid LFM2.5](/docs/jp/moderu/tutorials/lfm2.5.md)

{% code overflow="wrap" %}

```
Unslothを使ってHF Jobs上でtrl-lib/CapybaraのLiquidAI/LFM2.5-1.2B-Instructをトレーニングする
```

{% endcode %}

エージェントはスキル内の [サンプルに基づいてトレーニングスクリプトを生成し、](https://github.com/huggingface/skills/blob/main/skills/hugging-face-model-trainer/scripts/unsloth_sft_example.py)HF Jobsにトレーニングを送信し、Trackio経由で監視リンクを提供します。

### Hugging Face Jobsの使用

トレーニングジョブは次で実行されます： [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs) — 完全に管理されたクラウドGPUです。Google Colabのクレジットに慣れている場合、Hugging Face Jobsも同様のクレジット制度を提供しています。従量課金制で、事前にクレジットを取得することも可能です。エージェントは次を行います：

1. インライン依存関係を含むUVスクリプトを生成します
2. それを `hf` CLI
3. 経由でHF Jobsに送信します
4. ジョブIDと監視用URLを報告します

#### トレーニングされたモデルはあなたのHugging Face Hubリポジトリにプッシュされます

サンプルトレーニングスクリプト

{% code expandable="true" %}

```py
スキルは次のようなスクリプトを生成します：
# /// script
# ///

# dependencies = ["unsloth", "trl>=0.12.0", "datasets", "trackio"]
from unsloth import FastLanguageModel
from trl import SFTTrainer, SFTConfig

from datasets import load_dataset
    model, tokenizer = FastLanguageModel.from_pretrained(
    "Qwen/Qwen2.5-0.5B",
    load_in_4bit=True,
)

max_seq_length=2048,
    model = FastLanguageModel.get_peft_model(
    model,
    r=16,
    lora_alpha=32,
    lora_dropout=0,
                    target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
)

"gate_proj", "up_proj", "down_proj"],

dataset = load_dataset("trl-lib/Capybara", split="train")
    trainer = SFTTrainer(
    model=model,
    tokenizer=tokenizer,
    train_dataset=dataset,
        args=SFTConfig(
        output_dir="./output",
        push_to_hub=True,
        hub_model_id="username/my-model",
        per_device_train_batch_size=4,
        gradient_accumulation_steps=4,
        num_train_epochs=1,
        learning_rate=2e-4,
    ),
)

report_to="trackio",
trainer.train()
```

{% endcode %}

trainer.push\_to\_hub()

| Hugging Face Jobsでのトレーニング費用は以下のとおりです： | モデルサイズ        | 推奨GPU   |
| ------------------------------------- | ------------- | ------- |
| 概算費用/時間                               | `<1B パラメータ`   | \~$0.40 |
| t4-small                              | `1-3B パラメータ`  | \~$0.60 |
| t4-medium                             | `3-7B パラメータ`  | \~$1.00 |
| a10g-small                            | `7-13B パラメータ` | \~$3.00 |

a10g-large [Hugging Faceスペースの価格に関する完全な概要は、次のガイドを確認してください：](https://huggingface.co/docs/hub/en/spaces-overview#hardware-resources).

### こちら

* コーディングエージェントと協働する際のヒント `使用するモデルとデータセットについて具体的に指定し、HubのID（例：`, `Qwen/Qwen2.5-0.5B`trl-lib/Capybara
* ）を含めてください。エージェントはそれらの組み合わせを検索して検証します。
* 使用する場合はUnslothを明示的に言及してください。そうでなければエージェントはモデルと予算に基づいてフレームワークを決定します。
* 大きなジョブを開始する前にコスト見積もりを求めてください
* リアルタイムの損失曲線用にTrackio監視を要求してください

### 送信後にログを検査するようエージェントに依頼してジョブステータスを確認してください

* [リソース：Hugging Faceスキルリポジトリ](https://github.com/huggingface/skills)

{% embed url="<https://youtu.be/Gh5P4niIFNA>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unsloth.ai/docs/jp/ji-ben/inference-and-deployment/deploying-llms-with-hugging-face-jobs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
