1. 기반 환경 구성
CUDA Toolkit, CUDNN, WSL 설치
2. 개발 환경 구성(https://docs.axolotl.ai/docs/installation.html 참고)
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
source miniconda3/bin/activate
conda create -n axo python=3.11 -y
conda activate axo
pip install torch torchvision torchaudio
pip install -U packaging setuptools wheel ninja
pip install --no-build-isolation axolotl[flash-attn,deepspeed]
3. 모델 다운로드, 디렉터리 구조 정하기
workspace
- config.yml
- dataset.jsonl
- models/
- llama-3.2-Korean-Bllossom-3B/
- config.json
- generation_config.json
- model-00001-of-00002.safetensors
- model-00002-of-00002.safetensors
- model.safetensors.index.json
- special_tokens_map.json
- tokenizer.json
- tokenizer_config.json
4. 훈련용 데이터셋 구하기
{"instruction": "Translate to Korean", "input": "apple", "output": "사과"}
{"instruction": "Translate to Korean", "input": "banana", "output": "바나나"}
{"instruction": "Translate to Korean", "input": "cheese", "output": "치즈"}
...
이렇게 생긴 데이터셋을 alpaca 형식이라고 부른다. 헷갈리게도 Alpaca라는 이름의 데이터셋이 존재한다. 아래 getting-started 문서를 보고 전처리하면 메모리도 아끼고 좋다.
5. Axolotl 설정하기
https://docs.axolotl.ai/docs/getting-started.html
https://docs.axolotl.ai/docs/batch_vs_grad.html
https://docs.axolotl.ai/docs/lora_optims.html
https://docs.axolotl.ai/docs/config.html
위 문서들을 순서대로 읽으면 이해에 좋다.
config.yml:
base_model: ./models/llama-3.2-Korean-Bllossom-3B
load_in_8bit: true
adapter: lora
# Training settings
micro_batch_size: 2
num_epochs: 3
learning_rate: 0.0003
# Your dataset
datasets:
- path: dataset.jsonl # Your local data file
type: alpaca # Or other format
6. 파인튜닝 실행하기
axolotl train config.yml
학습이 끝나면 ./outputs/lora-out에 저장되나보다.
7. 추론 실행하기
axolotl inference config.yml --lora-model-dir="./outputs/lora-out"
이렇게 하면 CLI로 실행되는데, gradio라는 웹 기반 UI로 실행할 수도 있다.
8. 같이 보기
https://devocean.sk.com/blog/techBoardDetail.do?ID=166168
No-Code LLM 파인튜닝 : Axolotl
devocean.sk.com
SK 블로그 자료이다.
https://huggingface.co/docs/accelerate/en/usage_guides/model_size_estimator
Model memory estimator
One very difficult aspect when exploring potential models to use on your machine is knowing just how big of a model will fit into memory with your current graphics card (such as loading the model onto CUDA). To help alleviate this, Accelerate has a CLI int
huggingface.co
실행, 훈련(Adam 기준)시 필요한 VRAM 계산기이다.
Axolotl을 국내에서는 아홀로틀이라고 읽는 것 같다. 내가 아는 그 우파루파 도롱뇽 맞다.