GCP-110 · Lesson 7 of 12 · 18 min

Fine-tuning and other ways to adapt a model

▶ Video coming soon A video version of this lesson is on the way.

By early December the description writer is working well with a prompt template and each product's specifications. One complaint remains. The descriptions are accurate, but they do not quite sound like Birchline. The copy team has a distinctive voice, dry and practical with a small joke now and then, built over twenty years of catalogues, and the model keeps drifting back to generic marketing language. Jules asks whether they should "train the model on our catalogue". Ravi says that might be the right answer eventually, but that there is a ladder of options to climb first. This lesson walks up that ladder.

The adaptation ladder

Adapting a model means changing its behaviour for a specific use. The techniques differ in what they change, how much data and effort they need, and what they cost. Ravi draws them as a ladder: start at the bottom and climb only when the rung below is not enough.

A ladder of adaptation techniques from bottom to top: prompt design, few-shot examples, grounding with RAG, prompt tuning, parameter-efficient fine-tuning, full fine-tuning, and training a model from scratch, with arrows showing effort and cost increasing upward.
Climb the adaptation ladder only as far as the task needs: each rung adds effort, data and cost.
  • Prompt design (lesson 5): change the instructions. No training, instant iteration.
  • Few-shot examples: show the model what good output looks like inside the prompt.
  • Grounding and RAG (lesson 6): give the model facts it lacks at request time.
  • Prompt tuning: learn a small set of special input values that steer the model, without changing its weights.
  • Parameter-efficient fine-tuning: train a small number of extra or selected parameters on task examples.
  • Full fine-tuning: retrain all of the model's parameters on task data.
  • Training from scratch: build a new foundation model, which almost no business needs.

The key distinction is between techniques that change what the model sees (prompts, examples, grounding) and techniques that change the model itself (the tuning methods). Changing what the model sees is cheaper, faster, easier to update and easier to reverse. Changing the model can teach behaviour that is hard to describe in a prompt, but it needs data, evaluation, versioning and ongoing maintenance.

What fine-tuning is

Fine-tuning continues training a pre-trained model on a smaller, task-specific dataset, adjusting its parameters so it performs that task better. The most common form for business use is supervised fine-tuning: the training data is a set of input and output pairs showing exactly what the model should produce. For Birchline, each pair would be a product's specifications as input and the copy team's approved description as output.

Fine-tuning teaches behaviour: style, tone, format, domain vocabulary and how to handle a specialized kind of task consistently. It is good at making a model write like the copy team, classify emails into Birchline's specific queues with fewer examples in each prompt, or follow a complex output format reliably. It is not a good way to teach facts that change, such as prices, stock or this season's policy. Facts learned in tuning are hard to update and easy to misremember, so changing facts belong in grounding.

Ravi puts the rule on the whiteboard in large letters: tune for behaviour, ground for knowledge. Jules notices that the copy team's voice is behaviour, while the tents' specifications are knowledge. The two techniques work together: a tuned model for the voice, grounded on each product's real specifications for the facts.

Choosing between grounding and tuning.
NeedBetter solved byWhy
Use current prices and stockGrounding or tool callsFacts change daily; tuning would be stale immediately
Answer from this season's policiesRAG over the policy documentsPolicies change; re-indexing is instant
Write in Birchline's distinctive voiceFine-tuning (after prompting and examples)Style is hard to describe fully in a prompt
Follow a strict output format every timeResponse schemas, then tuning if neededSchemas enforce format; tuning improves consistency
Classify emails into Birchline's queuesFew-shot prompting, then tuning a small model at volumeTuning can let a small, cheap model match a larger one

Parameter-efficient tuning

Full fine-tuning updates every parameter of a model, which for a large model means enormous compute and a full new copy of the model to store and serve. Parameter-efficient fine-tuning (PEFT) methods update only a small fraction. A widely used method, low-rank adaptation (LoRA), keeps the original weights frozen and trains small additional matrices that adjust the model's behaviour. The trained adapter is tiny compared with the model, cheap to train and store, and can be swapped in and out, so one base model can serve several tuned behaviours.

Most managed tuning services on cloud platforms use parameter-efficient methods behind the scenes. On Google Cloud, the Gemini Enterprise Agent Platform offers supervised tuning of supported Gemini models and tuning of open models such as Gemma; GCP-111 covers the products. For a leader, what matters is that tuning a hosted model is now a matter of preparing good examples and running a managed job, not of building infrastructure.

Prompt tuning, sometimes called soft prompting, is lighter still. Instead of changing the model's weights, it learns a short sequence of numerical vectors that are placed in front of every input, acting like a learned prompt that no person could write in words. It needs less data than fine-tuning and leaves the model untouched. The exam guide lists prompt tuning among core terms, so Jules notes the distinction: prompt engineering writes words; prompt tuning learns vectors.

Python Example
# Rough comparison of trainable parameters: full fine-tuning vs a LoRA adapter.
# Illustrative model shape, not a real Gemini or Gemma configuration.
layers, hidden = 32, 4096
full = layers * 12 * hidden * hidden          # rough count of a transformer's main weights

rank = 8                                      # LoRA rank
adapted_matrices_per_layer = 4                # e.g. attention projections
lora = layers * adapted_matrices_per_layer * 2 * hidden * rank

print(f"full fine-tuning updates about {full / 1e9:.1f} billion parameters")
print(f"a rank-{rank} LoRA adapter trains about {lora / 1e6:.1f} million parameters")
print(f"that is about 1 in {round(full / lora):,} of the full count")
Output
full fine-tuning updates about 6.4 billion parameters
a rank-8 LoRA adapter trains about 8.4 million parameters
that is about 1 in 768 of the full count

What this code does

Using an illustrative model shape, the program estimates how many weights full fine-tuning would update and how many a small LoRA adapter trains instead. The adapter's count comes from a few small matrices added to each layer. It trains about 1 in 768 of the parameters, which is why it is far cheaper.

Other ways models are adapted

Three further techniques appear in discussions of adaptation, and leaders should recognize them.

Reinforcement learning from human feedback (RLHF) and related preference methods train a model on people's judgements of which of two responses is better. Model builders use them to make assistants more helpful and safer. Organizations rarely run them themselves, but the idea explains why human review data, such as thumbs-up and thumbs-down ratings on an assistant's answers, is valuable: it can feed future improvements.

Distillation trains a smaller "student" model to imitate a larger "teacher" model's outputs. The student is cheaper and faster to run while keeping much of the teacher's skill on the target task. Birchline might, in time, distil its email-sorting behaviour from a large model into a small one to cut costs at high volume.

Continued pre-training trains a model further on large amounts of unlabelled text from a specialized domain, such as medical literature, before task tuning. It is expensive and suited to organizations with vast domain-specific text and needs a general model does not meet.

What tuning needs

If the ladder leads to tuning, the work shifts to data. Ravi lists what Birchline would need for the brand-voice model.

  • Examples: a set of high-quality input and output pairs. Managed services often accept tuning with a few hundred examples, and more good examples generally help; quality matters far more than quantity. Birchline has about 2,000 copy-team descriptions from the last three seasons.
  • Cleaning: remove descriptions of discontinued products with outdated claims, fix errors, and exclude anything that should not be learned, such as personal information or confidential supplier terms.
  • Held-out evaluation set: keep a portion of examples out of training to test whether tuning actually helped (lesson 9).
  • Baseline: measure the best prompt-only result first, so the team knows what tuning adds.
  • Ownership and versioning: a tuned model is a new asset. It needs an owner, a version number, a record of the data used and a plan for retuning when the base model is updated or retired.

Jules realizes that the last point is easy to forget. Base models are updated and older versions retired on a published schedule, and a tuned model built on a retired base must be retuned and re-evaluated. Prompt-only and RAG solutions also need retesting when the base model changes, but they carry less to redo.

Costs and trade-offs

Tuning has three kinds of cost. The tuning job itself, charged by the amount of training data processed. The serving cost, which for some tuned models differs from the base model's. And the people and process costs of preparing data, evaluating results and maintaining versions, which are usually the largest. Against those, tuning can reduce costs: a tuned model may need shorter prompts (fewer few-shot examples on every request), and a tuned small model may replace a large one.

Python Example
# When does tuning a small model pay off against few-shot prompting a large one?
# All prices are illustrative, in US dollars per million tokens.
large_in, large_out = 1.25, 10.00
small_in, small_out = 0.10, 0.40
requests = 20_000                     # emails per month
fewshot_prompt, tuned_prompt, output = 1_200, 250, 20
tuning_job_once = 150.0               # illustrative one-time tuning charge

large_month = requests * (fewshot_prompt * large_in + output * large_out) / 1e6
tuned_month = requests * (tuned_prompt * small_in + output * small_out) / 1e6
print("large model with few-shot prompt, per month:", round(large_month, 2))
print("tuned small model, per month:", round(tuned_month, 2))
print("months to recover the tuning job:", round(tuning_job_once / (large_month - tuned_month), 1))
Output
large model with few-shot prompt, per month: 34.0
tuned small model, per month: 0.66
months to recover the tuning job: 4.5

What this code does

Using illustrative prices, the program compares a month of email sorting with a large model and a long few-shot prompt against a tuned small model with a short prompt. It also includes a one-time tuning charge. The tuned model costs far less per month and recovers the tuning cost in about four and a half months.

With these illustrative numbers the tuning job pays for itself in a few months, but only if the tuned small model is as accurate as the large one, which the evaluation must show. Ravi's point is the method, not the numbers: compare total cost, including people's time, against measured quality.

Common mistakes

  • MistakeFine-tuning to teach facts that change.

    InsteadTune for behaviour; ground for knowledge such as prices, stock and policies.

  • MistakeStarting with tuning.

    InsteadClimb the ladder: prompts, examples and grounding first, tuning only when they fall short.

  • MistakeTuning without a baseline or held-out test set.

    InsteadMeasure the best prompt-only result and test tuning on examples it never saw.

  • MistakeTreating a tuned model as finished.

    InsteadIt needs an owner, versioning and retuning when the base model changes.

  • MistakeConfusing prompt tuning with prompt engineering.

    InsteadPrompt engineering writes words; prompt tuning learns input vectors.

Preparing a tuning dataset

Jules asks what a tuning example actually looks like. Ravi opens a sample: each line of the file is one example with an input, the product's specifications in the same format the production prompt uses, and an output, the approved description. Consistency matters. If half the examples include a heading and half do not, the tuned model will be inconsistent too. The inputs should look exactly like what the model will see in production, so that it learns the real task. And the outputs should be the best examples available, because the model will imitate their quality, including any mistakes. Ravi's team spends more time choosing and cleaning the 2,000 descriptions than it expects to spend on the tuning job itself.

Worked problem

Climbing the ladder for the brand voice

Birchline wants descriptions in the copy team's voice, always accurate to the specifications. Walk up the ladder and decide where to stop.

Show solution
  1. Prompt design: describe the voice in the system instructions. Result: better, but drifts on long items.
  2. Few-shot examples: add three approved descriptions to each prompt. Result: closer, but costly in tokens at catalogue scale and still uneven.
  3. Grounding: already in place for specifications, which handles accuracy but not voice.
  4. Supervised fine-tuning with a parameter-efficient method on about 2,000 cleaned descriptions, with a held-out set of 200 to compare against the few-shot baseline.
  5. Keep grounding for specifications on the tuned model, so facts stay current.

Answer: Stop at parameter-efficient fine-tuning for voice, combined with grounding for facts, adopted only if the held-out evaluation beats the few-shot baseline.

Summary and key terms

  • Adapting a model ranges from prompt design, examples and grounding, which change what the model sees, to prompt tuning, parameter-efficient fine-tuning, full fine-tuning and training from scratch, which change the model.
  • Climb only as far as needed.
  • Fine-tuning continues training on task examples and is best for behaviour such as style, tone and format; grounding is best for changing facts.
  • Parameter-efficient methods such as LoRA train small adapters instead of all weights.
  • Prompt tuning learns input vectors without changing weights.
  • RLHF, distillation and continued pre-training are further techniques.
  • Tuning needs clean examples, a baseline, a held-out test set, ownership and retuning when base models change.
Fine-tuning
Continuing a pre-trained model's training on task-specific data.
Supervised fine-tuning
Fine-tuning on input and desired output pairs.
Parameter-efficient fine-tuning (PEFT)
Tuning only a small fraction of a model's parameters.
LoRA
Low-rank adaptation: training small adapter matrices while freezing the base weights.
Prompt tuning
Learning soft prompt vectors placed before inputs, without changing model weights.
Distillation
Training a smaller student model to imitate a larger teacher.
Held-out set
Examples kept out of training to test the tuned model.
Baseline
The result of the simplest approach, used for comparison.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Should Birchline fine-tune a model on this week's prices?

    Show answer

    No. Prices change constantly; supply them by grounding or tool calls.

  2. What is the main advantage of LoRA over full fine-tuning?

    Show answer

    It trains a tiny adapter instead of all weights, so it is cheaper to train, store and swap.

  3. Why keep a held-out set when tuning?

    Show answer

    To test the tuned model on examples it never saw and compare it fairly with the baseline.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz