Papa Programmer
Lesson 20 of 20

Choosing a model for a task

9 min read

Optional

Start with your test, not a leaderboard

Public benchmarks, such as MMLU, a test of multiple-choice questions on 57 subjects, rank models by general skill. Your task is narrower. A model that ranks lower overall can be the better choice for sorting your support emails, and it can cost far less.

Before you compare models, build an Evaluation setA list of tasks, each with a way to check the result, that you run again after every change to an agent. You measure how often the agent gets each task right.. Collect 20 to 50 real inputs and write down the answer you expect for each. Include the hard cases you already know about. This set decides which model you choose.

What to compare

Compare each Large language modelA model trained on a huge amount of text to predict the next token. Chat replies, summaries and code all come from repeating that prediction. Often shortened to LLM. on five things.

  • Quality. How many items in your evaluation set it gets right.
  • Cost. Providers charge for each million input tokens and each million output tokens. Output tokens usually cost more.
  • Speed. The time to the first token, and the number of tokens per second after that.
  • Context window. Whether your longest prompt and reply fit.
  • Data and licence. Where your data goes, and what the model's licence allows. Some open models use the Apache 2.0 licence. Others, such as Llama, use their own licence with extra conditions.
Open-weight modelHosted model
DataStays on your serversSent to the provider
CostHardware and running it yourselfA price for each token
Quality ceilingLimited by the hardware you haveThe provider's largest models
ControlFixed version, fine-tune freelyThe provider may update or retire a version
Open-weight models and hosted models trade different things

A small evaluation in code

The program below compares two stand-in models on four support messages. The functions take the place of real models so that you can run it. The prices are made-up example numbers, not any provider's real prices.

python
cases = [
	("I want my money back", "refund"),
	("Where is my parcel?", "delivery"),
	("The app crashes on start", "bug"),
	("Can I change my delivery address?", "delivery"),
]

def small_model(text):
	return "refund" if "money" in text else "delivery"

def large_model(text):
	if "money" in text:
		return "refund"
	if "crash" in text:
		return "bug"
	return "delivery"

models = {"small": (small_model, 0.10), "large": (large_model, 3.00)}

for name, (model, price) in models.items():
	correct = sum(model(text) == label for text, label in cases)
	print(f"{name}: {correct}/{len(cases)} correct, ${price:.2f} per million tokens")

It prints:

text
small: 3/4 correct, $0.10 per million tokens
large: 4/4 correct, $3.00 per million tokens

The small model misses the bug report and costs 30 times less. Whether 3 out of 4 is good enough depends on the task. A wrong label that a person fixes later may be fine. A wrong refund may not. With real models, replace each function with an API call and keep the loop the same.

Start small, then step up

  1. Run your evaluation set on a small, cheap model.
  2. When it fails, read the failures. A clearer prompt or better examples often fix them.
  3. Move to a larger model only for the failures that a better prompt cannot fix.

Many products use more than one model. A small model handles the easy requests, and the hard ones go to a larger model. This setup is called routing, and it can cut costs a lot when most requests are easy.

Test again when anything changes

Providers update and retire models, and new models appear every few months. Pin the exact model version in your code, so that the model does not change under you. When you switch versions or try a new model, run the evaluation set again before you ship the change.

Your test decidesChoose with your own evaluation set, not a public ranking.
Start smallUse the smallest model that passes, and step up only for the cases it fails.
Pin and re-testFix the model version, and run the set again before any switch.

Your reading position is saved

0%

0 of 20 complete

Contents

Learning tools