Tinh chỉnh với TorchTune

Fine-Tuning với Llama 3

Francesca Donadoni

Curriculum Manager, DataCamp

Các thành phần tinh chỉnh với TorchTune

  • Model

    • Xác định kiến trúc và trọng số tiền huấn luyện để tinh chỉnh
    • Có các phiên bản và số tham số khác nhau
  • Dataset

    • Chỉ định dữ liệu dùng để huấn luyện
  • Recipe

    • Tệp cấu hình trung tâm kết hợp model, dataset và tham số huấn luyện
    • Bảo đảm nhất quán và tái lập

iStock-2151073200.jpg

iStock-1281282682.jpg

iStock-2173849278.jpg

Fine-Tuning với Llama 3

Các thành phần tinh chỉnh với 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 với Llama 3

Các thành phần của một recipe TorchTune

  • Thiết lập chung và thư mục đầu ra
    • Batch size, device, epochs

 

  • Model
    • Xác định kiến trúc và cấu hình model

 

  • Optimizer

    • Gồm learning rate
  • Dataset

    • Định nghĩa tiền xử lý và đường dẫn dataset
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 với Llama 3

Cấu hình recipe TorchTune

  • Nhiều tham số hơn
  • Cấu hình trong Python bằng 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 với Llama 3

Chạy tinh chỉnh tùy chỉnh

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 đã lưu
  • Khởi tạo thành công
  • Tiến độ epoch và bước
  • Chỉ số loss
Fine-Tuning với Llama 3

Hãy luyện tập!

Fine-Tuning với Llama 3

Preparing Video For Download...