← AI Practitioner study path

Applications with foundation models · 9 min

Which way of customizing a model is the right one?

In this lesson you will learn the ways to adapt a foundation model ordered by cost, which ones change the model's weights and which ones don't, what Amazon Bedrock charges for a custom model and which technique suits each scenario.

Customizing a means adapting it to your use case, for example so that it classifies an insurance company's claims into its own categories of billing, service and cancellation. Without that adaptation, the model can make up categories the insurance company doesn't use, such as "general complaint". Task 3.1.5 of the exam guide asks you to choose how to make that adaptation, and there are several ways that work: training your own model, tuning one that already exists or writing a good . However, these ways differ widely in cost and time, so to choose well you have to know where the spending goes.

Techniques for adapting a model

Ways to adapt a model, from lowest to highest cost

The techniques for adapting a model fall into two groups. In the two cheapest ones, the model stays the same and what changes is what you send it. In the rest, the model's weights change, which are the numbers it learned in its training. From lowest to highest cost, the six techniques are these:

  • In-context learning, which puts instructions and examples inside the prompt (zero-shot or few-shot), where you test a change in minutes and pay for the of each call.
  • RAG, which adds your documents to the prompt before calling the model and which on AWS is done with Amazon Bedrock Knowledge Bases.
  • Fine-tuning, which continues training a model with labeled data (input and output pairs, such as a claim along with its correct category) for a task or a format.
  • Distillation, where a large model generates responses and those responses are used to tune a smaller, cheaper one.
  • Continued pre-training, which continues the model's pre-training with many unlabeled documents from your domain, that is, from your field of work, such as insurance or medicine.
  • Pre-training from scratch, which consists of creating the whole model.

For example, the insurance company does in-context learning if it puts the three categories and two already classified claims in the prompt, and it does fine-tuning if it trains the model with thousands of claims that its employees already classified. In the first case the model stays the same, and in the second there is a new model that belongs to the insurance company.

The Generative AI Lens of the places all of these techniques in the same phase of the lifecycle, model customization. The Generative AI Lens also says that these techniques can be combined, for example a fine-tuned model that also receives documents with RAG.

Does it change the model's weights?

0 of 5

Tap the column that matches each technique.

  1. Add three solved examples to the prompt

  2. Connect a knowledge base with the company's manuals

  3. Train with 5,000 labeled claims

  4. Transfer what a large model knows to a small one

  5. Continue training with millions of unlabeled contracts

How much does it cost to change the weights?

The three Amazon Bedrock charges for a custom model: training, storage and inference

The techniques that change the weights require you to prepare the data, pay for the training and wait for it to finish, and in the end they leave you with a model that you have to store and pay for. According to its documentation, Amazon Bedrock charges for three things for a custom model:

  1. Training, which is charged for the tokens in your data multiplied by the number of epochs, where an epoch is one full pass through the data.
  2. Storage, which is a monthly fee for each custom model, whether you use it or not.
  3. , which is paid with Provisioned Throughput, dedicated capacity that is charged by the hour, or with an on-demand deployment that is charged for what you use.

Since training is charged per epoch, with three epochs you pay three times for the tokens in your data. The Bedrock pricing page has a complete example with Llama 2 13B, which charges 1.49 USD per million training tokens, 1.95 USD a month to store the model and 21.18 USD per hour of Provisioned Throughput with a one-month commitment. With those prices, a file of one million tokens trained for three epochs costs 4.47 USD, while keeping the model running for the 720 hours of a month costs about 15,250 USD. For example, for the insurance company the training would be the cheap part, and the expensive part would be keeping the model available all month to classify its claims.

The most expensive technique is pre-training from scratch. AWS says that developing a foundation model from scratch costs millions of dollars and that training can take months, so this technique is left to model providers. For example, instead of creating its own model, an insurance company adapts one of the models that Amazon Bedrock already offers.

cloud path tip: if an exam option proposes training your own model from scratch, rule it out first when the question is looking for the lowest cost or effort, because it is the most expensive and slowest technique of all.

Where do you start customizing a model?

The Amazon SageMaker AI documentation gives an order for trying these techniques. Prompt engineering comes first, which doesn't change the weights, and if that is not enough, fine-tuning. When what the model lacks is information from a knowledge library, such as a company's manuals or policies, the technique is RAG, which doesn't retrain anything either.

With that order, the first step for the insurance company is a prompt that names the categories and includes a few examples. From there, each problem that comes up calls for a different technique:

  • The categories depend on policies that get updated, which is a case for adding RAG.
  • The insurance company classifies millions of claims a month and the prompt with examples gets expensive or fails on unusual cases, which is a case for fine-tuning with its labeled claims.
  • The insurance company already uses a large model that classifies well but costs a lot, which is a case for trying distillation.

Match each scenario with the technique

0 of 5 pairs

Tap a scenario and then the technique that suits it.

0 of 5 pairs.

On the exam

In the questions for this task, first decide whether the scenario calls for changing the model's weights. The phrases "without retraining", "with the least effort" or "data that changes often" point to the techniques that don't change them, that is, to prompts or to RAG. On the other hand, "change the model's behavior" or "learn a style or a task with thousands of examples" point to the techniques that do change them. For example, if the question says that a school wants its assistant to answer with the rules that change every semester without retraining, the answer is RAG.

Among the techniques that change the weights, these phrases tell one technique from another:

  • "Unlabeled domain data", which points to continued pre-training.
  • "Labeled examples of a task", which points to fine-tuning.
  • "Cheaper and faster with similar quality", which points to distillation.

cloud path tip: in an account on the new AWS experience, Amazon Bedrock is on the free plan and you can try the techniques that don't change the weights, but not the ones that do. According to the Bedrock documentation, the models that can be customized are in us-east-1 or us-west-2, and that account stays fixed in the us-east-2 , so you won't see any models for fine-tuning there. In a full account you do see them, by choosing the model's Region.

Review question

A store wants its assistant to answer with the product catalog, which changes every week, and it is looking for the lowest cost and effort. What should it use?

Next