Module: L2-M07 · Duration: ~105 min (estimate, including the independent exercise) · Previous: L02 · Next: L04
1. Introduction
Choosing among four systems is not just choosing the highest pass score. A cheap and fast system may be a few points worse and still be worth choosing; an expensive system may be only slightly better, or may not yet be proven better. Anthropic's documentation on choosing a model says this is a balance of capability, speed and cost [R1], and its documentation on success criteria says most cases need multidimensional evaluation [R2]. This lesson teaches how to put quality, cost and latency into one trade-off table with an interval for each number, find the dominated system, and choose under constraints while remembering that measured quality has error (L02).
Every system, cost and latency in the lab is simulated. Cost is in made-up cost units (cu) and latency in made-up milliseconds; the lab states no price or speed of any real model or vendor, and the lesson does not rank them. The product of the lesson: a trade-off table and a choice with a reason, decided by the person who signs.
2. Learning objectives
- Compute p50, p95, cost per request and cost per pass by hand. Practice: §8.3 (lines 1 and 2), §9 (TODO 2).
- Build a trade-off table with intervals for quality and p95, and lint it. Practice: §8.2 parts A and D, §8.3 (line 9).
- Find the dominated system on the Pareto front. Practice: §8.2 part B, §9 (TODO 1).
- Choose a system under constraints using the lower bound of the interval, and explain why "no system" is a valid answer. Practice: §8.2 part D, §8.3 (lines 6 and 7), §9 (TODO 3).
- Read the extra cost per quality point only when the quality is truly better. Practice: §8.2 part C, §8.3 (line 8).
- State what the table does not say. Practice: §6.1, §8.3 (lines 4 and 5).
3. Prerequisites and tools
- L02 (an interval for the difference, a verdict against the margin), L01 (the plan, sample size), L2-M01-L04. Code lab
code-labs/l2-m07. - Disambiguation. "Cost" here is the cost of running the system on the requests, in made-up cu; the cost of running the evaluation itself (judge, human graders) is a different matter and is not in the table. Baseline is still the system currently in use (L01). Pass rate is the share of requests that pass on this dataset.
4. Concept explanation
4.1 Three axes, and why one quality score is not enough
Anthropic's documentation on success criteria lists latency ("acceptable response time") and price ("model-running budget") alongside accuracy, and gives an example of a multidimensional criterion of the form "95% of response times under 200 ms" [R2]. The documentation on choosing a model describes an effort parameter that trades capability for latency and cost within the same model, and says tuning it is often a better lever than switching models; the starting level should be tuned based on your own evals [R1]. The same page advises building your own benchmark for your use case, and calls a good evaluation set the most important step [R1]. The implication for QA: each candidate needs three numbers with intervals, not one.
4.2 Cost: per request and per pass
In the lab, a run costs tokens_in × input price + tokens_out × output price (made-up cu per token). The cost per request is the mean over all requests. The cost per success (cost per pass) is the total cost divided by the number of passes: a cheap system that is often wrong can be more expensive per correct answer. If no run passes, the division is 0/0; the lab returns None rather than "free".
4.3 Latency: percentiles, not the mean
The mean hides the tail. For 10 latencies [120, 80, 95, 400, 110, 100, 90, 105, 85, 2000] ms, the mean is 318.5, p50 is 100 and p95 is 2000 (§8.3). The lab's nearest-rank percentile: the p-th is the smallest value such that at least p% of the data are less than or equal to it, with no interpolation, so it is always a value that really occurs in the data. With 10 requests, p95 is simply the maximum. Real latency also depends on the number of output tokens: OpenAI's documentation on latency optimization says generating tokens is almost always the slowest step and, as a rule of thumb, cutting 50% of the output tokens can cut about 50% of the latency [R3]. The lab's simulation has only that shape: a base latency plus time per output token, plus noise, and 8% of requests that are three times slower (the tail).
4.4 The Pareto front and the dominated system
System X dominates Y if X is no worse than Y on every dimension (a pass rate that is higher or equal; cost and p95 that are lower or equal) and better (even slightly, by point estimate) on at least one. Two identical points do not dominate each other. The Pareto front is the set of systems that nobody dominates. Being on the Pareto front only means that improving one dimension is paid for with another; it does not mean the system is good. A dominated system is a candidate to drop, provided the numbers are firm enough (§6.1).
5. Technical deep dive
5.1 The trade-off table of four simulated systems
tradeoff.row gives for each system: the pass rate with a bootstrap interval over items (not over requests: three runs of one item are not independent, L02 §4.4), p95 with a bootstrap interval over requests, and cost per request and per pass. With 200 items × 3 runs (600 requests): A reaches 0.742 [0.702; 0.782], p95 6150 ms, 3651.1 cu per request; B reaches 0.745 [0.700; 0.788], p95 10899 ms, 12379.6 cu; S reaches 0.588 [0.547; 0.637], p95 3384 ms, 1073.6 cu; C reaches 0.722 [0.680; 0.758], p95 14196 ms, 14209.1 cu (§8.2 part A). The Pareto front is A, B, S. C is dominated: B, on point estimates, is no worse on every dimension and better on quality, cost and latency.
B costs about 3.4 times as much as A per request. The paired quality difference of B against A: +0.003, interval [−0.040; 0.047], unclear (L02). These data do not prove that B is better than A, even though in the simulation B is truly 3.9 points better. The intervals side by side in the table overlap, but those are two unpaired intervals; to compare two systems, use analyze_pair (L02), not an overlap reading.
5.2 Extra cost per point: only when truly better
extra_cost_per_point(base, cand) is the extra cost per request divided by the increase in pass rate, that is, cu for every +1.00 of pass rate. The demo divides by a further 100 to get cu for every +0.01: A to B is 26186 cu per request for every +0.01 (the function returns 100 times that figure; §8.2 part C). This number is a ratio of two point estimates and rests on a difference of +0.003 whose interval contains 0: it should not be used yet. The function returns None only when the point difference is not positive; it does not know whether the difference can be told apart from 0. A to S returns None because S is worse: a worse system has no "price per point". The rule: compute this ratio only after analyze_pair gives better.
5.3 Constraint-based choice
choose(rows, min_quality, max_p95_ms, max_cost, use_lower_bound) picks the cheapest system (per request) that meets every constraint; ties go to the lower p95, then by name. By default it compares min_quality with the lower bound of the quality interval. With a minimum pass requirement of 0.72: by point estimate it picks A (0.742 ≥ 0.72); by lower bound it returns None, because the lower bound of A is 0.702 and of B is 0.700 (§8.2 part D). A None answer is valid: no system has yet been proven to reach 0.72; the right action is to add items, or to have a person accept the risk in writing. The lab does not relax the constraints by itself. With a minimum pass of 0.54 and p95 ≤ 4000 ms, S is chosen; with p95 ≤ 3000 ms, no system. The constraints come from the product (of the form "95% of responses under X"), not from the table.
The lab does not combine the three dimensions into one weighted score: weights hide the decision. The table puts the feasible options on view; a person chooses.
6. The QA perspective
6.1 What the table does not say
- Every number is simulated; real cost and latency depend on price, load, region, cache and streaming: the lab does not model them.
- Quality is only the pass rate on this dataset, not per slice. A system that wins overall may regress on a small slice (like B's
piiin the simulation); the gate in L04 checks each slice. - p95 from few requests is very wide: A has a p95 of 6150 ms with 600 requests, interval [2679; 6690]; only the first 60 requests give [2540; 7578] (§8.3). The p95 interval treats requests as independent, so with several runs per item it is slightly optimistic.
- The cost of the evaluation itself (judge, human graders, repeated runs) is not in the table.
- Pareto does not rank the systems on the front, and
lint_tableonly checks that the table has all its numbers, intervals and the "simulated" label; it does not check whether the numbers are right or whether the dimensions suit the product.
6.2 A minimum report
For each system: the pinned model id, n items and n requests, the pass rate with its interval, p50 and p95 with intervals, cost per request and per pass with the unit and the source of the prices, the constraints used to choose, the dominated systems, the paired difference against the baseline, and the label "simulated" or the source.
7. Real-world scenarios
Scenario 1 (fictional): "The premium model is only slightly better". HocVui chooses between A and B. The table shows B costing 3.4 times as much while the paired difference is +0.003, interval [−0.040; 0.047]. QA rejects the figure "26186 cu per point" and suggests adding items (L01) or choosing A. The decision records who signed and why.
Scenario 2 (fictional): "p95 over 60 requests". A report gave p95 = 2587 ms from 60 requests and promised "under 3 seconds". The bootstrap interval of p95 over those 60 requests is [2540; 7578]. The team collected more requests and reported the interval.
8. Hands-on tutorial
8.1 Setup
cd academy-content/code-labs/l2-m07
python3 -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest # 79 passed
8.2 Run the demo
python -m lab.demo l03
Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-04; the two versions give identical output). Every system, cost and latency is simulated:
A. 200 items x 3 runs, SIMULATED systems; cost in made-up cost units (cu)
| system | requests | pass rate [95% interval] | p95 ms [interval] | cost/request (cu) | cost/success (cu) |
|---|---|---|---|---|---|
| a | 600 | 0.742 [0.702, 0.782] | 6150 [2679, 6690] | 3651.1 | 4922.8 |
| b | 600 | 0.745 [0.700, 0.788] | 10899 [9534, 11532] | 12379.6 | 16617.0 |
| s | 600 | 0.588 [0.547, 0.637] | 3384 [3192, 3600] | 1073.6 | 1824.9 |
| c | 600 | 0.722 [0.680, 0.758] | 14196 [12141, 14757] | 14209.1 | 19689.3 |
B. Pareto front (higher pass rate, lower cost per request, lower p95): ['a', 'b', 's']
dominated: ['c']
C. is b better than a? difference 0.003 interval [-0.040, 0.047] verdict unclear
extra cost per request per +0.01 pass rate, a -> b: 26186 cu; a -> s: None
D. choose(min pass rate 0.72): point estimate -> a lower end -> None
choose(min 0.54, p95 <= 4000 ms): s choose(min 0.54, p95 <= 3000 ms): None
table lint: []
Reading the output: A is the four-system table (the system column is the middle part of the model id). B is the Pareto front and the dominated system. C is the paired difference b against a (3 runs per item) and the extra cost per +0.01. D is three constraint-based choices and the table lint (no errors).
8.3 Try it yourself
Save it as try_l03.py in the lab's root folder (next to lab/, not inside lab/), run python try_l03.py, then delete the file:
from fractions import Fraction as F
from lab import compare as C, simulate as S, tradeoff as T
from lab.stats import bootstrap_percentile_interval, percentile
lat = [120, 80, 95, 400, 110, 100, 90, 105, 85, 2000]
print(percentile(lat, 50), percentile(lat, 90), percentile(lat, 95), sum(lat) / len(lat))
items = S.make_dataset("v1")
rows = {m.split("-")[1]: T.row(m.split("-")[1], C.system(m), items, 3, "s1", b=300) for m in S.models()}
a, b, s = rows["a"], rows["b"], rows["s"]
print(round(float(a["cost_per_success"])), round(float(a["cost_per_request"])), round(float(s["cost_per_success"])))
print(T.pareto_front(list(rows.values())), T.dominates(b, rows["c"]))
recs_a = T.collect(C.system("tutor-a-2026-03-01"), items, 3, "s1")
lat_a = [r["latency_ms"] for r in recs_a]
print(len(lat_a), percentile(lat_a, 50), percentile(lat_a, 95), bootstrap_percentile_interval(lat_a, 95, b=300))
print(bootstrap_percentile_interval(lat_a[:60], 95, b=300))
for mq in ("18/25", "27/50"):
print(mq, T.choose(list(rows.values()), min_quality=mq), T.choose(list(rows.values()), min_quality=mq, use_lower_bound=False),
T.choose(list(rows.values()), min_quality=mq, max_p95_ms=4000))
print(T.extra_cost_per_point(a, b) is not None, T.extra_cost_per_point(b, a))
broken = dict(rows["a"])
del broken["p95_lo"]
print(T.lint_table([rows["a"], broken]), percentile(lat_a[:60], 95))
Output (identical on Python 3.14.6 and 3.12.14):
100 400 2000 318.5
4923 3651 1825
['a', 'b', 's'] True
600 2228 6150 (2679, 6690)
(2540, 7578)
18/25 None a None
27/50 s s s
True None
['a:MISSING:p95_lo'] 2587
Reading it: line 1: p50, p90, p95 of the 10 latencies and the mean (318.5). Line 2: A's cost per pass (4923), A's cost per request (3651) and S's cost per pass (1825). Line 3: the Pareto front and True (B dominates C). Line 4: the number of requests, p50, A's p95 (6150) and the interval of p95 over 600 requests. Line 5: the p95 interval over the first 60 requests. Line 9: the table lint with one row whose p95 lower bound was removed (a:MISSING:p95_lo), and the p95 of the first 60 requests (2587). Lines 6 and 7: choose with two minimum pass levels: by lower bound, by point estimate, then with p95 ≤ 4000. Line 8: the extra-cost ratio has a value for A to B and is None for B down to A.
8.4 Run the lesson's tests
python -m pytest tests/test_l03_tradeoff.py -v
Result: 8 passed. Read test_dominance_and_the_front_by_hand, test_choose_is_conservative_and_fails_closed and test_simulated_systems_and_their_rows. The tests run on in-memory values and the lab's data.
8.5 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
choose returns None |
No system meets the constraints, especially when comparing the lower bound | Add items, relax the constraints by a person's decision, or change the constraints |
ValueError: no records |
The list of requests is empty | Check the run step; do not fill in a 0 |
cost_per_success is None |
No request passed | That is the result: the system is not usable on this dataset |
9. Independent exercise
Problem: Choose among four systems from recorded request logs.
Requirements: complete exercises/test_l03_tradeoff.py:
- TODO 1:
FRONT: the set of system names not dominated by another system (higher pass rate, lower cost per request, lower p95). - TODO 2:
COST_PER_SUCCESS(aFraction) of the systemm2. - TODO 3:
CHOICE: the system that is cheapest per request and whose pass-rate interval lower bound (bootstrap_mean_intervalon the 0/1 flags, default parameters) is at least 3/5 and whose p95 is at most 9000 ms;Noneif there is none.
Test data: exercises/ex_records.json (four simulated systems, 100 requests each, one run per item; made-up cost and latency).
Deliverable: the three variables above, in the file exercises/test_l03_tradeoff.py itself.
Acceptance criteria: python -m pytest exercises/test_l03_tradeoff.py passes (3 tests), recomputed with lab.tradeoff and lab.stats. The tests do not check whether the constraints make sense for the product, and do not check that you read the p95 interval.
Hints: TODO 1: build the list of rows with T.summarize and then use T.pareto_front; or check each pair yourself. TODO 3: compute the lower bound first, then filter; try to see whether the result changes if you use the point estimate.
10. Knowledge check
0/18 done · Results are kept in this browser only.
P02 · True or false
P04 · Select all that apply
P05 · Put in order
P06 · Match
P07 · Spot the bug
The function below computes a nearest-rank percentile but gives a wrong p95 (lower than the correct value) on 12 requests. Find the bug.
def percentile(values, q):
vals = sorted(values)
rank = len(vals) * q // 100
return vals[rank - 1]P08 · Short answer
A table (simulated, made up) has system W (pass rate 0.70, 900 cu per request) and Z (pass rate 0.82, 4000 cu per request). The paired analysis Z minus W gives +0.12 with interval [−0.03; 0.26], verdict unclear. Someone wants to write "each +0.01 of pass rate costs 258 cu more". How is that number computed, and should it be reported?
P09 · Essay
Write 5-8 sentences: a report (simulated) states "system B's p95 latency is 10086 ms, meeting the requirement p95 ≤ 10500 ms". This number comes from the first 40 requests of a run (seed z7) with a per-request p95 bootstrap interval [4338; 12792]. Running all 200 requests gives p95 = 11661 ms, interval [10023; 13143]. State the conclusion, why 40 requests are not enough, and what else must be reported.
P11 · Recall
Lesson: L2-M07-L02P12 · Recall
Lesson: L2-M01-L04P13 · Multiple choice
P14 · Select all that apply
P15 · True or false
P16 · Multiple choice
P17 · True or false
P18 · Recall
Lesson: L2-M07-L0111. Summary
- Concepts: the three axes of quality, cost and latency; cost per request and per pass; nearest-rank percentile; the Pareto front and the dominated system; constraint-based choice using the lower bound; extra cost per point only when truly better.
- Skills: building and linting a trade-off table, finding the dominated system, choosing under conditions, reading the p95 interval.
- Traps: reading the mean instead of p95; comparing two unpaired intervals by eye; computing a "price per point" from a difference that cannot be told apart from 0; treating
Noneas an error and silently relaxing the constraints. - You can now: receive a table saying "the more expensive model is better" and ask: better by how much with an interval, which constraints, p95 over how many requests.
12. References
| ID | Title | Publisher | URL | Accessed | Relevance |
|---|---|---|---|---|---|
| R1 | Choosing the right model (Claude Platform Docs) | Anthropic | https://docs.anthropic.com/en/docs/about-claude/models/choosing-a-model | 2026-11-04 | Read the page text: balancing capability, speed and cost; the effort parameter; your own benchmark. The page names specific models; this lesson does not use them |
| R2 | Define success criteria and build evaluations (Claude Platform Docs) | Anthropic | https://docs.anthropic.com/en/docs/test-and-evaluate/develop-tests | 2026-11-04 | Read the page text: latency and price as criteria, multidimensional evaluation |
| R3 | Latency optimization (OpenAI API docs) | OpenAI | https://platform.openai.com/docs/guides/latency-optimization | 2026-11-04 | Read the page text: generating tokens is the slow step, the 50% rule of thumb |
Key terms (English ↔ Vietnamese)
| English | Tiếng Việt |
|---|---|
| Trade-off table | Bảng đánh đổi chất lượng, chi phí, độ trễ |
| Cost unit (cu) | Đơn vị chi phí giả của lab |
| Cost per request / per success | Chi phí mỗi yêu cầu / mỗi lần pass |
| Latency percentile (p50, p95) | Phân vị độ trễ; lab dùng hạng gần nhất |
| Dominated / Pareto front | Bị trội / mặt Pareto |
| Extra cost per point | Chi phí thêm cho mỗi điểm chất lượng |
| Constraint-based choice | Chọn theo ràng buộc, dùng cận dưới |
| Conservative choice | Chọn bảo thủ: không hệ thống đạt thì trả None (cùng tinh thần fail closed, L04) |