What QLoRA changes and which GPU you need
Plain LoRA keeps the frozen base model in 16-bit, so weights cost about two bytes per parameter. QLoRA stores those frozen weights in 4-bit and dequantizes them for each computation, while the small LoRA adapters train in higher precision. The QLoRA paper reports that this reduces memory enough to fine-tune a 65B parameter model on a single 48 GB GPU.
The paper adds three pieces: the 4-bit NormalFloat (NF4) data type for normally distributed weights, double quantization that quantizes the quantization constants, and paged optimizers that absorb memory spikes. Transformers’ documentation says double quantization saves about 0.4 bits per parameter more, and gives an example of a 13B model fine-tuned on a 16 GB T4 at sequence length 1024 and batch size 1.
The table uses weight arithmetic at about half a byte per parameter. Activations, the adapter, optimizer state and CUDA overhead come on top, so treat it as a floor. For the full method see the LLM VRAM requirements guide.
| Base model size | 4-bit weights (approx.) | Single GPU to start with |
|---|---|---|
| 7-8B | 4-5 GB | 24 GB card such as RTX 4090 or L4 |
| 13-14B | 7-8 GB | 24 GB card; 48 GB for long sequences |
| 30-34B | 16-18 GB | 48 GB card such as L40S or RTX A6000 |
| 65-70B | 33-38 GB | 48 GB tight, as in the QLoRA paper; 80 GB is easier |
References: QLoRA: Efficient Finetuning of Quantized LLMs · Hugging Face Transformers: bitsandbytes quantization
Step 1 and 2: check the GPU and install bitsandbytes
Step 1. Run nvidia-smi to confirm the card, memory and driver. bitsandbytes supports NVIDIA GPUs from compute capability 6.0 for NF4, but the current Linux x86-64 wheels built with CUDA 12.8 start at sm70, and those built with CUDA 13 start at sm75. Any data center card from A10 onward, and consumer RTX 30, 40 and 50 series, falls inside those ranges.
Step 2. In a fresh virtual environment run pip install "trl[peft]" bitsandbytes. bitsandbytes needs Python 3.10 or newer and PyTorch 2.4 or newer. Confirm with python -c "import bitsandbytes, torch; print(torch.cuda.is_bf16_supported())" and save the output of trl env with your run notes.
Accept the license for gated models on their model page and run hf auth login. Point HF_HOME at the large local disk; even quantized training downloads the full 16-bit checkpoint and quantizes it on load.
References: bitsandbytes installation guide · Hugging Face TRL: PEFT integration and QLoRA
Step 3: configure 4-bit loading and the adapter
Create train.py. Import torch, load_dataset from datasets, LoraConfig from peft, BitsAndBytesConfig from transformers, and SFTConfig and SFTTrainer from trl.
Set the quantization: bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16, bnb_4bit_use_double_quant=True). Transformers recommends NF4 for training 4-bit base models, and notes the compute dtype defaults to float32 unless you change it, which is slower.
Set the adapter: peft_config = LoraConfig(r=16, lora_alpha=32, lora_dropout=0.05, target_modules="all-linear", task_type="CAUSAL_LM"). PEFT describes all-linear as the QLoRA-style choice: adapters on every linear layer, not only query and value projections.
References: Hugging Face Transformers: bitsandbytes quantization · Hugging Face TRL: PEFT integration and QLoRA · Hugging Face PEFT: LoRA developer guide
Step 4: train with SFTTrainer
Set training arguments: args = SFTConfig(output_dir="out", learning_rate=2e-4, per_device_train_batch_size=1, gradient_accumulation_steps=16, max_length=2048, optim="paged_adamw_8bit", logging_steps=10, save_steps=200). The paged_adamw_8bit and paged_adamw_32bit names are built into Transformers’ optimizer options.
Build the trainer: trainer = SFTTrainer(model="Qwen/Qwen3-14B", args=args, train_dataset=load_dataset("json", data_files="train.jsonl", split="train"), quantization_config=bnb, peft_config=peft_config). TRL’s PEFT guide says the trainer loads and quantizes the model for you when you pass both configs. Then call trainer.train() and trainer.save_model("out/adapter").
The CLI equivalent is trl sft --model_name_or_path Qwen/Qwen3-14B --dataset_name your/dataset --load_in_4bit --use_peft --lora_r 16 --lora_alpha 32 --lora_target_modules all-linear --per_device_train_batch_size 1 --gradient_accumulation_steps 16 --output_dir out.
Do not pass device_map="auto" for training. Transformers’ guide says that setting should only be used for inference. Gradient checkpointing is already on by default in SFTConfig, which is what keeps activations small.
References: Hugging Face TRL: PEFT integration and QLoRA · Hugging Face TRL: SFT Trainer and SFTConfig · Hugging Face Transformers: bitsandbytes quantization · Hugging Face Transformers training_args.py optimizer names
QLoRA fine-tuning settings table
Start with these values from the official docs and the QLoRA paper, then change one at a time against a fixed eval set.
| Setting | Value | Source or reason |
|---|---|---|
| load_in_4bit | True | Enables 4-bit base weights |
| bnb_4bit_quant_type | nf4 | Recommended for training 4-bit base models |
| bnb_4bit_compute_dtype | torch.bfloat16 | Default is float32, which is slower |
| bnb_4bit_use_double_quant | True | Saves about 0.4 bits per parameter more |
| target_modules | all-linear | QLoRA-style adapters on every linear layer |
| learning_rate | 2e-4 | TRL’s LoRA and QLoRA rate, 10x the SFT default |
| optim | paged_adamw_8bit | Paged optimizer absorbs memory spikes |
| per_device_train_batch_size | 1-4 | Raise only after a clean 20-step trial |
| gradient_accumulation_steps | 8-16 | Keeps effective batch size useful |
References: Hugging Face Transformers: bitsandbytes quantization · Hugging Face TRL: PEFT integration and QLoRA · Hugging Face TRL: SFT Trainer and SFTConfig · QLoRA: Efficient Finetuning of Quantized LLMs
Step 5: test, then merge into a 16-bit base
The output is a LoRA adapter, not a new 4-bit model. To test it, load the base with the same BitsAndBytesConfig, attach the adapter with PeftModel.from_pretrained, and compare base and tuned answers on 20-50 held-out prompts.
For a single set of serving weights, reload the base model in bfloat16 on a machine with enough memory, attach the adapter, and call merge_and_unload. PEFT notes the call returns a new model, so assign it before save_pretrained. Merging into the 16-bit base gives you a normal checkpoint you can quantize again for inference if needed.
References: Hugging Face PEFT: LoRA developer guide
Common QLoRA errors and fixes
Run with max_steps=20 first. Most of these show up within a minute, and the planned CUDA out of memory guide goes deeper on the first row.
| Error or symptom | Likely cause | Fix |
|---|---|---|
| CUDA out of memory during a step | Sequence length or batch too large | Lower max_length or batch size, keep checkpointing on |
| Memory spikes then OOM on long examples | Optimizer and activation peaks | Use optim="paged_adamw_8bit" |
| bitsandbytes cannot find a CUDA kernel | Wheel not built for your GPU or CUDA | Check the sm targets in the install guide; upgrade or build from source |
| Error training a 4-bit model directly | 4-bit weights cannot be trained | Pass a peft_config; only extra parameters train |
| Training much slower than expected | Compute dtype left at float32 | Set bnb_4bit_compute_dtype=torch.bfloat16 |
| Layers placed on CPU, very slow steps | device_map="auto" used for training | Remove device_map; it is meant for inference |
| Model never stops generating | EOS token mismatch with chat template | Set eos_token in SFTConfig |
References: Hugging Face Transformers: bitsandbytes quantization · bitsandbytes installation guide · Hugging Face TRL: SFT Trainer and SFTConfig
Estimate time and GPU-hours for QLoRA fine-tuning
Measure, then multiply. Count dataset tokens after templating, run 50 steps, and divide the change in the logged num_tokens by elapsed seconds. Do not reuse a 16-bit LoRA rate: dequantizing weights on every pass changes the speed, so a fresh trial is the only reliable input.
An illustrative calculation with assumed inputs: 10,000 examples at 800 tokens is 8 million tokens per epoch. At an assumed measured rate of 1,500 tokens per second, an epoch takes about 1.5 hours. Two epochs plus 30 minutes of setup is about 3.5 GPU-hours, or $3.50 at an assumed $1 per GPU-hour on a 24 GB card.
Compare that with renting a larger card and running plain LoRA, which may finish sooner per token. The trade-offs across runs and GPU types are in the LoRA fine-tuning cost guide, and the plain LoRA steps are in fine-tune an LLM with LoRA.
| Input (illustrative) | Value |
|---|---|
| Tokens per epoch | 10,000 × 800 = 8M |
| Measured rate (assumed) | 1,500 tokens per second |
| Training, 2 epochs | ≈3 hours |
| Setup and evaluation | 0.5 hours |
| Total at $1 per GPU-hour (assumed) | ≈3.5 GPU-hours, about $3.50 |
References: Hugging Face TRL: SFT Trainer and SFTConfig
Checklist and next step
Check the GPU architecture against the bitsandbytes wheel targets. Install trl[peft] and bitsandbytes. Use nf4, bfloat16 compute and double quantization. Target all-linear, start at 2e-4 and paged_adamw_8bit. Skip device_map="auto". Run 20 steps, then measure tokens per second for 50. Merge into a 16-bit base for serving.
A 24 GB card such as the RTX 4090 covers most 7-14B jobs; a 48 GB L40S gives room for 30B-class models and longer sequences. NeuraMesh rents both by the hour: choose GPU, plan, count, hours and region on rent GPUs, get a confirmed quotation, typically within one business day, and pay only when you approve. For a sizing second opinion, ask the compute advisor.
NeuraMesh prices for these GPUs
| GPU | Memory | Data center | Value |
|---|---|---|---|
| RTX 4090 | 24 GB | $0.46 | $0.40 |
| L40S | 48 GB | $1.26 | $0.54 |
| A100 | 80 GB | $1.56 | $0.98 |
| H100 | 80 GB | $2.88 | $2.00 |
Every order is confirmed in a quotation before you pay. See all GPU prices.
Questions readers ask
Can I do QLoRA fine-tuning of a 70B model on one GPU?
The QLoRA paper reports fine-tuning a 65B model on a single 48 GB GPU. A 70B model’s 4-bit weights alone are roughly 35-38 GB, so 48 GB is tight and needs short sequences and batch size 1. An 80 GB card gives more headroom.
Is QLoRA worse than LoRA?
The QLoRA paper’s abstract says the method reduces memory while preserving full 16-bit fine-tuning task performance in its experiments. Results vary by task, so compare both on your own eval set if you can afford a 16-bit run.
Which GPUs support bitsandbytes 4-bit?
bitsandbytes lists NF4 support from compute capability 6.0, but current wheels target sm70 or sm75 and newer depending on CUDA version. Turing, Ampere, Ada, Hopper and Blackwell cards are covered by the CUDA 12.8 and 13 wheels.
What learning rate should QLoRA use?
TRL’s PEFT guide uses 2e-4 for QLoRA, ten times the 2e-5 SFT default. Lower it if the loss spikes or turns to NaN.
Can I merge a QLoRA adapter into the 4-bit model?
It is cleaner to reload the base model in bfloat16, attach the adapter and call merge_and_unload. That gives a standard 16-bit checkpoint you can serve or quantize again with an inference-focused method.
Sources and editorial notes
- QLoRA: Efficient Finetuning of Quantized LLMs
- Hugging Face Transformers: bitsandbytes quantization
- bitsandbytes installation guide
- Hugging Face TRL: PEFT integration and QLoRA
- Hugging Face PEFT: LoRA developer guide
- Hugging Face TRL: SFT Trainer and SFTConfig
- Hugging Face Transformers training_args.py optimizer names
Primary documentation reviewed November 24, 2026. Provider descriptions reflect published documentation. Recommendations are our analysis; worked figures are illustrative unless explicitly stated otherwise. No independent provider benchmark or uptime ranking is claimed.
Need this GPU? Rent it from NeuraMesh: choose a GPU and plan, get a confirmed quotation, and pay only when you approve. See pricing.


