Repository navigation
Add a precision benchmark: float32 against float64 across CPU, CUDA and Apple Silicon - #2
Conversation
…nd Apple Silicon A harness under precision/ that measures what float64 costs on each kind of device, by kernel type: a dense matmul (compute-bound), a Bellman step over stored rewards (memory-bound), the same step recomputing rewards in blocks (transcendental), and a Kalman filter under lax.scan (launch-bound). Each cell runs in a fresh process with precision and device set before JAX imports, keeps cold and warm times apart, asserts the result dtype, and appends one JSON line with an environment block to results/<host>/. The Bellman workloads shard by rows across GPUs, for the capacity question on qe-wharton1-gpu. The workflow gains a run_precision input that runs the matrix on the RunsOn GPU instance and its host CPU. Part of #1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
It introduces a sizable new benchmarking subsystem whose GPU/CUDA and multi-card sharding paths are, by the author's own account, not yet executed on real hardware and incur CI cost, so final human verification is warranted.
No open issues 🎉
What changed in this PR
This PR adds a new precision/ subsystem that measures the cost of float64 relative to float32 across CPU, CUDA, and Apple Silicon, broken down by kernel type (compute-, memory-, transcendental-, and launch-bound). It is Phase 0 of issue #1 and is designed to run unchanged on qe-mini1, the RunsOn T4, and qe-wharton1-gpu. Each benchmark cell runs in a fresh process with precision/device flags set before JAX imports, records cold and warm timings, asserts the result dtype, captures fidelity samples and XLA memory analysis, and (on GPU) reads telemetry. A memory-aware planner skips cells that would exceed a device-memory fraction, and summarise.py renders markdown tables including the float64 penalty and GPU/CPU crossover.
Changes:
- New
precision/harness:spec.py(matrix + memory formulas),kernels.py(matmul, two Bellman steps, Kalman filter, with row-sharding),run_cell.py(single-cell timing),run_matrix.py(per-cell process orchestration + memory planning),summarise.py(markdown tables),env_info.py(environment capture). benchmark.ymlgainsrun_precision/precision_quickdispatch inputs and a GPU job that runs the matrix on the RunsOn GPU and its host CPU, writing to the job summary and uploadingresults/.- README updates documenting the new
precision/andresults/directories.
| File | Description |
|---|---|
precision/spec.py |
Declares workloads, sizes, shardability, rate units, and per-device memory estimates used for skip planning. |
precision/kernels.py |
JAX kernel builders with row-sharding; stored and recomputed Bellman steps compute the same answer. |
precision/run_cell.py |
Times one cell in a fresh process, asserts result dtype, captures samples/telemetry/memory analysis. |
precision/run_matrix.py |
Orchestrates one process per cell, sets precision/device env, enforces memory-fraction skipping, writes JSONL. |
precision/summarise.py |
Aggregates JSONL into markdown tables: times, penalty, rates, fidelity, GPU/CPU crossover. |
precision/env_info.py |
Collects a machine/environment block that is a superset of benchmark_hardware.py's system block. |
precision/README.md |
Documents workloads, running instructions, method, output, and caveats. |
.github/workflows/benchmark.yml |
Adds dispatch inputs and a precision GPU job (install JAX, run matrix, summarise, upload results). |
README.md |
Adds precision/ and results/ entries and a Precision Benchmarks section. |
Review effort: Balanced
- run_cell.py records backend_init_s, the time jax.devices() takes to start the backend. It fell into no field before. On qe-wharton1-gpu it is about 0.2 s on the CPU and 0.6 s on a TITAN RTX, as much as the compile and first run of most quick cells. summarise.py counts it in the cold time and the cold crossover. - env_info.py ignores untracked files for git_dirty, so earlier results in results/ don't mark every later run dirty. - JAX is pinned in precision/constraints.txt (0.12.0.1), used by the workflow and the README, so that every platform runs the same release. - The precision job uses the lectures' RunsOn label form, with the image defined in .github/runs-on.yml as lecture-jax defines it. The old labels (runner=gpu, image=quantecon-gpu-ubuntu2404) are not defined in this repository. - Two dispatch choices: precision_instance (g4dn T4, g5 A10G, g6 L4) and precision_cuda (cuda13, cuda12; cuda12 runs get --label cuda12). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Smoke-tested on real hardware on 2026-10-25, with fixes and two dispatch choices pushed in 91baa22. What ran. The quick matrix on What 91baa22 changes.
Still open, outside this PR.
|
Part of #1: the Phase 0 harness, built so the matrix can run on
qe-mini1, the RunsOn T4 and thenqe-wharton1-gpuwithout changes.What it adds
precision/, which measures what float64 costs against float32 on each device, by kernel type:matmulbellman_stored: one Bellman step over a stored m × m reward arraybellman_recompute: the same step, recomputing log-utility rewards in blocks of 512 rowskalman: a 10-state Kalman filter underlax.scanBoth Bellman workloads shard by rows across GPUs (
gpu:2), for the capacity question on the Wharton machine's two Titans.One fresh process per cell, with
JAX_ENABLE_X64,JAX_PLATFORMSandCUDA_VISIBLE_DEVICESset before JAX imports. Each cell records compile and first-run time apart from five warm runs. It asserts the result dtype, keeps 64 fixed-position result values for float32/float64 fidelity, and keeps XLA's memory analysis. On a GPU it also reads clocks, temperature and power just after timing.Memory-aware planning: cells that would exceed
--memory-fractionof a device's memory are recorded as skipped rather than run. A skipped cell is a data point for the capacity question.Output: one JSON line per cell in
results/<host>/<date>.jsonl. Each line carries an environment block that is a superset ofhardware/benchmark_hardware.py'ssystemblock.summarise.pyturns the lines into markdown tables: times, the float64 penalty, rates, fidelity, and where each GPU first beats its own host CPU, warm and cold.benchmark.ymlgainsrun_precisionandprecision_quickinputs. They run the matrix on the RunsOn GPU instance and its host CPU, and write the summary to the job summary.run_precisiondefaults to false, so nothing runs, and nothing costs anything, until it is dispatched.How it was tested
cpu:2). Sharded and unsharded results agree exactly, stored and recomputed results agree exactly, and float32 sits about 4e-7 from float64.nvidia-smitelemetry andgpu:2sharding over real cards. The firstrun_precisiondispatch on the T4 is its test.One finding along the way
Written as one broadcast, the recomputing Bellman step saves no memory on CPU. XLA materialises the full m × m array, and its memory analysis reports a temp of exactly m² × itemsize. Hence the blocks, which bring the temp down to about 512 × m. A lecture written the naive way would get the same surprise.
Not yet
sargent_suricoNUTS cell (jax on the GPU runner is >2.7x slower than its CPU for a small float64 model (sargent_surico NUTS cell) lecture-python.myst#1022) as an as-used workload. It needs FRED data, a posterior mode from an earlier section and most of the lecture's code, so it is a follow-up of its own.qe-mini1and the T4. The T4 run is arun_precisiondispatch and costs a little RunsOn time.🤖 Generated with Claude Code