advanced34 min studyLesson 500 in Engineering

Approve a precision change with separate quality and cost evidence

Build mechanism-level references and controlled end-task experiments before accepting a faster or smaller learning computation.

On this page

What you’ll understand

  • Isolate input, product, accumulator, state, and output precision in a test matrix.
  • Apply absolute-plus-relative tolerances with explicit reference and near-zero behavior.
  • Measure comparable quality, latency, memory, and numerical exceptions before approving a configuration.

A precision change is a proposal about behavior and cost, not just a smaller dtype label. It can alter representable inputs, intermediate ranges, accumulator spacing, optimizer state, kernel selection, and communication. A useful evaluation separates these mechanisms and then asks whether the complete system still satisfies its actual quality requirements. Reference calculations explain numerical differences; representative end-task measurements establish their consequences. Neither a faster microbenchmark nor agreement on one convenient tensor answers both questions.

Build a reference ladder and isolate the changed stage

Begin with small fixtures whose exact answers can be derived or computed with a genuinely stronger method. Include near-zero cancellation, a large positive partial sum followed by small contributions, finite values near range limits, and optimizer updates below destination spacing. A wider floating-point implementation is a useful reference candidate, but verify convergence as reference precision increases or compare exact representable cases when possible. The reference can have its own unstable formula, narrow intermediate, or backend-specific reduction, so merely naming its output dtype does not certify it.

Create ablations that change input storage, multiplication, accumulation, optimizer state, and output storage separately when the framework permits. Record the operations actually used under automatic mixed precision rather than inferring them from model parameters. Distinguish a master-parameter change from an accumulator change and keep scaling policy explicit. Kernel choices, fused operations, and backend precision controls can change with shape as well as dtype. Hold data, batch shapes, mathematical hyperparameters, and the intended number of valid updates fixed before attributing a result to one precision boundary.

∣ytest−yref∣≤atol+rtol ∣yref∣,atol≥0,rtol≥0|y_{\rm test}-y_{\rm ref}|\le \mathrm{atol}+\mathrm{rtol}\,|y_{\rm ref}|,\qquad \mathrm{atol}\ge0,\quad\mathrm{rtol}\ge0
For finite scalar outputs this is one explicitly chosen componentwise comparison rule. atol has the output's units and rtol is dimensionless. It is asymmetric in the reference and requires application-justified tolerances. NaNs, infinities, and signed-zero requirements need separate stated policies rather than ordinary finite subtraction.↔ Scroll wide equations horizontally.

Treat tolerance and task quality as designed contracts

Absolute tolerance matters near zero because a pure relative comparison has no useful nonzero allowance at a zero reference. Relative tolerance allows errors to scale with larger reference magnitudes. Inspect componentwise failures as well as aggregate norms, because a small average can conceal a critical coordinate. Choose tolerances using problem scales, sensitivity, and downstream requirements before inspecting a candidate's favorable cases. An unexplained failure calls for diagnosis; silently increasing the threshold until it passes converts a test into a record of the observed discrepancy.

Mechanism tests should be followed by representative inference or training evaluations. Track the task metric, nonfinite events, skipped optimizer steps, and convergence trajectories, including variation across repeated runs where randomness matters. Similar final losses can conceal different valid-update counts or a different data schedule after overflow skipping. Gradient checks also need care: a finite-difference step that is too small can disappear in subtraction, while a large step introduces truncation error. Check the reference method and its step-size behavior instead of treating one finite-difference disagreement as a complete diagnosis.

speedup=TrefTtest,memory saving=1−MtestMref(Tref,Ttest,Mref>0)\mathrm{speedup}=\frac{T_{\rm ref}}{T_{\rm test}},\qquad \mathrm{memory\ saving}=1-\frac{M_{\rm test}}{M_{\rm ref}}\quad(T_{\rm ref},T_{\rm test},M_{\rm ref}>0)
Times must measure comparable work in the same units, and memory measurements must share a defined scope and unit. The saving is dimensionless and may be negative. These cost ratios do not establish numerical correctness or task quality; those are independent acceptance conditions.↔ Scroll wide equations horizontally.

Measure real execution and preserve an audit trail

Benchmark after a stated warmup and compilation policy, and synchronize asynchronous device work at the intended timing boundaries. Report whether transfer, optimizer work, communication, and setup are included. Use the same effective batch and valid work count when comparing latency or throughput, and state whether memory means peak allocated, reserved, or total device usage. Keep software, hardware, shapes, selected precision controls, and reference outputs with the result. A configuration accepted for one regime should be rechecked when a different shape or backend selects a new numerical path.

The roofline lab supports a deliberately narrower cost comparison. Reset, set both I=4 FLOP/byte and B=100 decimal GB/s, predict a ceiling of 400 GFLOP/s, then Play. Reset and set both I=16 and B=100 to predict the fixed compute ceiling of 1000 GFLOP/s. Its intensity is an input parameter rather than a precision switch; the display measures no actual kernel, latency, memory footprint, or task accuracy. Use it to reason about a possible bandwidth-to-compute transition, then approve a real precision configuration only from the separate reference, quality, and measured-cost evidence.

A faster candidate still fails its declared comparison

For reference outputs [0.001,2,−4], a candidate returns [0.0011,2.0002,−3.9996]. Apply atol=0.00005 and rtol=0.0001 componentwise to finite outputs. Comparable measured execution takes 40 ms and 25 ms respectively; peak allocated memory is 800 MiB and 600 MiB.

  1. For the first coordinate, the allowance is 0.00005+0.0001×0.001=0.0000501. Its error is 0.0001, so it fails. A small reference magnitude makes the absolute term decisive here.

  2. The second coordinate has allowance 0.00025 and error 0.0002, so it passes. The third has allowance 0.00045 and error 0.0004, so it also passes. Two passing coordinates do not erase the first failure.

  3. The measured speedup is 40/25=1.6 and memory saving is 1−600/800=0.25, or 25%. These favorable cost ratios are separate from the failed numerical contract and do not by themselves authorize acceptance.

The result

Investigate the failing coordinate and its downstream significance against the predeclared requirement. Keep the useful cost measurement, but do not redefine numerical success from that measurement.

Explore the model

Interactive lab

Interactive lab · roofline

A synthetic performance ceiling leaves quality untested

Reset, set both I=4 FLOP/byte and B=100 decimal GB/s, predict 400 GFLOP/s, then Play. Reset and re-enter both I=16 and B=100 for a second run predicting 1000 GFLOP/s. The formula is min(1000,B×I); Play traces that fixed roof without changing the selected kernel. This is neither a measured benchmark nor a precision, latency, memory, or accuracy simulator.

A synthetic performance ceiling leaves quality untestedSynthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Current readings: Attainable ceiling: 640 GFLOP/s; Ridge intensity: 12.5 FLOP/byte; Ceiling regime: Memory-bound ceiling. All parameters are adjustable with the labeled controls below.Hypothetical roofline upper bound: 640 GFLOP per second at operational intensity 8 FLOP per byte and bandwidth 80 gigabytes per second.0.1110641101001000Operational intensity · FLOP/byte · log scaleCeiling · GFLOP/s · log scalePeak: 1000
Attainable ceiling / kernelBandwidth roof / traceCompute ceiling
Attainable ceiling
640 GFLOP/s
Ridge intensity
12.5 FLOP/byte
Ceiling regime
Memory-bound ceiling
t = 0 s

Synthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA cost model, a numerical reference, and a task evaluation supply different evidence for the same proposed change.

Check your understanding

A lower-precision configuration is faster but fails one predeclared numerical tolerance. What is the strongest next action?

Try it yourself

A finite reference output is 0 and a candidate output is 0.00002. With atol=0.00001 and rtol=0.001, does the componentwise rule pass? Explain how you would choose a meaningful requirement if the application's natural scale is nonzero despite this zero reference.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

The relative contribution is proportional to the reference magnitude, not to the candidate or a convenient default scale.

Compare with the solution

The allowance is 0.00001+0.001×0=0.00001, while the error is 0.00002, so it fails. An ordinary relative error divided by zero is unavailable. If a physical or task-related nonzero scale is appropriate, define and justify an absolute or scaled contract using that scale before acceptance; do not substitute the candidate's magnitude merely to make this case pass.

Take it with you

  • Reference calculations need their own stability and precision checks, especially near cancellation and range limits.
  • Isolate precision boundaries and declare tolerance, exception, and end-task requirements explicitly.
  • Approve real changes using comparable measured cost together with numerical and task-quality evidence.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.