C.W.K.
Stream
Lesson 04 of 06 · published

QLoRA & DoRA — vanilla LoRA 가 부족할 때

~14 min · qlora, dora, advanced-fine-tuning

Level 0Curious
0 XP0/51 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

Vanilla LoRA 의 두 강화

LoRA 가 대부분 작업에 대부분 갈 길 데려가. 두 명명된 정제가 specific 방향으로 도달 확장 — fitting 더 큰 base 모델을 더 적은 메모리에 위한 QLoRA, full fine-tuning 까지의 품질 갭 닫기 위한 DoRA. mlx-lm 이 둘 다 최소 추가 의식으로 지원.

QLoRA — 양자화된 base 위에 adapter 학습

QLoRA 는 학습 중 base 모델을 4-bit 로 양자화하고 그 위에 (full-precision) LoRA adapter 를 학습하는 기법. Base 모델이 fp16 에서의 ~25% 메모리 차지; adapter 는 어쨌든 작아. 결과 — fp16 으로 70B 가 추론에서도 안 들어갈 하드웨어에서 70B 모델 fine-tune 가능.

mlx-lm 에서 QLoRA 는 --model 을 이미-양자화된 base (예 mlx-community/Mistral-7B-Instruct-v0.3-4bit) 가리킬 때 일어나는 것의 implicit 이름. --qlora 플래그 없음 — base 모델이 양자화돼 있을 때 quantization-aware 학습이 자동. 학습 수학은 vanilla LoRA 와 같음; 메모리 절약은 base 모델의 양자화에서 와, mlx-lm 이 투명하게 처리.

DoRA — 같은 parameter 수에서 더 좋은 품질

DoRA (Weight-Decomposed Low-Rank Adaptation) 가 weight 업데이트를 두 부분으로 분해 — magnitude 벡터와 direction 행렬. 둘 다 학습. 경험적으로, DoRA 가 같은 parameter 예산에서 LoRA 와 full fine-tuning 사이 남은 품질 갭 대부분 닫아 — 비용은 step 당 compute 와 메모리의 작은 증가.

mlx-lm 에선 --fine-tune-type dora 로 DoRA 켜. 같은 데이터 형식, 같은 다른 flag, drop-in 교체.

각각 손 뻗을 때

  • 기본 — 양자화된 base 의 vanilla LoRA (사실상 QLoRA). 90% 케이스 덮음.
  • 네 머신이 허용해야 할 것보다 더 크게 가기 — base 더 공격적으로 양자화 (mixed-precision 의 Q4). 순수 QLoRA 영역.
  • LoRA 품질이 plateau 되고 이미 rank 올림 — DoRA 시도. 한 flag 바꾼 같은 학습 명령.
  • Full fine-tuning 고려 — 더 높은 rank 의 DoRA 먼저 시도; 수학이 보통 full 에 반대.

생각할 필요 없는 것

"LoRA" vs "QLoRA" 명시적으로 안 골라 — 후자는 양자화된 base 위의 LoRA 일 뿐, mlx-lm 이 자동 처리. DoRA 또는 (드물게) full 로 갈 때만 명시적으로 fine-tune type 전환.

Code

QLoRA — 그냥 양자화된 base 가리키기·bash
# QLoRA is implicit: --model points at an already-Q4 base, mlx-lm
# trains a full-precision adapter on top, base stays quantized in memory.
python -m mlx_lm lora \
  --model mlx-community/Mistral-7B-Instruct-v0.3-4bit \
  --train --data ./my-data \
  --fine-tune-type lora \
  --num-layers 16 \
  --batch-size 4 --iters 200 --learning-rate 5e-5 \
  --adapter-path ./my-qlora-adapter

# Memory footprint stays at the base-model's quantized size + a small adapter.
# Same workflow as vanilla LoRA — no QLoRA-specific flags.
DoRA — --fine-tune-type dora 만 drop in·bash
# Same training run, but using DoRA's weight decomposition for slightly
# better quality at the same trainable-parameter count.
python -m mlx_lm lora \
  --model mlx-community/Mistral-7B-Instruct-v0.3-4bit \
  --train --data ./my-data \
  --fine-tune-type dora \
  --num-layers 16 \
  --batch-size 4 --iters 200 --learning-rate 5e-5 \
  --adapter-path ./my-dora-adapter

# Per-step memory and compute are slightly higher than LoRA;
# converged quality is usually slightly better.

External links

Exercise

같은 데이터셋을 세 빠른 fine-tune 통해 돌려 (각 50 iteration, 같은 다른 flag) — fp16 base 의 vanilla LoRA, Q4 base 의 vanilla LoRA (= QLoRA), Q4 base 의 DoRA. iter 50 의 train loss 곡선과 step 당 시간 비교. 운동은 — 구체적으로 — 각 강화가 뭐 비용 들고 뭐 사주는지를 네 하드웨어와 데이터에서 느끼는 것.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.