Lesson 4 of 5 Amazon Bedrock

Customising Foundation Models with Fine-Tuning and Continued Pre-Training

This lesson explains how to customise a foundation model with your own data when prompt engineering and RAG are not enough. Each method needs different data, costs a different amount and gives a different result.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish fine-tuning, continued pre-training and distillation by the data each needs.
  • Define domain adaptation and transfer learning.
  • Order the ways of customising a model by cost.
  • Describe the qualities of good customisation data.

Customisation methods

Foundation models can be customised in several ways, which need different data. Fine-tuning trains the model on labelled examples of prompts and ideal completions, such as 1,000 support questions with their best answers, producing a model specialised for that task, format or style. Instruction tuning is fine-tuning on instructions and responses, which makes a model better at following instructions. Continued pre-training trains on large amounts of unlabelled text from a domain, such as medical papers, so the model learns that domain's vocabulary and knowledge.

Distillation uses the responses of a large teacher model to train a smaller student model, which is faster and cheaper for one use case. Reinforcement fine-tuning improves behaviour from feedback or reward signals rather than fixed correct answers. The following table summarises the methods.

MethodData neededResult
Fine-tuningLabelled prompt-completion pairs, e.g. 1,000 support questions with ideal answersA model specialised for a task, format or style
Instruction tuningInstructions with their responsesBetter at following instructions
Continued pre-trainingLarge amounts of unlabelled domain data, e.g. medical papersA model that knows the domain's vocabulary and knowledge
DistillationResponses generated by a large teacher modelA smaller, faster, cheaper student model for one use case
Reinforcement fine-tuningFeedback or reward signalsImproved behaviour without fixed answers

Bedrock creates a private copy of a customised model that only you can use. Depending on the model, serving it may need Provisioned Throughput or on-demand custom model inference.

Scenario questions

Choosing a customisation method

Exam skills 3.1.5 · 3.3.2

Choose the customisation method for each situation.

Log in to try this activity Interactive activities are free with an account.

Related terms

Three further terms are common in discussions of customisation. Domain adaptation means making a general model work better in a specialised field, such as law or medicine, for example through continued pre-training. Transfer learning means reusing what a model learned on one task as the starting point for a new, related task, which needs far less data than training from scratch and is the idea behind fine-tuning. RLHF (reinforcement learning from human feedback) aligns a model with human preferences by training it on people's ratings of its responses. The following table summarises the terms.

TermMeaning
Domain adaptationMaking a model work better in a specialised field
Transfer learningReusing what a pre-trained model learned on a new, related task
RLHFAligning a model with human preferences using people's ratings of its responses
Match the pairs

Customisation terms

Exam skills 3.3.1 · 3.3.2

Match each term with its meaning.

Log in to try this activity Interactive activities are free with an account.

From cheapest to most expensive

The methods of customising a foundation model differ considerably in cost and effort. In ascending order of cost, they are as follows.

  1. Prompt engineering and in-context learning

    Examples in the prompt.

  2. RAG

    Retrieve your documents at question time; no training.

  3. Fine-tuning

    Train on a modest set of labelled examples.

  4. Continued pre-training

    Train on large volumes of unlabelled domain text.

  5. Training from scratch

    Pre-train a new model on very large data, at a cost of millions of dollars.

Custom models add training and hosting costs and need ongoing maintenance as base models improve.

The following diagram ranks the methods by relative cost.

Ways to customise a foundation model, from cheapest to most expensive. Prompt engineering and in-context learning put examples in the prompt. RAG retrieves your documents at question time with no training. Fine-tuning trains on a modest set of labelled examples. Continued pre-training uses large volumes of unlabelled domain text. Training from scratch pre-trains a new model on very large data at a cost of millions of dollars. Custom models also add hosting and maintenance costs.
Try the cheaper methods first.
Put in order

The cost ladder

Exam skills 3.1.5

Put the ways of improving a model's output in order, from the cheapest to the most expensive.

Log in to try this activity Interactive activities are free with an account.

Preparing data

Customisation data must be:

  • Curated, accurate and consistently labelled.
  • Representative of real use, and of an appropriate size.
  • Free of sensitive data you do not want the model to learn.
  • Governed, with known lineage, consent and licensing.

Hold back some evaluation data to measure the improvement.

Select all that apply

Fine-tuning data

Exam skills 3.3.3

A team is preparing 5,000 examples to fine-tune a model for claims summaries.

Log in to try this activity Interactive activities are free with an account.
Worked example

Choosing between prompting, RAG and customisation

A software company works through four requirements for its support assistant, using the cheapest method that meets each:

RequirementMethodReason
Answer in a friendly tone, in under 100 wordsPrompt engineeringInstructions in the system prompt are enough
Know the details of this month's product release notesRAG (Knowledge Bases)Knowledge that changes often
Always reply in the company's strict ticket format, with its own category codesFine-tuning on 2,000 example ticketsA consistent behaviour that prompting does not achieve reliably
Cut cost for 5 million simple classification requests a monthDistillation into a smaller modelA cheaper student model imitates the large teacher model for this one task

Continued pre-training was considered and rejected: it suits teaching a model a whole domain's vocabulary from large amounts of unlabelled text, which this company does not need. Each customised model is private to the company's account.

Check yourself

What data does continued pre-training use, compared with fine-tuning?

Show answer

Continued pre-training uses large amounts of unlabelled domain text, which teach the model a field's language. Fine-tuning uses labelled prompt and response pairs for a specific task.

Exam Tips

Remember for the exam

  • Labelled prompt-completion examples for a task or style call for fine-tuning.
  • Large volumes of unlabelled domain documents call for continued pre-training.
  • A smaller, cheaper model that imitates a larger one is produced by distillation.
  • The cheapest ways to improve output are prompt engineering first, then RAG.
  • To align a model with human preferences, use RLHF.
  • Fine-tuned Bedrock models are private to your account.