ToolsPromptsSkillsWorkflowsBlogAbout

LoRA / QLoRA Fine-tuning — adapt models without retraining

Inject low-rank adaptation matrices into transformer layers to fine-tune a model on domain-specific data using a single consumer GPU.

Fine-tuning4.6
LoRA / QLoRA Fine-tuning — adapt models without retraining preview

Prompt template

N/A — this is a fine-tuning workflow, not a prompting technique. Use the following training configuration:

Base model: {base_model}
LoRA rank: 8-64
LoRA alpha: 16-128
Target modules: q_proj, v_proj (or all linear layers)
Learning rate: 1e-4 to 3e-4
Epochs: 3-10
Batch size: 4-16 (with gradient accumulation)

How to use

  1. 1Prepare a high-quality instruction dataset (500-10,000 examples) in chat or instruction-response format
  2. 2Clean and deduplicate the dataset; remove low-quality or off-policy examples
  3. 3Load the base model in 4-bit (QLoRA) or 16-bit (LoRA) precision with bitsandbytes
  4. 4Configure LoRA adapters with rank 8-64, alpha 16-128, targeting attention projection layers
  5. 5Train using SFTTrainer (TRL) with cosine learning rate schedule and warmup
  6. 6Evaluate the adapter on a held-out test set; merge with base model or deploy as separate adapter

Pro tips

  • QLoRA with 4-bit quantization can fine-tune a 70B model on a single 48GB GPU
  • Start with rank 8-16; higher ranks (32-64) help for complex tasks but increase storage and compute
  • Target all linear layers (not just q/v projections) for better adaptation at the cost of more parameters
  • Always keep a copy of the base model — LoRA adapters are small (tens of MB) and can be swapped

Works best with

pefttrlbitsandbyteshuggingface

Ratings & Reviews

Loading reviews…

Share your experience

Select a rating

Related Skills