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

LoRA fine-tuning

~8 min · keras-nlp

Level 0Keras 도제
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

큰 LLM 의 *모든 weight* 학습은 GPU 메모리 폭발 (Gemma 2B fine-tune 에 80GB+). LoRA — frozen base 옆에 작은 *low-rank adapter* (보통 rank 8 ~ 32) 만 학습. 학습 메모리 1/100, 저장 size 1/1000.

KerasHub 에서 한 줄: model.backbone.enable_lora(rank=8). 그 후 일반 fit() — 자동으로 adapter 만 update. 학습 후 adapter weight 만 save → deploy 시 base + adapter merge.

Code

# Enable LoRA on the model backbone
classifier.backbone.enable_lora(rank=4)

# Check trainable params — dramatically reduced!
print(classifier.summary())
# Total params: 110M, Trainable: ~300K (0.3%!)

# QLoRA: Quantize first, then LoRA
classifier.backbone.quantize("int8")     # Reduce model size
classifier.backbone.enable_lora(rank=4)  # Add adapters
# Even less memory, nearly same quality

External links

Exercise

Gemma-2b 로드. LoRA(rank=8) enable. backbone.count_params() 전후 비교 — trainable parameter 가 2B 에서 수백만 으로 떨어지는 거 메모.

Progress

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

댓글 0

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

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