SFT
, PPO
, DPO
등 RLHF 파인튜닝을 쉽게 구성 가능from transformers import AutoTokenizer, AutoModelForCausalLM
from trl import SFTTrainer, SFTTrainingArguments
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf")
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
dataset = [{"text": "Q: What is the capital of France?\nA: Paris"}]
training_args = SFTTrainingArguments(
output_dir="./results",
per_device_train_batch_size=2,
num_train_epochs=3,
)
trainer = SFTTrainer(model=model, tokenizer=tokenizer, train_dataset=dataset, args=training_args)
trainer.train()
huggingface-cli login
autotrain setup
autotrain llm --train --project-name "my_project" --model "meta-llama/Llama-2-7b-hf" --data-path ./data --use-peft
CSV/JSONL 형식의 text 컬럼 필수
{
"train_batch_size": 32,
"fp16": { "enabled": true },
"zero_optimization": { "stage": 2 }
}
deepspeed --num_gpus=4 train.py --deepspeed ds_config.json
train.py
는 Hugging Face Trainer나Accelerate
로 작성
python src/train_bash.py \
--model_name_or_path meta-llama/Llama-2-7b-hf \
--data_path ./data.json \
--output_dir ./output \
--adapter lora \
--num_train_epochs 3
[
{
"instruction": "What is the capital of Germany?",
"input": "",
"output": "Berlin"
}
]
base_model: meta-llama/Llama-2-7b-hf
datasets:
- path: ./data.json
adapter: qlora
output_dir: ./output
num_epochs: 3
micro_batch_size: 2
from unsloth import FastLanguageModel
from trl import SFTTrainer, SFTTrainingArguments
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="unsloth/llama-2-7b-bnb-4bit",
max_seq_length=2048,
load_in_4bit=True,
)
dataset = [{"text": "Q: What is AI?\nA: Artificial Intelligence"}]
training_args = SFTTrainingArguments(
output_dir="outputs",
per_device_train_batch_size=1,
num_train_epochs=1,
)
trainer = SFTTrainer(model=model, tokenizer=tokenizer, train_dataset=dataset, args=training_args)
trainer.train()
*Unsloth = "빠르고 가벼운 모델 로닝"
*TRL = "LLM에 특화된 학습 툴킷 (SFT, DPO 등)
* 즉, 이 둘을 결합하면 낮은 사양에서도 LLM을 빠르게 학습시킬 수 있어서, 특히 개발자 개인이나 소규모 연구 팀에서 매우 유용
라이브러리 | 주요 특징 | 장점 | 단점 | 추천 대상 |
---|---|---|---|---|
TRL | RLHF & SFT 지원 (Hugging Face) | Hugging Face와 연동 쉬움 | 커스터마이징 제한 | 연구자, 모델 실험가 |
AutoTrain | GUI 기반 자동 튜닝 플랫폼 | 코드 없이 사용 가능 | 고급 설정 어려움 | 초보자, 비개발자 |
DeepSpeed | 분산 학습/대규모 모델 최적화 | GPU 효율 최고, 다양한 전략 지원 | 설정 복잡, 다른 툴과 함께 사용 필요 | 고사양 인프라 사용자 |
LLaMA-Factory | LLaMA 모델 경량 튜닝 툴킷 | QLoRA, LoRA 등 경량화 완비 | LLaMA 외 모델은 비권장 | 로컬 튜닝 사용자 |
Axolotl | YAML 설정 기반 종합 툴킷 | 매우 유연함, 다양한 기능 통합 | 진입장벽 있음, 문서 부족 | 실험 중심 사용자 |
Unsloth | 빠르고 저용량 GPU 최적화 | 8GB GPU도 가능, 속도 매우 빠름 | 모델 종류 제한(LLaMA 등) | 저사양 로컬 사용자 |