Catch a capacity model that contradicts its own data
Fit a load-to-throughput model from four points, compare its prediction with an observed point, and keep the extrapolation guard.
A capacity model is a claim about how throughput responds to load. It should be fitted to observations, checked against points it did not use, and refused outside the observed range. A model that predicts 16 tokens per second at load 4 when the measurement at load 4 was 30 has failed its own data, even if its API is tidy.
This example builds a four-point capacity table: loads 1, 2, 4 and 8 with throughputs 10, 18, 30 and 32. It then predicts throughput at load 4 and rejects a prediction at load 100. The prediction at 4 is 16, because the model scales linearly from the maximum observed load rather than fitting the points. The extrapolation guard is correct; the interpolation is not. The page uses the contradiction as the lesson: a guard against extrapolation is not a substitute for a fit.
Run it
From the canonical repository at commit
f958967d70992d7b09d9c75000bd8c543f1644d4:
python examples/ch38/capacity.py --jsonPython 3.11 or later, standard library only. No model, network, GPU or
credentials. It finishes immediately. The chapter’s capacity_lab.py contains
the measured sweep; this page uses the small accounting fixture.
Implementation
build_model takes the maximum observed load and throughput and computes a
placeholder headroom. predict linearly scales load up to the saturation point
and refuses any load above the maximum observed. It never checks the prediction
against the training points.
class CapacityModel:
max_observed_load: float
saturation_throughput: float
headroom: float
metadata: dict = field(default_factory=dict)
def to_dict(self) -> dict:
return asdict(self)
def predict(self, load: float) -> float:
if load > self.max_observed_load:
raise ValueError("extrapolation beyond supported load")
# Simple linear scaling up to saturation.
return min(load * (self.saturation_throughput / self.max_observed_load), self.saturation_throughput)
def build_model(points: List[CapacityPoint]) -> CapacityModel:
if not points:
raise ValueError("points required")
max_load = max(p.load for p in points)
sat_throughput = max(p.throughput for p in points)
headroom = 1.0 - (max_load / (max_load + 1)) # placeholder
return CapacityModel(max_observed_load=max_load, saturation_throughput=sat_throughput, headroom=headroom, metadata={"n": len(points)})Expected outcome
Observed with the command above (exit 0):
{
"model": {
"max_observed_load": 8,
"saturation_throughput": 32,
"headroom": 0.11111111111111116,
"metadata": {
"n": 4
}
},
"prediction_at_4": 16.0,
"extrapolation_error": "extrapolation beyond supported load"
}The observed point at load 4 had throughput 30, but the model predicts 16. The
prediction is not a fit; it is 4 * (32 / 8). The headroom field is a
placeholder formula, not a measured reserve. The only defensible part of this
result is the refusal at load 100: the model will not silently extrapolate.
Mechanism and limitations
Documented: build_model rejects an empty point list and derives maximum load,
maximum throughput and a placeholder headroom. predict refuses a load above the
maximum observed and scales linearly below it. The tests check the model’s maximum
load, the extrapolation error, the demo and JSON serialisation.
Observed: the command exited 0 with the model, the prediction of 16 at load 4
and the extrapolation error above. The targeted tests.test_ch38_capacity is
part of the canonical suite; no independent test count is claimed here.
Not shown: GPU utilisation, memory pressure, concurrency, a load sweep, a
fitted curve, or a capacity plan. The model’s prediction contradicts the observed
point at load 4, and the headroom is a placeholder. No GPU was measured. The
chapter’s capacity_lab.py is the source for a real sweep; this page is a
cautionary fixture about model validation.
Challenge this result
Add a validation step that compares each prediction with its observed point and
reports the residual. At load 4 the residual should be 14. Then fit a simple
piecewise-linear interpolation through the four points and compare its prediction
at load 6 with the current model. Finally, decide which is more dangerous: a
model that extrapolates confidently beyond load 8, or a model that interpolates
badly inside its observed range. Explain your answer in terms of the decisions
the model will be used for.
Source and verification
Canonical source:
examples/ch38/capacity.py
at commit f958967d70992d7b09d9c75000bd8c543f1644d4. Tests:
tests/test_ch38_capacity.py
.
Chapter: GPU Utilization and Capacity Planning
.
The run above is a fresh local execution on Windows 11 with Python 3.13.15; it
is a deterministic capacity fixture, not a GPU measurement.
Understand this example
Copy this prompt into your AI tool. No code runs here.
Apply this example
Copy this prompt into your AI tool. No code runs here.