TorchTune でのファインチューニング

Llama 3 のファインチューニング

Francesca Donadoni

Curriculum Manager, DataCamp

TorchTune のファインチューニング構成要素

  • モデル

    • 微調整するアーキテクチャと事前学習済み重みを定義
    • バージョンやパラメータ数が異なる
  • データセット

    • 学習に用いるデータを指定
  • レシピ

    • モデル、データセット、学習パラメータをまとめる中央設定
    • 一貫性と再現性を担保

iStock-2151073200.jpg

iStock-1281282682.jpg

iStock-2173849278.jpg

Llama 3 のファインチューニング

TorchTune のファインチューニング構成要素

  • モデル

    • !tune ls
      llama3/8B_full
      llama3_1/8B_full
      llama3_2/1B_full ...
      
  • データセット

    • ds.save_to_disk("new_dataset")
  • レシピ

    • custom_recipe.yaml

iStock-2151073200.jpg

iStock-1281282682.jpg

iStock-2173849278.jpg

Llama 3 のファインチューニング

TorchTune レシピの構成要素

  • 全般設定と出力先
    • バッチサイズ、デバイス、エポック

 

  • モデル
    • アーキテクチャとモデル設定を指定

 

  • オプティマイザ

    • 学習率など
  • データセット

    • 前処理とパスを定義
batch_size: 4
device: cuda
epochs: 20
output_dir: /tmp/full-llama3.2-finetune

model:
  _component_: 
      torchtune.models.llama3_2.llama3_2_1b

optimizer:
  _component_: bitsandbytes.optim.PagedAdamW8bit
  lr: 2.0e-05

dataset:
  _component_: torchtune.datasets.alpaca_dataset
Llama 3 のファインチューニング

TorchTune レシピの設定

  • 利用可能なパラメータが増加
  • yaml を使い Python で設定可能
import yaml

config_dict = {"batch_size": 4, "device": "cuda", "model": { "_component_": "torchtune.models.llama3_2.llama3_2_1b" }, ... }
yaml_file_path = "custom_recipe.yaml" with open(yaml_file_path, "w") as yaml_file: yaml.dump(config_dict, yaml_file)
Llama 3 のファインチューニング

カスタム学習の実行

tune run --config custom_recipe.yaml
INFO:torchtune.utils.logging:Running 
Writing logs to /tmp/full-llama3.2-finetune/log_1732815689.txt
INFO:torchtune.utils.logging:Model is initialized with precision torch.bfloat16.
INFO:torchtune.utils.logging:Tokenizer is initialized from file.
1|52|Loss: 2.3697006702423096:   0%|▏                     | 52/25880
  • ログ保存
  • 正常に初期化
  • エポック/ステップ進捗
  • 損失メトリクス
Llama 3 のファインチューニング

Let's practice!

Llama 3 のファインチューニング

Preparing Video For Download...