Fine-tune Gemma 3 with QLoRA (single GPU)

QLoRA combines 4-bit base model quantization with LoRA adapters, making it possible to fine-tune Gemma 3 12B on a single 16GB GPU (RTX 4080, A4000).

Why QLoRA?

  • 4× memory reduction vs full LoRA
  • Same quality as full fine-tuning (~99% of benchmark scores per the QLoRA paper)
  • Works on consumer hardware

1. Install

bash
pip install "soup-cli[train,fast]"

Since v0.71.0 the base soup-cli package is a light, PyTorch-free CLI. [train] adds the training stack; [fast] adds Unsloth on top. Installing [fast] alone cannot train.

2. Config

yaml
base: google/gemma-3-12b-it
task: sft
backend: unsloth            # root-level, NOT under training

data:
  train: train.json
  format: alpaca
  max_length: 2048          # sequence length lives under data

training:
  quantization: 4bit        # the key is quantization, not quant
  epochs: 3
  lr: 2.0e-4                # the key is lr, not learning_rate
  batch_size: 1
  gradient_accumulation_steps: 16
  lora:
    r: 16                   # LoRA turns on when r > 0; there is no enabled flag
    alpha: 16
    use_rslora: true
    target_modules: [q_proj, k_proj, v_proj, o_proj]

Note the key flags:

  • quant: 4bit — 4-bit NF4 quantization of base model
  • use_rslora: true — rank-stabilized LoRA (v0.21.0+), better for larger models
  • batch_size: 1 with gradient_accumulation_steps: 16 — effective batch of 16 on tight VRAM

3. Train

bash
soup train --config gemma3.yaml

Monitor VRAM with nvidia-smi in another terminal. You should see ~14GB peak on Gemma 3 12B.

4. Merge and export

bash
# Dequantize, merge LoRA, save full model
soup merge --adapter ./runs/gemma3/latest --output ./gemma3-merged

# Or export directly to GGUF q4_k_m
soup export --model ./runs/gemma3/latest --format gguf --quant q4_k_m

Common issues

OOM during backward pass? Reduce data.max_length to 1024 or enable gradient checkpointing:

yaml
training:
  gradient_checkpointing: true

Loss spikes? Enable loss watchdog (v0.24.0+):

yaml
training:
  loss_watchdog: true          # a bool, not a block
  loss_watchdog_threshold: 2.0 # spike factor vs the running mean (default 3.0)
  loss_watchdog_patience: 5

Soup is free and Apache-2.0. If it saved you a training run, starring the repo costs nothing and helps most. You can also fund the GPU time behind the work a 4 GB laptop cannot reach.