Unit 6 of 12 · about 4 hours · derive

Tolerances and an extreme-value policy

Floating-point order changes can be legitimate, but a loose tolerance can conceal a defect. Extreme values need semantic decisions, not a larger error threshold.

You'll be able to

  • Derive an absolute-plus-relative acceptance rule and justify its scale from precision, reduction order and output use.
  • Separate input rounding from accumulation error using a higher-precision reference.
  • Declare and test policies for non-finite inputs, masked rows, overflow, underflow and subnormals.

Covers

Tolerance from precision, reduction order, conditioning and output useNaN, Inf, overflow, underflow, denorm and extreme-input policy
1

Read

In this order, only the parts listed

0 of 4 done

  1. CS336: accumulation precision experimentCS336 Assignment 2 - Section 2.1 Profiling

    Section 2.1.5, Problem (mixed_precision_accumulation), pp. 7 to 8

  2. PyTorch 2.14: numerical limitsPyTorch 2.14 numerical accuracy and tensor testing

    Introduction; Extremal values; Linear algebra - Non-finite values and Extremal values in linalg; TensorFloat-32 on Nvidia Ampere; Reduced Precision Reduction for FP16 and BF16 GEMMs

    The page's slice example compares A.sum(-1)[0], a row sum, with A[:,0].sum(), a column sum; the intended pair is A.sum(-1)[0] and A[0].sum(). Skip the AMD-specific sections.

  3. Finite and non-finite comparison rulesPyTorch 2.14 numerical accuracy and tensor testing

    torch.testing.assert_close: closeness inequality, non-finite comparison and rtol, atol, equal_nan parameters

  4. CUDA 13.4: order and subnormal controlsCUDA 13.4 Floating Point and IEEE 754

    Sections 2.2, Operations and Accuracy; 3.1 to 3.2, dot-product algorithms and comparison; 4.4, Compiler Flags

2

Focus on

  • For finite outputs use , where is the reference and and are declared absolute and relative tolerances. Near zero, relative error alone is unsuitable.
  • Evaluate quantized inputs in higher precision to isolate accumulation error. Comparing with unrounded original inputs adds input-representation error to the result.
  • Cancellation and ill-conditioning can amplify relative error. A dtype-only default is not an error bound for arbitrary reduction lengths or applications.
  • Test NaN and infinity locations separately. Declare all-masked-row behavior, overflow handling and subnormal preservation or flushing; record precision modes and compiler flags.
Common mistakes · 3
  • Increasing tolerance until an omitted element or wrong mask passes.
  • Setting equal_nan=True and calling unexpected NaNs correct.
  • Assuming max-subtracted softmax defines an all-masked row. Subtracting negative infinity from itself produces NaN; the application must specify a separate policy.
3

Try it yourself

Closed-book, before checking anything

Run the four CS336 accumulation loops unchanged on CPU. In PyTorch 2.14.1, the FP32 loop gives 10.000133514404297 and the FP16 loop gives 9.953125; both loops with FP16 increments accumulated in FP32 give 10.00213623046875, exactly 1000 times the FP16 value of 0.01 (0.01000213623046875), so all of that error is input rounding. Explain input rounding versus repeated accumulation rounding, then define acceptance and extreme-input policies for your reduction. These are numerical examples, not GPU timing results.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Why does promoting a rounded FP16 increment to FP32 not recover the original decimal value?Answer

    Promotion preserves the already rounded value. It improves subsequent accumulation, not the information lost on conversion.

  2. 2.Can a finite final mathematical answer guarantee finite intermediate arithmetic?Answer

    No. Intermediate products, squares or sums can overflow even when a rearranged or higher-precision calculation has a representable final answer.

  3. 3.Does a larger relative tolerance repair comparison near a zero reference?Answer

    No. The relative term vanishes at zero. Use a justified absolute tolerance and investigate cancellation.

  4. 4.What does -ftz=true change for single-precision CUDA arithmetic?Answer

    It enables flushing subnormal values to zero in affected operations. Record it as a numerical-semantic choice, not just a performance flag.

5

Practice

  • CS336 Assignment 2: mixed_precision_accumulation

    Problem (mixed_precision_accumulation), pp. 7 to 8

    Run all four loops and explain each discrepancy from the real-arithmetic sum of 10. This written experiment has no public autograder. The section mini-project adds cancellation, NaN, infinity, overflow, underflow and all-masked policy tests.

You're done when

You explain all four accumulation results and defend a predeclared finite-output tolerance plus separate extreme-value policies that reject a seeded wrong-mask or skipped-element defect.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 9 more in the section
  • CS336 Assignment 2 - Section 2.1 ProfilingStanford University · support

    Do the benchmarking_script, nsys_profile, mixed_precision_accumulation and memory_profiling problems on a model size that fits your GPU instead of the handout's B200 settings. Keep raw timings, traces and memory snapshots.

  • PyTorch 2.14 numerical accuracy and tensor testingPyTorch · reference

    Read the numerical-accuracy introduction, Extremal values, non-finite inputs and Ampere precision sections, plus the assert_close contract and make_tensor parameters. These supply current comparison semantics missing from the pool's project checklist.

  • CUDA 13.4 Floating Point and IEEE 754NVIDIA · reference

    Read sections 2.2, 3.1 to 3.2 and 4.4 for reduction order and single-precision flush-to-zero flags. Do not use the historical CPU-has-no-FMA statements as current hardware facts.

Also in this section

  • AI Systems Performance Engineering - Chapters 6 to 8Chris Fregly · primary

    Read Chapters 6 to 8: GPU architecture and occupancy, profiling and tuning memory access, and occupancy, warp efficiency and instruction-level parallelism, with their Nsight Systems, Nsight Compute and roofline workflows. Treat every quoted speedup as a hypothesis for your own hardware.

  • AI Systems Performance Engineering companion code - Chapters 6 to 8Chris Fregly · required

    Use selected baseline and optimized pairs from code/ch06, code/ch07 and code/ch08 plus the shared benchmark and verification machinery. Run only hardware-compatible paths, inspect the tests first, retain raw artifacts and document any guard or unavailable feature.

  • Nsight Systems User GuideNVIDIA · required

    Learn capture, statistics, CUDA API and GPU timeline views, NVTX ranges and report export. Produce one trace that attributes a host gap, transfer or synchronization cost without using the kernel profiler first.

  • Nsight Compute Profiling GuideNVIDIA · required

    Study the profiling model, replay, metric collection, sections, roofline and source correlation. Collect the smallest counter set that can falsify your bottleneck hypothesis and record profiler overhead.

  • Compute SanitizerNVIDIA · required

    Run memcheck plus applicable racecheck, initcheck and synccheck cases against seeded defects. Preserve minimal reproducers and regression tests, and distinguish unsupported checks from a clean result.

  • Roofline: An Insightful Visual Performance ModelUC Berkeley · required

    Read the original model and construct one roofline plot with explicit peak assumptions, useful operations and bytes. Add measured points and explain gaps from launch, resource, cache or instruction effects.

  • CUTLASS GEMM Performance Measurement MethodologyNVIDIA · support

    Apply the environment, clock, warmup, timing, verification and reporting guidance to the benchmark harness. Generalize the method beyond GEMM and document every intentional deviation.

  • TensorTonic Language Modeling from Scratch - Measure Kernel Timeline UtilizationTensorTonic · support

    Solve the timeline-utilization problem after the timeline unit, then repeat the calculation on a trace you captured yourself.

  • GPU Microbenchmark and Kernel Suite - Harness and InstrumentationRoadmap-Final · support

    Complete Milestones A and B: correct references, synchronized timing, raw samples, noise characterization, environment capture, operation and byte models, timeline traces and profiler evidence.