> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-sdk-testing-latest.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Hugging Face AutoTrain

> 1つのCLIパラメーターで、コード不要のモデル トレーニング向けに Hugging Face AutoTrain で W&B の実験管理を使用できます。

[Hugging Face AutoTrain](https://huggingface.co/docs/autotrain/index) は、自然言語処理 (NLP) タスク、コンピュータービジョン (CV) タスク、音声タスク、さらに表形式データのタスク向けに、最先端のモデルをトレーニングするためのコード不要のツールです。

[W\&B](https://wandb.com/) は Hugging Face AutoTrain に直接統合されており、実験管理と設定管理を利用できます。CLI コマンドで1つのパラメーターを指定するだけで、実験で簡単に使用できます。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-sdk-testing-latest/5BwwFpNAnQO_33rW/images/integrations/hf-autotrain-1.png?fit=max&auto=format&n=5BwwFpNAnQO_33rW&q=85&s=0b619351888f62d91e2a1dde7861ddca" alt="実験メトリクスのログ" width="2880" height="1630" data-path="images/integrations/hf-autotrain-1.png" />
</Frame>

<div id="install-prerequisites">
  ## 前提条件をインストールする
</div>

`autotrain-advanced` と `wandb` をインストールします。

<Tabs>
  <Tab title="コマンドライン">
    ```shell theme={null}
    pip install --upgrade autotrain-advanced wandb
    ```
  </Tab>

  <Tab title="ノートブック">
    ```notebook theme={null}
    !pip install --upgrade autotrain-advanced wandb
    ```
  </Tab>
</Tabs>

これらの変更点を示すため、このページでは数学データセットで LLM をファインチューニングし、[GSM8k Benchmarks](https://github.com/openai/grade-school-math) の `pass@1` で SoTA の結果を達成します。

<div id="prepare-the-dataset">
  ## データセットを準備する
</div>

Hugging Face AutoTrain で正しく動作させるには、CSV のカスタムデータセットを特定の形式にする必要があります。

* トレーニングファイルには、トレーニングで使用する `text` 列が含まれている必要があります。最適な結果を得るには、`text` 列のデータを `### Human: Question?### Assistant: Answer.` 形式に従わせる必要があります。優れた例として、[`timdettmers/openassistant-guanaco`](https://huggingface.co/datasets/timdettmers/openassistant-guanaco) を参照してください。

  ただし、[MetaMathQA dataset](https://huggingface.co/datasets/meta-math/MetaMathQA) には `query`、`response`、`type` の各列が含まれています。まず、このデータセットを前処理します。`type` 列を削除し、`query` 列と `response` 列の内容を結合して、`### Human: Query?### Assistant: Response.` 形式の新しい `text` 列を作成してください。トレーニングには、こうして作成したデータセット [`rishiraj/guanaco-style-metamath`](https://huggingface.co/datasets/rishiraj/guanaco-style-metamath) を使用します。

<div id="train-using-autotrain">
  ## `autotrain` を使用してトレーニングする
</div>

コマンドラインまたはノートブックから `autotrain` advanced を使用してトレーニングを開始できます。`--log` 引数を使用するか、`--log wandb` を使用して結果を [W\&B Run](/ja/models/runs/) にログできます。

<Tabs>
  <Tab title="コマンドライン">
    ```shell theme={null}
    autotrain llm \
        --train \
        --model HuggingFaceH4/zephyr-7b-alpha \
        --project-name zephyr-math \
        --log wandb \
        --data-path data/ \
        --text-column text \
        --lr 2e-5 \
        --batch-size 4 \
        --epochs 3 \
        --block-size 1024 \
        --warmup-ratio 0.03 \
        --lora-r 16 \
        --lora-alpha 32 \
        --lora-dropout 0.05 \
        --weight-decay 0.0 \
        --gradient-accumulation 4 \
        --logging_steps 10 \
        --fp16 \
        --use-peft \
        --use-int4 \
        --merge-adapter \
        --push-to-hub \
        --token <huggingface-token> \
        --repo-id <huggingface-repository-address>
    ```
  </Tab>

  <Tab title="ノートブック">
    ```notebook theme={null}
    # ハイパーパラメーターを設定
    learning_rate = 2e-5
    num_epochs = 3
    batch_size = 4
    block_size = 1024
    trainer = "sft"
    warmup_ratio = 0.03
    weight_decay = 0.
    gradient_accumulation = 4
    lora_r = 16
    lora_alpha = 32
    lora_dropout = 0.05
    logging_steps = 10

    # トレーニングを実行
    !autotrain llm \
        --train \
        --model "HuggingFaceH4/zephyr-7b-alpha" \
        --project-name "zephyr-math" \
        --log "wandb" \
        --data-path data/ \
        --text-column text \
        --lr str(learning_rate) \
        --batch-size str(batch_size) \
        --epochs str(num_epochs) \
        --block-size str(block_size) \
        --warmup-ratio str(warmup_ratio) \
        --lora-r str(lora_r) \
        --lora-alpha str(lora_alpha) \
        --lora-dropout str(lora_dropout) \
        --weight-decay str(weight_decay) \
        --gradient-accumulation str(gradient_accumulation) \
        --logging-steps str(logging_steps) \
        --fp16 \
        --use-peft \
        --use-int4 \
        --merge-adapter \
        --push-to-hub \
        --token str(hf_token) \
        --repo-id "rishiraj/zephyr-math"
    ```
  </Tab>
</Tabs>

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-sdk-testing-latest/5BwwFpNAnQO_33rW/images/integrations/hf-autotrain-2.gif?s=7b689e6f30be0f74a47a18c37d8793f8" alt="実験設定の保存" width="800" height="910" data-path="images/integrations/hf-autotrain-2.gif" />
</Frame>

<div id="more-resources">
  ## 参考資料
</div>

* [AutoTrain Advanced で実験管理がサポートされるようになりました](https://huggingface.co/blog/rishiraj/log-autotrain) ([Rishiraj Acharya](https://huggingface.co/rishiraj) 著)
* [Hugging Face AutoTrain ドキュメント](https://huggingface.co/docs/autotrain/index)
