본문 바로가기
AI

LLaMA-Factory Baseline

by Myungbin 2024. 4. 18.
 

GitHub - hiyouga/LLaMA-Factory: Unify Efficient Fine-Tuning of 100+ LLMs

Unify Efficient Fine-Tuning of 100+ LLMs. Contribute to hiyouga/LLaMA-Factory development by creating an account on GitHub.

github.com

LLaMA-Factory는 llm을 쉽게 Fine-tuning하기 위한 라이브러리로 GUI환경에서 복잡한 코드 입력 없이도 튜닝을 진행할 수 있습니다.

Installation

git clone <https://github.com/hiyouga/LLaMA-Factory.git>
python -m venv llama_factory
source llama_factory/bin/activate 
cd LLaMA-Factory
pip install -e .[metrics]

LLaMA Board GUI

LLaMA Board GUI는 단일 GPU에서의 훈련만 지원합니다. 분산 훈련에는 CLI를 사용하세요

export CUDA_VISIBLE_DEVICES=0 # `set CUDA_VISIBLE_DEVICES=0` for Windows
export GRADIO_SERVER_PORT=7860 # `set GRADIO_SERVER_PORT=7860` for Windows
python src/train_web.py # or python -m llmtuner.webui.interface

Custom Dataset

 

LLaMA-Factory/data/README.md at main · hiyouga/LLaMA-Factory

Unify Efficient Fine-Tuning of 100+ LLMs. Contribute to hiyouga/LLaMA-Factory development by creating an account on GitHub.

github.com

dataset_info.json

custom dataset은 data/dataset_info.json파일에 다음과 같이 데이터셋 정보를 추가하면 됩니다

  "KoAlpaca": {
    "hf_hub_url": "beomi/KoAlpaca-v1.1a",
  },
  "KoAlpaca_json": {
    "file_name": "KoAlpaca.json"
  },
  1. hugging face dataset ⇒ hf_hub_url /  dataset name
  2. local dataset ⇒ 알파카 또는 sharegpt 형식의 dataset을 지원하며, 알파카 형식의 데이터세트는 아래 형식을 따라야 합니다.
    # Example
    [
        {
            "instruction": "Give three tips for staying healthy.",
            "input": "",
            "output": "1.Eat a balanced diet and make sure to include plenty of fruits and vegetables. \n2. Exercise regularly to keep your body active and strong. \n3. Get enough sleep and maintain a consistent sleep schedule."
        }
    
    ]​

그러면 GUI상에 다음과 같이 추가됩니다!

Model

모델을 설정하고 훈련하는 과정은 간단합니다. 모델의 경로와 이름(Hugging face model name)을 설정한 후, 필요한 옵션을 선택하여 사용할 수 있습니다.


CLI

Train

example

CUDA_VISIBLE_DEVICES=0 python src/train_bash.py \
    --stage sft \
    --do_train True \
    --model_name_or_path yanolja/EEVE-Korean-Instruct-10.8B-v1.0 \
    --use_fast_tokenize \
    --finetuning_type lora \
    --quantization_bit 4 \
    --template default \
    --dataset_dir data \
    --dataset KoAlpaca \
    --cutoff_len 1024 \
    --learning_rate 5e-05 \
    --num_train_epochs 3.0 \
    --max_samples 100000 \
    --per_device_train_batch_size 2 \
    --gradient_accumulation_steps 8 \
    --lr_scheduler_type cosine \
    --max_grad_norm 1.0 \
    --logging_steps 5 \
    --save_steps 100 \
    --warmup_steps 0 \
    --optim adamw_torch \
    --report_to none \
    --output_dir saves/Custom/lora/train_2024-04-18-15-01-00 \
    --fp16 True \
    --lora_rank 8 \
    --lora_alpha 16 \
    --lora_dropout 0.1 \
    --lora_target q_proj,v_proj \
    --plot_loss True \
 

全量微调的ckpt没办法在do_predict时被加载 · Issue #2035 · hiyouga/LLaMA-Factory

Reminder I have read the README and searched the existing issues. Reproduction CUDA_VISIBLE_DEVICES=0 python src/train_bash.py --stage sft --do_predict --model_name_or_path xxxx/checkpoint-xxx --da...

github.com

Custom model 을 사용할 때 일부 모델이(e.g. yanolja/EEVE-Korean-Instruct-10.8B-v1.0) GUI에서는 TypeError: not a string 에러가 뜨는데, 이는 CLI에서 --use_fast_tokenize 옵션을 추가해주면 해결 가능합니다!

 

CLI의 경우 GUI에서 Preview command를 통해 쉽게 작성 가능합니다.

⇒ 먼저 GUI에서 Train config를 설정 후 Preview command로 입력하면 편할 수 있습니다!

'AI' 카테고리의 다른 글

EasyOCR 간단 리뷰(Recognition)  (0) 2024.07.04
YOLO Custom Dataset  (0) 2024.05.29
ollama baseline  (0) 2024.04.19