Introduction
Training large AI models from scratch is very expensive and slow. LoRA and QLoRA help make this process faster and cheaper by changing how the model learns and stores information.
Jump into concepts and practice - no test required
Imagine you have a huge book that contains all the knowledge you need. Instead of rewriting the whole book to add new information, you just add small sticky notes with updates. LoRA is like adding these sticky notes, and QLoRA is like making the notes smaller so they take less space.
┌─────────────────────────────┐ │ Large AI Model │ │ ┌───────────────┐ │ │ │ Original Model │ │ │ └───────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────┐ │ │ │ LoRA Matrices │ │ │ │ (small additions) │ │ │ └─────────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────┐ │ │ │ QLoRA Compression │ │ │ │ (smaller data size) │ │ │ └─────────────────────┘ │ └─────────────────────────────┘
model_size = 1000 # in MB lora_size = 10 # LoRA adds 10 MB quantization_factor = 0.25 # QLoRA compresses to 25% lora_model_size = model_size + lora_size qlora_model_size = int(lora_model_size * quantization_factor) print(qlora_model_size)
model_size = 800 lora_size = 20 quantization_factor = 0.3 qlora_model_size = model_size + lora_size * quantization_factor print(qlora_model_size)