Zum Hauptinhalt springen
Intelligence View
⚡ tsecurity.de Intelligence

LoRA: I Trained

Series — Fine-Tuning, Smallest to Largest: Full Fine-Tuning (270M) LoRA (1.5B) ← you are here QLoRA (7B) If the small model worked, why go bigger? In Part 1 I f…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Quelle & Fakten · 3 Min. Lesezeit
Quelle: dev.to
Rubrik: Sichere Programmierung

Series — Fine-Tuning, Smallest to Largest:




  1. Full Fine-Tuning (270M)


  2. LoRA (1.5B) ← you are here

  3. QLoRA (7B)

  4. If the small model worked, why go bigger?




In Part 1 I fully fine-tuned a 270M model — updating every weight. That's fine for a tiny model. It gets painful as models grow, because full fine-tuning needs gradients and optimizer state for every parameter (~4× the model size in memory).



So: what do you do when the model is too big to comfortably fine-tune all of?






The idea behind LoRA



LoRA (Low-Rank Adaptation) rests on one observation: the change fine-tuning makes to a weight matrix is "low rank" — it lives in a small subspace. You don't need to learn the full update ΔW; you can learn it as the product of two skinny matrices, B·A:




output = W·x  +  (B·A)·x
↑frozen ↑trainable (tiny)






For a single 1536×1536 layer at rank 16, that's about 49,000 trainable numbers instead of ~2.4 million. And you freeze the entire base model — only the adapters train. B starts at zero, so at step 0 the model behaves exactly like the original and training nudges it from there.






The config






from peft import LoraConfig, get_peft_model, TaskType

lora_config = LoraConfig(
task_type=TaskType.CAUSAL_LM,
r=16, # rank — adapter capacity
lora_alpha=32, # scaling; effective scale = alpha / r
lora_dropout=0.05,
target_modules=["q_proj","k_proj","v_proj","o_proj",
"gate_proj","up_proj","down_proj"],
)
model = get_peft_model(model, lora_config)
model.print_trainable_parameters()
# -> trainable params are ~1% of the model. The other 99% is frozen.






I ran this on Qwen2.5-1.5B-Instruct — 5× bigger than the Gemma model from Part 1. Same Banking77 task. Then the GPU fought back.






Wall #1: ValueError: Attempting to unscale FP16 gradients



I'd loaded the model in fp16 to save memory. Wrong move: the optimizer needs fp32 master weights; mixed precision is applied at train time by the trainer, not baked into the loaded weights.




# load weights in fp32; let the Trainer's AMP do fp16 during training
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype=torch.float32)
# and set fp16=True in TrainingArguments (on CUDA) for the mixed-precision part









Wall #2: CUDA out of memory at batch size 64



Adapter training still holds activations and optimizer state. Fix: smaller batch + gradient accumulation (keeps the effective batch) + gradient checkpointing (recompute activations in the backward pass):




per_device_train_batch_size=16,
gradient_accumulation_steps=2, # effective batch 32, lower peak memory
gradient_checkpointing=True, # ~30% more compute, big memory savings









Wall #3: my laptop and a cloud GPU showed the same speed



This one was sneaky. My Mac (MPS) and a Kaggle T4 reported nearly identical it/s. How is a datacenter GPU no faster than a laptop?



It wasn't. The Kaggle session had 2 GPUs running data-parallel — each step processed 2× the data, so the total step count halved (626 vs 1250) while it/s stayed flat. The fix isn't code, it's how you read the number: compare examples/second, never iterations/second. Once I did, the GPU was clearly ~3× faster.






Result



~96% accuracy again — a frozen 1.5B model + a few-MB adapter matched the fully-fine-tuned 270M model from Part 1, with a saved artifact roughly 1000× smaller.



And that card_arrival vs card_delivery_estimate confusion from Part 1? Still there. Bigger model, different technique, identical mistake. (We resolve that mystery in Part 4.)






What's next



Part 3: I fit a 7-billion-parameter model onto a 16GB GPU that can't even load it normally. That's QLoRA.



📓 Full runnable notebook on Kaggle: https://www.kaggle.com/code/sumannath88/02-lora-qwen2-5-1-5b






Built with PyTorch + Hugging Face Transformers + PEFT. Questions or corrections welcome in the comments.

Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:
✏️ Information ergänzen
🛡️ Versioniert via CMS-Revisions-Engine (Freigabe-Queue für Gäste)

💬 Topluluk tartışması ve yorumlar

🌐 Ana sohbete katıl

Tartışmayı başlat: Social Chat yayın akışı veya yukarıdaki ekleme formuyla uzman katkısı gönder.

Security Briefing Ücretsiz · Tek tıkla abonelikten çıkma

Zeka Digest - ücretsiz

Günlük en önemli güvenlik haberi · herhangi bir zamanda alınabilir

Community Rating & Social Proof
⭐ Okuyucu Puanı
–
Ø / 5.0
Hiçbir okuyucu henüz yorum yok
Bu makale yararlı mıydı?
0
Değerlendirmenizi gönderin
Detaylı değerlendirme (isteğe bağlı)
İçerik ve Kalite
Kaynak ve Güvenilirlik
Güncellik

İlgili Story Cluster & Kaynaklar (vector AI)

6 Cluster
24 Kaynaklar
Black Friday tech deals under $100 / £100: Fire TV Sticks, earbuds, coffee machines and more
Latest from TechRadar 29 dakika önce
23 diğer kaynaklar
Caschys Blog1 saat önceGoogle One: Black-Friday-Angebot mit bis zu 50 Prozent Rabatt netzwelt.de1 saat önceDem Testsieger ebenbürtig: Zum Black Friday stürzt Xiaomis stärkster E-Scooter im Preis ab Macerkopf.de1 saat önceFotos verbessern mit Aiarty: 52 % Rabatt + Gratisgeschenke zum Black Friday CNET11 gün önceGrab Our Top Gaming Chair Pick for up to $200 Off in Secretlab’s Black Friday Sale Latest from TechRadar57 dakika önceWalmart's Black Friday deals are live — shop our top picks now Latest from TechRadar56 dakika önceLive: Apple Black Friday deals — save on AirPods Pro 3, iPad 11-in, Apple Watch 12, AirTags & more WIRED1 saat önceThe Best Early Black Friday MacBook Deals (2026) Latest from Windows Central1 saat önceEssential Xbox Ally travel accessories drop their prices before Black Friday IT Security News59 dakika önceBeyond Black Friday: The Cyber Threats Retailers Need to Prepare for in 2026 Latest from TechRadar1 saat önceBest Black Friday streaming deals from 99 cents: Apple TV, HBO Max, Paramount+, Peacock, and more CNET1 saat önceThis Bissell Vacuum Tackles Tough Pet Hair and It’s Just $170 During the Black Friday Sales WIRED1 saat önceGPS Dog Collar for Less: Our Top Tested Picks From Fi’s Black Friday Sale (2026) Latest from Windows Central1 saat önceDell's excellent XPS laptops are up to 33% off in this early Black Friday sale WinFuture News1 saat önceBlack Friday bei VZMore: Bis 600 Euro Rabatt auf Power-Mini-PCs Latest from TechRadar2 saat önceThe best Black Friday turntable deals, as picked by an audio editor Latest from TechRadar1 saat önce40+ best Black Friday deals in the UK — Switch 2, Shark vacuums, iPhone 18, Lego, PS5 bundles, Samsung, LG OLED TVs, and more CNET12 gün önceUpgrade Your Home Security for Less. Score Up to 65% Off With These Black Friday Ring Deals Giga.de2 saat önceVor Black Friday zu viel bezahlt? Mit einem Trick könnt ihr doch noch sparen - Futurezone1 saat önceStreaming-Sticks zur Black Week: Mit diesen Deals sparst du bis zu 46 % t3n.de1 saat önceBlack Friday: Diese Samsung-Angebote bei Amazon und Media Markt lohnen sich netzwelt.de3 saat önceBlack-Friday-Kracher: Huawei-Smartwatch mit EKG für unter 150 Euro Golem.de1 saat önceAnzeige: Sony WH-1000XM6 Referenz-Kopfhörer am Black Friday zum Amazon-Bestpreis Macerkopf.de2 saat önceAmazon Black Friday: Apple Pencil, WISO Steuer 2027, Microsoft 365, iPhone 18 Cases und mehr
Benzer katkılar
🔍 Verwandte News

Auch interessante Nachrichten LoRA: I Trained

Thematisch verwandte Begriffe: LoRA, Trained, Model, Matched · 6 Treffer

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Yorumlar yüklenir..
Update to Update
Widgets & Topics
Loading widgets…
Nächster Beitrag