ContextJet AIContextJet AI
  1. 01Capabilities
  2. 02Work
  3. 03Process
  4. 04Team
  5. 05About
  6. 06Terms
  7. 07Blog
  8. 08Contact
takeoff@contextjetai.servicesSan Diego · Dubai · Bengaluru
Work  /  Project 10

LLM Fine-tuning Framework

Domain-specific model tuning with LoRA and Q-LoRA, built as a repeatable framework rather than a one-off experiment.

Applied Research  ·  3 min read
LLM Fine-tuning Framework

Sector

Applied Research

Stack

LoRA, Q-LoRA, PyTorch

The problem

General-purpose language models are very good at general-purpose text. Domain-specific generation is harder. When terminology, format and tone have to be right every time, prompting alone often is not enough: the model keeps drifting back toward how it writes in general.

Fine-tuning closes that gap by adapting the model itself. But fine-tuning is frequently done as a series of one-off experiments. Each run uses slightly different data and settings, results are hard to reproduce, and six months later nobody can say exactly how a given model was produced or whether a new one is actually better.

What we built

A repeatable framework for fine-tuning language models on domain-specific generation, used across multiple industries. It turns fine-tuning from an experiment into a process that a team can run again, compare and improve. The work covered model optimization and custom training pipelines.

How it works

The models

The framework has been used to fine-tune GPT-3.5, Llama 2 and flan-t5. Supporting several model families matters, because the right base model depends on the task, the deployment constraints and the cost of running it.

Parameter-efficient tuning: LoRA and Q-LoRA

Fully retraining a large model means updating billions of parameters, which is expensive in compute and memory. LoRA (low-rank adaptation) takes a different approach: it leaves the original model’s weights unchanged and trains a small number of additional parameters that adjust its behaviour. The result captures most of the benefit of fine-tuning at a fraction of the cost.

Q-LoRA goes further by loading the base model in a compressed, quantized form while training the adapters. That reduces memory requirements enough to fine-tune larger models on far more modest hardware.

Few-shot learning

Where labelled data is limited, few-shot learning lets a model learn a task from a small number of examples. It is useful early on, before enough data exists for a full fine-tuning run.

Built on PyTorch

The training pipelines are built on PyTorch.

Why a framework rather than a script

The value of a framework is repeatability. When the data, settings and evaluation are captured consistently, two things become possible that one-off experiments do not allow.

  • Honest comparison. A new model can be compared fairly against the current one, on the same evaluation, so improvement is measured rather than assumed.
  • Reproducibility. Any model can be traced back to exactly how it was produced, which matters for debugging and for anyone who inherits the system.

When fine-tuning is the right call

Fine-tuning is not our default. We reach for it only after cheaper approaches have been tried. In rough order:

  1. Better prompting. Clear instructions and good examples solve more problems than people expect.
  2. Retrieval. If the model lacks knowledge, give it the right documents at question time. Retrieval is usually better than fine-tuning for knowledge, because knowledge changes and retrieval stays current.
  3. Fine-tuning. When the model has the knowledge but needs to behave differently, in format, tone or terminology, consistently, fine-tuning is the right tool.

Treating it as a repeatable framework is what makes that decision cheap to revisit as base models improve.

Where it can go wrong

  • Poor training data. A fine-tuned model learns whatever is in its data, including its mistakes. Data quality matters more than quantity.
  • Overfitting. A model tuned too narrowly can lose general ability it still needs.
  • Evaluating on the wrong thing. Improvement on a convenient test set is not improvement on the real task. Evaluation has to reflect real use.

Questions to ask before building one

If you are considering a system like this, these are the questions we would want answered first.

  1. Have you exhausted prompting and retrieval? Fine-tuning should be the answer to a problem those could not solve.
  2. Is your need knowledge or behaviour? Retrieval is usually better for knowledge; fine-tuning is better for consistent behaviour.
  3. Do you have good training examples? A few hundred excellent examples beat thousands of mediocre ones.
  4. How will you know the new model is better? Define the evaluation before the first training run.
← All projects
Next step

Ready to build AI that performs?

Tell us the problem and what needs to change. We will say honestly whether AI is the right instrument for it, or something else and how we would approach the solution.