Fine-tune Gemma 3 with QLoRA (single GPU)
QLoRA combines 4-bit base model quantization with LoRA adapters, which is the setup used to fit Gemma 3 12B on a single 16 GB GPU (RTX 4080, A4000). Soup publishes no measured peak for this config; soup profile --config gemma3.yaml --gpu rtx4080 prints an analytical estimate for your card.
Why QLoRA?
- The frozen base weights take about a quarter of the memory of 16-bit weights
- The QLoRA paper reports that it preserves 16-bit fine-tuning task performance on the tasks it measured; Soup has not measured that for Gemma 3
- Works on consumer hardware
1. Install
pip install "soup-cli[train,fast]"Since v0.71.0 the base
soup-clipackage is a light, PyTorch-free CLI.[train]adds the training stack;[fast]adds Unsloth on top. Installing[fast]alone cannot train. Since v0.77.0 Soup needs Python 3.11 to 3.13 (>=3.11,<3.14); on Python 3.10, pip keeps installing v0.76.x.
2. Config
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
gradient_checkpointing: true # since v0.77.0 the default false turns Unsloth's off
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]
output: ./runs/gemma3Note the key flags:
quantization: 4bit— 4-bit NF4 quantization of base model (the key isquantization;quantis not a field, and since v0.75.0 it is refused as an unknown key; v0.74.0 only reported it). It applies totask: sft. On the tasks whose trainer never quantises the base (distill,classifier,reranker,cross_encoder,prm,moe_lora_routing,unlearnandasr) an explicit4bitor8bit(orload_in_8bit: true) is refused at load since v0.77.0:training.quantization: 4bit has no effect on task='reranker': its trainer never quantises the base, so no run can honour it. Delete the line or set quantization: none. Refused as of Soup v0.77.v0.76 loaded it with a warning and treated it asnone(#795)use_rslora: true— rank-stabilized LoRA (v0.21.0+), better for larger models. Onbackend: unslothit is applied only since v0.77.0 (#1853, #1899): through v0.76.x the flag loaded and was never read there, so a run with this config trained plain-LoRA scaling (alpha / r) with nothing said. Results from such a run change on v0.77.0; drop the flag to keep the old behaviourgradient_checkpointing: true— since v0.77.0 the Unsloth backend honours this key (#1981). Through v0.76.x it always used Unsloth's own checkpointing kernel; now the schema defaultfalseturns checkpointing off, so the config setstrueto keep itbatch_size: 1withgradient_accumulation_steps: 16— effective batch of 16 on tight VRAM
Before you train
Run soup doctor --config gemma3.yaml first. Since v0.76.0 many more settings are refused when the config loads, each naming the field and what to change, so a config that loaded on an older release can stop loading. soup doctor --config prints the error and exits 2 without loading a model (it stops at the first cross-field refusal, so fix that setting and run it again until it prints no error), and since v0.77.0 it no longer prints All checks passed! above a refusal. Several things v0.76 only warned about are refused at v0.77.0, for example a staged field (validated, read by nothing) set away from its default, which stops the load with a line ending refused as of v0.77. Delete the line., and the deprecated data.remove_unused_columns: true. See Config refusals.
3. Train
soup train --config gemma3.yamlIn a script or CI job, pass --yes: since v0.77.0 soup train with its stdin piped or redirected and no --yes exits 3 instead of waiting at the confirmation prompt.
Monitor VRAM with nvidia-smi in another terminal. The peak depends on data.max_length and the batch size, and no peak is published here for this config; if it does not fit your card, see the out-of-memory note below.
4. Merge and export
# Dequantize, merge LoRA, save a full fp16 model (the default --save-format)
soup merge --adapter ./runs/gemma3 --output ./gemma3-merged
# Or export directly to GGUF q4_k_m
soup export --model ./runs/gemma3 --format gguf --quant q4_k_mCommon issues
OOM during backward pass? Reduce data.max_length to 1024, and check that gradient checkpointing is on (the config above sets it; since v0.77.0 leaving it out turns it off):
training:
gradient_checkpointing: trueLoss spikes? Enable loss watchdog (v0.24.0+):
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: 5Related
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.