# ==========================================
# CELL 5: ATTACH LORA ADAPTER
# ==========================================
# Run this AFTER cell_04

model = FastLanguageModel.get_peft_model(
    model,
    r=LORA_R,
    lora_alpha=LORA_ALPHA,
    lora_dropout=0,              # 0: we have 971k samples, no overfitting risk
    bias="none",
    use_gradient_checkpointing="unsloth",  # Saves ~30% VRAM
    random_state=3407,
    target_modules=[
        "q_proj", "k_proj", "v_proj", "o_proj",
        "gate_proj", "up_proj", "down_proj",
    ],
)

# Print trainable parameters
model.print_trainable_parameters()

gc.collect()
torch.cuda.empty_cache()
print(f"VRAM after LoRA adapter: {torch.cuda.memory_allocated() / 1024**3:.1f} GB")
