Foundations to Frontier
Tests
N. MLOps and AI Systems Engineering › N5 ML System Design

Trade-offs: Accuracy, Latency, Cost

Every production model sits somewhere on a curve: more capacity buys accuracy at the price of latency and compute, with diminishing returns. Which point is right depends on things outside the model: how much a correct prediction is worth, how many requests arrive, what latency users tolerate, and what training costs. The exercises train a family of eight random-feature classifiers of increasing width on the same task, measure their real test accuracy, attach latency and cost from a hardware model, and find the most profitable width for different values of accuracy and latency objectives. Practice problems cover reduced precision and Pareto frontiers, distillation into a cheaper student, ensembles at equal compute, total cost of ownership across traffic volumes, and splitting a fixed training budget between data and model size.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Choosing a car

A faster car costs more to buy and to run, and each extra bit of speed costs more than the last. A delivery company picks its vans by how much a faster delivery is worth to its customers, how many deliveries it makes, and the speed limits it must respect, not by the fastest van on the market. Choosing a model is the same: the best model is the one whose extra accuracy is worth its extra cost and still meets the latency limit.

🎮 MLOps lab
width 4
0.7110 · p99 1.05 ms · $0.030
width 8
0.7340 · p99 1.10 ms · $0.059
width 16
0.7442 · p99 1.20 ms · $0.119
width 32
0.7450 · p99 1.41 ms · $0.237
width 64
0.7823 · p99 1.82 ms · $0.474
width 128
0.8050 · p99 2.64 ms · $0.948
width 256
0.8135 · p99 4.28 ms · $1.896
width 512
0.8283 · p99 7.55 ms · $3.793

Most profitable: width 128, profit $39.30 per million requests. Raise the value of accuracy and the choice moves up the curve; tighten the latency objective and it moves down.

Why engineers care

In Exercise 2, width 512 cost four times as much as width 128 and gained only 2.3 points of accuracy; when a million correct predictions were worth $5, width 8 was the best choice, at $5,000 width 512, and with a 4 ms latency objective width 128.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Larger models usually…
  2. 2. The right model size depends on…
  3. 3. A latency objective can rule out…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Operating point: a configuration (model, precision, hardware) with its accuracy, latency and cost.
  • Pareto frontier: the configurations not dominated by any other that is at least as good in every objective and better in one.
  • Diminishing returns: accuracy grows roughly logarithmically or as a power law in model size, data and compute (scaling laws).
  • Value model: profit per request = value of a correct prediction × accuracy − serving cost; constraints such as a p99 objective cut the feasible set.
  • Efficiency techniques: reduced precision (float16, int8), distillation (training a small student on a large teacher’s outputs), pruning, and caching and cascades (topic N4-4).
  • Total cost of ownership: training and retraining, serving, engineering and monitoring; their balance changes with traffic.
  • Compute-optimal training: for a fixed training budget, balance data and model size.
📝 Quick check (Level 1)
0/3 answered
  1. 1. A configuration is Pareto-optimal when…
  2. 2. Distillation trains a small model on…
  3. 3. Total cost of ownership includes…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

A family of models

Exercise 1.

  • Task: a nonlinear binary problem in 10 dimensions with 5% label noise; 3,000 training and 4,000 test examples.
  • Models: random Fourier features of width 4 to 512 with a ridge-regression readout, trained in closed form.
  • Each request scores 4,000 candidates; operations per example 32 × width.
  • Hardware model: 20 GFLOP/s effective on a $2.50 per hour GPU at 60% utilisation; p99 latency = 1 ms + twice the compute time.

Practice.

  • Plot the frontier of accuracy against latency and cost before choosing a model.
  • Put a value on accuracy, even a rough one, and include training and maintenance in the cost.
  • Try efficiency techniques first: reduced precision and distillation often move the whole frontier.
  • Respect the latency objective at the tail, not the mean.
  • Revisit the choice when traffic, prices or the value of accuracy change.
def choose(models, value, slo_ms):
    feasible = [m for m in models if m.p99_ms <= slo_ms]
    return max(feasible, key=lambda m: value * m.accuracy - m.cost_per_request)
🐍 Exercise 1: a family of models
Train random-feature classifiers of increasing width on the same task and measure how test accuracy and compute grow.
📝 Quick check (Level 2)
0/3 answered
  1. 1. When accuracy becomes more valuable, the best width…
  2. 2. Reduced precision usually…
  3. 3. At low traffic, total cost is dominated by…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Marginal analysis. With profit per request V·a(W) − c(W), a wider model is worth it when the marginal gain V·Δa exceeds the marginal cost Δc. Cost grows linearly in width while accuracy grows roughly logarithmically, so Δa per doubling shrinks while Δc per doubling doubles: there is an interior optimum, and it moves to larger widths in proportion to log V.

Constraints. A latency objective removes the configurations above it; the optimum is then either the unconstrained one or the largest feasible configuration. Constraints often bind for valuable tasks, which is why efficiency work (precision, distillation) matters most where accuracy is most valuable.

Pareto dominance. If configuration B is at least as accurate as A and cheaper, A should never be chosen whatever the value of accuracy. Reduced-precision variants that keep accuracy within noise of full precision at a fraction of the cost dominate full precision, removing it from the frontier.

Amortization. Training costs T once; serving costs c(W) per request for Q requests. Total cost T(W) + Q·c(W): at small Q the training term decides, at large Q the serving term. The best model therefore depends on the volume it will serve.

Data and model size. Test error decreases with both data n and capacity W, with diminishing returns in each. Under a budget n·W = B, the optimum balances the two; scaling laws for neural networks (Kaplan and colleagues, 2020; Hoffmann and colleagues, 2022) found that data and parameters should grow roughly together.

📝 Quick check (Level 3)
0/3 answered
  1. 1. A wider model is worth it when…
  2. 2. A configuration dominated in accuracy and cost…
  3. 3. Hoffmann and colleagues (2022) found that data and parameters should…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Which model size is most profitable as the value of accuracy and the latency objective change?

History.

  • Multi-objective optimization and Pareto efficiency go back to V. Pareto (1906) and were formalized in engineering design in the 20th century.
  • G. Hinton, O. Vinyals and J. Dean (2015) popularized knowledge distillation; C. Buciluǎ, R. Caruana and A. Niculescu-Mizil (2006) had compressed ensembles into single models.
  • A. Rahimi and B. Recht (2007) introduced random Fourier features, a simple family whose capacity is set by one number.
  • J. Kaplan and colleagues (2020) and J. Hoffmann and colleagues (2022) measured scaling laws linking accuracy to model size, data and compute.
  • Efficiency benchmarks such as MLPerf Inference (2019) report accuracy together with latency and throughput.

Exercise 2.

  • Widths 4 to 512; each trained on 3,000 examples and tested on 4,000.
  • Profit per million requests = value of a million correct predictions × accuracy − cost; values $5, $50 and $5,000; with no latency objective and with p99 under 4 ms.

Seed 0:

width test accuracy p50 ms p99 ms $ per million
4 0.7110 1.03 1.05 0.030
8 0.7340 1.05 1.10 0.059
16 0.7442 1.10 1.20 0.119
32 0.7450 1.20 1.41 0.237
64 0.7823 1.41 1.82 0.474
128 0.8050 1.82 2.64 0.948
256 0.8135 2.64 4.28 1.896
512 0.8283 4.28 7.55 3.793

Most profitable width (seed 0): $5: 8; $50: 128; $5,000: 512; $5,000 with p99 under 4 ms: 128. Seed 1 gave the same choices. In seed 2 widths 256 and 512 were no more accurate than 128 on the test set (0.8203 and 0.8213 against 0.8225), so 128 was best at $5,000 too.

Findings.

  • Accuracy rose by 9.4 points from width 4 to 128 but only 2.3 points from 128 to 512, while cost rose fourfold over the second range.
  • The best width grew with the value of accuracy, from 8 at $5 to 128 at $50 and 512 at $5,000 (seeds 0 and 1).
  • The 4 ms latency objective capped the choice at width 128 in every seed; at high widths, differences of a point are within test-set noise, so the choice should rest on more than one evaluation.
🐍 Exercise 2 (research): which model size is most profitable as the value of accuracy and the latency objective change?
Train a family of models of increasing width, attach latency and cost, and find the most profitable width for different values of accuracy and latency objectives.

Trade-offs in practice

  • Model cards and launch reviews report accuracy together with latency percentiles and cost per thousand requests on the target hardware.
  • Families of models (small, base, large; distilled and quantized variants) let teams pick a point per product surface: a fast model for autocomplete, a large one for offline batch jobs.
  • Large language model providers price tiers by size, and routers send each request to the cheapest model expected to answer it well.
  • Satellite and edge systems face hard power and latency budgets onboard, which often decide the model before accuracy does; heavier models run on the ground.

References

  1. A. Rahimi and B. Recht (2007). “Random features for large-scale kernel machines.” NeurIPS.
  2. C. Buciluǎ, R. Caruana and A. Niculescu-Mizil (2006). “Model compression.” KDD.
  3. G. Hinton, O. Vinyals and J. Dean (2015). “Distilling the knowledge in a neural network.” arXiv.
  4. J. Kaplan and colleagues (2020). “Scaling laws for neural language models.” arXiv.
  5. J. Hoffmann and colleagues (2022). “Training compute-optimal large language models.” NeurIPS.
  6. V. J. Reddi and colleagues (2020). “MLPerf inference benchmark.” ISCA.