Published

LLM Fine-Tuning for Companies: When to Fine-Tune, LoRA/QLoRA and Training Data Strategy

When fine-tuning beats prompting and RAG, how LoRA and QLoRA make it affordable on open-weights models, and how to build training data with privacy in mind.

Written by
Ali ÖzdurmuşFounder, Veni AI
Updated
Reading time
7 min read

Fine-tuning adapts a pre-trained model to a specific task, format or domain by training it further on your own examples. It is powerful, but it is rarely the first tool to reach for. This guide explains when it pays off, how parameter-efficient methods make it practical, and how to assemble training data you are actually allowed to use.

First Question: Do You Need Fine-Tuning?

GoalUsually the better tool
Answer from company documents that change oftenRAG
Follow a format or tonePrompting with examples, structured output
Use live data from ERP/CRMTool calling / function calling
Very consistent output on a narrow, high-volume taskFine-tuning
Run a smaller, cheaper model on your own servers with near large-model quality on one taskFine-tuning
Domain vocabulary the base model handles poorlyFine-tuning (often combined with RAG)

A good rule: get the task working with prompting and RAG first, collect the cases where it fails, and use those as the starting point for a fine-tuning dataset.

Transfer Learning in One Paragraph

Pre-training teaches a model general language on enormous datasets over weeks or months. Fine-tuning reuses that knowledge and adapts it with a much smaller, task-specific dataset in hours or days. You get good results from far less data and compute than training from scratch.

Full Fine-Tuning

Updates every parameter of the model.

  • Pros: maximum capacity to adapt
  • Cons: high memory needs, risk of catastrophic forgetting, a full model copy per task

Memory for the weights alone:

Model sizeFP32FP16 / BF16
7B~28 GB~14 GB
13B~52 GB~26 GB
70B~280 GB~140 GB

Training needs several times more than this for gradients and optimizer states, which is why most companies use parameter-efficient methods instead.

Parameter-Efficient Fine-Tuning (PEFT)

PEFT methods train only a small number of extra parameters while the base model stays frozen.

  • Memory: a fraction of full fine-tuning
  • Modularity: one base model, many small adapters (one per task or department)
  • Lower forgetting risk: the base model is untouched

LoRA (Low-Rank Adaptation)

LoRA approximates the weight update with two small matrices:

W' = W + ΔW = W + BA

W: original weight matrix (d × k)
B: low-rank matrix (d × r)
A: low-rank matrix (r × k)
r: rank (typically 8–64)

Parameter savings for one 4096 × 4096 matrix at r = 16:

Original: 16.7M parameters
LoRA:     131K parameters  (~127× fewer)
python
from peft import LoraConfig, get_peft_model

config = LoraConfig(
    r=16,
    lora_alpha=32,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
    lora_dropout=0.05,
    bias="none",
    task_type="CAUSAL_LM",
)
model = get_peft_model(base_model, config)

Starting points:

  • Rank: 4–8 for simple tasks, 16–32 for general use, 64+ for heavy adaptation
  • Alpha: often 2 × rank
  • Target modules: attention projections first; add MLP layers (gate_proj, up_proj, down_proj) if quality is not enough

QLoRA (Quantized LoRA)

QLoRA loads the base model in 4-bit precision and trains LoRA adapters on top. It brings fine-tuning of mid-sized models within reach of a single GPU.

Key ideas: 4-bit NormalFloat (NF4) quantization, double quantization of the scaling constants, and paged optimizers that avoid out-of-memory spikes.

python
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig

BASE_MODEL = "your-org/open-weights-model"  # an open-weights model you are licensed to fine-tune

bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
)

model = AutoModelForCausalLM.from_pretrained(
    BASE_MODEL, quantization_config=bnb_config, device_map="auto"
)

Approximate GPU memory for training:

Method7B model70B model
LoRA (16-bit base)~16–20 GB~150+ GB
QLoRA (4-bit base)~6–10 GB~48 GB

Choosing a base model

Fine-tuning requires a model whose weights you can download and whose license allows commercial adaptation. The current open-weights generation includes models from Mistral AI, DeepSeek, Moonshot AI, Alibaba Qwen and OpenAI (gpt-oss). Smaller variants are usually the practical choice: cheaper to train, cheaper to serve, and easier to host in your own data center. Read the license before you start, not after.

Hosted providers also offer fine-tuning APIs for some of their models. That avoids running GPUs, but your training data leaves your infrastructure, which matters for personal data under KVKK and GDPR.

Training Data Strategy

Data quality decides the outcome far more than hyperparameters.

Formats

json
{"messages": [
  {"role": "system", "content": "You classify incoming supplier emails."},
  {"role": "user", "content": "Subject: Revised delivery date for PO 4471 ..."},
  {"role": "assistant", "content": "{\"category\": \"delivery_change\", \"po\": \"4471\"}"}
]}

What good data looks like

  • Representative: drawn from the real distribution of cases, including the messy ones
  • Consistent: one format, one labeling guideline
  • Accurate: reviewed labels; a few hundred clean examples beat thousands of noisy ones
  • Sized to the task: often 1,000–10,000 examples for a narrow task

Synthetic data

Licensing uncertainty and privacy rules limit what real data you can use. Synthetic data, generated by a stronger model from templates and seed examples, helps in three places:

  • Rare edge cases that hardly appear in real data (unusual document layouts, rare complaint types)
  • Privacy-sensitive domains where real records cannot be used for training
  • Bootstrapping a dataset before enough real examples exist

The trade-off: synthetic data drifts away from the real distribution if you rely on it alone. A balanced approach:

  1. Use real data as the backbone and as the evaluation set.
  2. Use synthetic data to fill gaps and cover edge cases.
  3. Compare model quality on real held-out data with and without the synthetic part.
  4. Check the terms of service of the model you use to generate data; some restrict using outputs to train other models.

Licensing and compliance checklist

  • Do you have the right to use each data source for training?
  • Does the data contain personal data? If yes, is there a legal basis, and can it be anonymized?
  • Are the base model's license and the data generator's terms compatible with your use?
  • Document these assumptions; auditors and customers will ask.

Training Setup

python
from transformers import TrainingArguments

training_args = TrainingArguments(
    output_dir="out",
    learning_rate=2e-4,              # typical for LoRA
    num_train_epochs=3,
    per_device_train_batch_size=4,
    gradient_accumulation_steps=4,
    warmup_ratio=0.03,
    lr_scheduler_type="cosine",
    bf16=True,
    logging_steps=10,
    save_strategy="epoch",
    eval_strategy="epoch",
    weight_decay=0.01,
    max_grad_norm=1.0,
)

Learning-rate ranges that usually work:

  • Full fine-tuning: 1e-5 to 5e-5
  • LoRA: 1e-4 to 3e-4
  • QLoRA: 2e-4 to 5e-4

Evaluation

  • Use task metrics on a held-out real test set: accuracy, F1, field-level exact match.
  • Compare against the base model with a good prompt. If fine-tuning does not clearly beat it, do not ship it.
  • Watch for overfitting: training loss falls while validation loss rises. Fix with early stopping, more data, fewer epochs or more dropout.
  • Re-run general sanity checks to catch catastrophic forgetting.

Deployment

python
# Merge the adapter into the base model for simple serving
merged = model.merge_and_unload()
merged.save_pretrained("merged_model")

Or keep adapters separate and serve several tasks from one base model; serving engines such as vLLM support multi-adapter setups.

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│ Data        │────▶│ Training    │────▶│ Evaluation  │
│ preparation │     │ (LoRA/QLoRA)│     │ & testing   │
└─────────────┘     └─────────────┘     └──────┬──────┘
                                                │
                    ┌─────────────┐     ┌──────▼──────┐
                    │ Production  │◀────│ Model       │
                    │ deployment  │     │ registry    │
                    └─────────────┘     └─────────────┘

Common Problems

ProblemFix
Out of memoryQLoRA, gradient checkpointing, smaller batches
Catastrophic forgettingLower learning rate, mix in general data, smaller rank
OverfittingMore data, regularization, early stopping
Poor generalizationMore varied examples and instructions

Summary

Fine-tune when a narrow, high-volume task needs consistency or when you want a small model running on your own infrastructure. Use LoRA or QLoRA to keep it affordable, build the dataset from real cases with synthetic data only where it fills gaps, and settle licensing and privacy before training starts.

Veni AI helps companies decide between prompting, RAG and fine-tuning, and builds the pipeline end to end when fine-tuning is the right call. See our services or talk to our team.

Keep reading

Have a process that should run on AI?

Describe one process as it runs today, and we'll show you which repetitive steps an AI application or agent could handle.