Fine-Tuning LLMs

Instruction Tuning and SFTfine tuningsupervised fine-tuning on prompt and response pairs: data formats, chat templates and loss masking. LoRA and QLoRAfine tuninglow-rank adapters and 4-bit quantised training for fine-tuning large models on modest hardware. Knowledge Distillationfine tuningtraining a small student model to reproduce a large teacher's behaviour. RLHFreinforcement learningreinforcement learning from human feedback: reward models and policy optimisation for alignment. Fine-Tuning in Snowflake Cortex AIcortexpretraining versus fine-tuning, and managed fine-tuning inside Snowflake.

Fine-tuning adapts a pretrained large language model to a task, a domain or a style of behaviour by continuing training on a smaller, targeted dataset. This section covers the main methods, how they fit together, and when fine-tuning is the right tool at all.


1. Overview

A pretrained LLM has learned language and a great deal of world knowledge by predicting the next token over a huge corpus, but it is not yet a helpful assistant and knows nothing about your private data or formats. Fine-tuning updates the model's weights, all of them or a small added set, using examples of the behaviour you want. It is one of three main levers for changing what a model does, alongside prompt engineering and retrieval-augmented generation (retrieval).

From Base Model to Deployed Assistant Pretrained base next-token on web text Instruction tuning SFT on prompt / answer pairs Preference tuning RLHF, DPO Deployed model task- or domain-ready LoRA / QLoRA train small adapters, any stage Distillation teacher -> smaller student Solid arrows: the usual sequence. Dashed: techniques that make a stage cheaper or the result smaller.

Instruction tuning (supervised fine-tuning, SFT) teaches the model to follow instructions using prompt and response pairs. Preference tuning then aligns outputs with human judgements: RLHF trains a reward model from human comparisons and optimises the policy with reinforcement learning, while Direct Preference Optimization (DPO) optimises directly on preference pairs without a separate reward model. Parameter-efficient fine-tuning such as LoRA freezes the base weights and trains small low-rank adapters, cutting memory needs dramatically; QLoRA adds 4-bit quantisation of the frozen base so that large models fit on a single GPU. Knowledge distillation trains a smaller student model to imitate a larger teacher, trading a little quality for much cheaper inference.

2. When to Fine-Tune

Fine-tuning is often reached for too early. A useful rule: use prompting first, add retrieval when the model needs facts it does not have or that change often, and fine-tune when you need a consistent behaviour, format or style that prompting cannot reliably produce, when you want to shrink prompts to cut cost and latency, or when you want a smaller model to match a larger one on a narrow task. Fine-tuning is a poor way to add frequently changing knowledge, because every update means retraining and the model may still hallucinate details.

3. Decision Table

GoalBest first toolWhy
Answer from private, changing documentsRAGFresh data without retraining; citations possible
Consistent output format or toneSFT with LoRABehaviour is learned, prompts get shorter
Follow instructions at all (from a base model)Instruction tuningBase models only continue text
Prefer helpful, harmless answersPreference tuning (RLHF, DPO)Optimises for judged quality, not imitation
Fit training on one GPUQLoRA4-bit frozen base plus small adapters
Cut inference cost on a narrow taskDistillationSmaller student imitates large teacher
Quick experiment, no training budgetPrompting, few-shot examplesZero training cost; iterate in minutes

Whatever you choose, build an evaluation set before training: a few hundred held-out prompts with reference answers or rubric-based grading, so you can show the fine-tuned model is actually better than a well-prompted base model.

LLM EngineeringSectionparent section TransformersSectionthe architecture being fine-tuned Prompt Engineeringllm engineeringtry this first LLM ProductionSectionserving and evaluating the result

5. Further Reading