Fine-tuning ด้วย TorchTune

Fine-Tuning กับ Llama 3

Francesca Donadoni

Curriculum Manager, DataCamp

องค์ประกอบของการ fine-tuning ด้วย TorchTune

  • Model

    • กำหนดสถาปัตยกรรมและ pre-trained weights ที่จะ fine-tune
    • มีให้เลือกหลายเวอร์ชันและจำนวนพารามิเตอร์
  • Dataset

    • ระบุข้อมูลที่ใช้ในการฝึก
  • Recipe

    • ไฟล์คอนฟิกหลักที่รวมโมเดล ชุดข้อมูล และพารามิเตอร์การฝึกไว้ด้วยกัน
    • ช่วยให้ได้ผลลัพธ์ที่สม่ำเสมอและทำซ้ำได้

iStock-2151073200.jpg

iStock-1281282682.jpg

iStock-2173849278.jpg

Fine-Tuning กับ Llama 3

องค์ประกอบของการ fine-tuning ด้วย TorchTune

  • Model

    • !tune ls
      llama3/8B_full
      llama3_1/8B_full
      llama3_2/1B_full ...
      
  • Dataset

    • ds.save_to_disk("new_dataset")
  • Recipe

    • custom_recipe.yaml

iStock-2151073200.jpg

iStock-1281282682.jpg

iStock-2173849278.jpg

Fine-Tuning กับ Llama 3

องค์ประกอบของ TorchTune recipe

  • การตั้งค่าทั่วไปและโฟลเดอร์ผลลัพธ์
    • Batch size, device และ epochs

 

  • Model
    • ระบุสถาปัตยกรรมและการตั้งค่าโมเดล

 

  • Optimizer

    • รวมถึง learning rate
  • Dataset

    • กำหนดการ preprocessing และพาธของชุดข้อมูล
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
Fine-Tuning กับ Llama 3

การตั้งค่า TorchTune recipes

  • มีพารามิเตอร์เพิ่มเติมให้ปรับได้
  • ตั้งค่าใน Python ด้วย yaml
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)
Fine-Tuning กับ Llama 3

รัน custom fine-tuning

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
  • บันทึก log ไว้แล้ว
  • การเริ่มต้นสำเร็จ
  • ความคืบหน้าของ epoch และ step
  • ค่า loss
Fine-Tuning กับ Llama 3

มาฝึกกันเถอะ!

Fine-Tuning กับ Llama 3

Preparing Video For Download...