Repository navigation
Description
Why now
Two independent JAX-on-cloud failures surfaced in the space of a week, in different repos, with different root causes, at different layers of the stack. Each was invisible until it burned hours of on-demand GPU runner time, and neither would have been predicted by "it works on a laptop" or "it works on Colab".
| incident | repo | symptom | root cause | status |
|---|---|---|---|---|
| NUTS cell timeout | QuantEcon/lecture-python.myst#1022 | jax + numpyro cell >2400s on the T4, 157s on a laptop CPU; GPU ≥2.7x slower than the CPU in the same box | unconfirmed — leading hypotheses are crippled FP64 on inference-class GPUs and kernel-launch overhead on 10x10 ops | worked around by pinning the lecture to CPU |
| Concurrent kernel death | QuantEcon/lecture-python-programming#363 | jax_intro kernel aborts with no traceback on every cold-cache build |
confirmed by an instrumented run — three JAX kernels share one T4, the first preallocates JAX's default 75% (11.3GiB of 15.3GiB), the loser clamps to the ~3.4GiB remainder and aborts when a cell outgrows it | fixed with XLA_PYTHON_CLIENT_PREALLOCATE=false, validation run in progress |
The two incidents share a pattern worth naming: our lecture code is written against a mental model of "a GPU makes JAX fast", but the runners are single inference-class GPUs (T4 on g4dn.2xlarge) shared by concurrent notebook execution, running workloads that are frequently small-matrix, float64, and latency-bound rather than throughput-bound. We do not currently have a tested model of when that combination wins, loses, or crashes — we find out one incident at a time.
Proposed project
A focused investigation to characterise JAX on our cloud CI runners and turn the findings into standing guidance and CI configuration, rather than per-incident firefighting.
Questions to answer
- FP64 penalty. How large is the float64 penalty on the T4 for our actual workload shapes (Kalman filters, NUTS, small linear models)? T4 FP64 is nominally 1/32 of FP32 throughput — measure what that does to representative lecture cells, and whether
jax_enable_x64lectures should default to CPU. - Small-op / launch overhead. At what array size does the T4 break even with the runner's own CPU for our common op mix? A
lax.scanof 10x10 ops may never amortise launch latency — find the crossover so lecture authors have a rule of thumb rather than a guess. - Concurrency policy. myst executes notebooks at parallelism = cpus-1, so multiple JAX kernels share one GPU. With preallocation off, what is the safe concurrency for JAX lectures, and should JAX-heavy lectures be serialised while pure-CPU lectures fan out?
- Sampler configuration. Does
chain_method='vectorized'close the GPU gap for numpyro workloads, or issequential+ CPU the right default for small models? - Standard CI environment. Which XLA/JAX env vars should be standard across all GPU lecture repos (
XLA_PYTHON_CLIENT_PREALLOCATE, possiblyXLA_PYTHON_CLIENT_MEM_FRACTION, allocator choice), and where do they belong so every repo inherits them rather than rediscovering them? - Instance fit. Is
g4dn.2xlargethe right instance at all? Candidates to price against:g5/g6(better FP64 story is not automatic — check), plain CPU instances for FP64-heavy lectures, or a split fleet where only genuinely large-array lectures get a GPU. - Failure hygiene. A pathological cell currently burns 40 minutes per builder because a failed notebook is never cached and every builder re-executes it. What per-cell timeout and caching policy makes a bad cell fail fast and fail once?
Method
A small benchmark harness that runs a matrix of representative kernels (Kalman filter scan, NUTS on the sargent_surico model, large dense linear algebra as a control, the jax_intro 50M-element ops) across {T4 GPU, runner CPU} x {float32, float64} x {1, 2, 3 concurrent processes}, with a jax profile captured for the pathological cases to separate kernel time from gap time. Run it on the actual CI runners via workflow_dispatch so the numbers are the numbers we live with. The two incident lectures become the first regression fixtures.
Deliverables
- A short findings report with the measured crossover points and the answer to each question above, checked into QuantEcon/meta.
- Guidance for lecture authors (a page in the style guide or manual): when to expect the GPU to help, when to pin a lecture to CPU, and the sampler/config idioms that make small models CI-safe.
- Standard CI configuration rolled out across the five GPU-CI lecture repos — env vars, concurrency settings, timeouts — ideally via the shared infrastructure in quantecon/actions so it lands once (related: Migrate the five native lecture CI pipelines to quantecon/actions/build-lectures #348, GitHub Actions config hardening across the five GPU-CI lecture repos #347).
- An audit of existing JAX lectures against the findings: which are in the losing region (small model + x64 on GPU) and should be pinned or restructured.
Out of scope
Rewriting lecture content for performance, GPU vendor comparisons beyond what instance selection requires, and anything about the mystmd/jupyter-book build engines (tracked separately on QuantEcon/lecture-python-programming#363).
Evidence trail
- 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 — the NUTS/T4 measurements, hypotheses and proposed experiments.
- [Experimental] Build the lectures with QuantEcon/mystmd instead of jupyter-book lecture-python-programming#363 — the preallocation-race diagnosis: instrumented run 30806359596 in that repo shows the GPU timeline (0 → 11,305MiB → 14,727 → 3,427 → 0) and a clean dmesg ruling out host OOM; commits
8af1015(instrumentation, engine pin) and94a7e52(fix).
Activity
mmcky commentedon Aug 4, 2026
Adding some analysis ahead of building the harness: priors for the seven investigation questions (so benchmark runs confirm/refute expectations rather than explore blindly), a few proposed additions to the methodology, and two fixes worth making now. Based on a review of the two incidents plus the CI configs across the lecture repos.
Reading of the two incidents
They look like one underlying mismatch in two guises:
Priors for the investigation questions
Proposed additions to the methodology
JAX_COMPILATION_CACHE_DIRalongside the jupyter cache in CI — speeds every build on every instance family, likely the single biggest cheap win here.workflow_dispatchinput interpolated into the RunsOn label (family=g4dn.2xlarge|g5.2xlarge|g6.2xlarge|c7i.2xlarge) runs the identical harness per family for ~$1 each, and answers Q6 with data.numpy_vs_numba_vs_jax,jax_introdevice printouts). These constrain retiering decisions independently of performance.quantecon/actions, so instance/env policy is a one-line change across all GPU repos.Two fixes worth making now (independent of the project)
- [ ] lecture-python-programming
- [ ] lecture-python-programming is a CPU-tier candidate: only ~3 of 27 lectures execute JAX. A c7i.2xlarge (~$0.36/hr) is half the g4dn's cost and likely builds faster — subject to the GPU-narrative tagging above.
Adding some analysis ahead of building the harness: priors for the seven investigation questions (so benchmark runs confirm/refute expectations rather than explore blindly), a few proposed additions to the methodology, and two fixes worth making now. Based on a review of the two incidents plus the CI configs across the lecture repos.publish.ymlomitsspot=— RunsOn defaults tospot=price-capacity-optimized, so the publish job currently runs on interruptible spot capacity while throwaway previews run on-demand. Addspot=false(or deliberately flip previews to spot instead).Reading of the two incidents
They look like one underlying mismatch in two guises:
Priors for the investigation questions
XLA_PYTHON_CLIENT_MEM_FRACTION=.30for ≤3 kernels — overPREALLOCATE=false, which trades OOM-at-init for fragmentation and per-alloc overhead. Plus guaranteed kernel teardown on timeout.chain_method="vectorized"should help GPU on small models (one launch across chains) but likely still loses to CPU for tiny models; guidance default:numpyro.set_platform("cpu")/JAX_PLATFORMS=cpufor small NUTS.XLA_PYTHON_CLIENT_MEM_FRACTION(orPREALLOCATE=false),JAX_COMPILATION_CACHE_DIR(see below),JAX_TRACEBACK_FILTERING=offin CI so failures produce real tracebacks.execute.timeoutin_config.ymlis already per-cell (nbclient semantics). lecture-python.myst's 2400 s is the outlier — programming/intro use 600 s. Lower the default and raise per-lecture in frontmatter. The 40-min-per-builder repeat is capped by the ci.yml gating fix (firstjb buildgates); confirm all GPU repos have it.Proposed additions to the methodology
JAX_COMPILATION_CACHE_DIRalongside the jupyter cache in CI — speeds every build on every instance family, likely the single biggest cheap win here.workflow_dispatchinput interpolated into the RunsOn label (family=g4dn.2xlarge|g5.2xlarge|g6.2xlarge|c7i.2xlarge) runs the identical harness per family for ~$1 each, and answers Q6 with data.numpy_vs_numba_vs_jax,jax_introdevice printouts). These constrain retiering decisions independently of performance.quantecon/actions, so instance/env policy is a one-line change across all GPU repos.Two fixes worth making now (independent of the project)
publish.ymlomitsspot=— RunsOn defaults tospot=price-capacity-optimized, so the publish job currently runs on interruptible spot capacity while throwaway previews run on-demand. Addspot=false(or deliberately flip previews to spot instead).3 of 27 lectures execute JAX. A c7i.2xlarge ($0.36/hr) is half the g4dn's cost and likely builds faster — subject to the GPU-narrative tagging above.mmcky commentedon Aug 4, 2026
Two things from
project-compute— one offer, one dependency.The offer. QuantEcon owns
quantecon-gpu2: two TITAN RTX cards, Turingsm_75— the same architecture generation as theg4dn's T4. It is powered down and shipping, but once recommissioned it could reproduce the incidents here on hardware we control, without consuming CI minutes or waiting onworkflow_dispatch. A second machine,quantecon-gpu1, is slated for a used 24 GB Ampere card, which would let you test directly whether the FP64 penalty in question 1 is generation-specific or persists past Turing. That bears on question 6: "a newer generation fixes it" and "GPUs are the wrong shape for these workloads" imply very different instance answers.Neither is available today, and the method here is deliberately to run on the actual CI runners so the numbers are the numbers we live with — so this is offered as a supplement, not a substitute.
The dependency, stated so it is visible rather than discovered later.
project-computeis planning a self-hosted GPU runner pilot, and its evidential base is 538 GPU-hours a year measured across the five GPU-CI repos. If this programme pins lectures to CPU, that figure shrinks — and the Turing FP64 penalty applies identically to gpu2's Titans, so a finding here changes what insourcing is worth. We are watching rather than blocking, but it is the largest external dependency that plan has, and it is now recorded as such on our side.mmcky commentedon Oct 4, 2026
Naming note, 2026-10-05. The two machines offered to this project from project-compute were renamed (decision on QuantEcon/project-compute#26).
quantecon-gpu2, the Wharton machine with two TITAN RTX cards, is nowqe-wharton1-gpu;quantecon-gpu1, the i9 tower whose card is on hold, is nowqe-anu1. The offer itself is unchanged.mmcky commentedon Oct 24, 2026
The harness this issue's priors were written for is scoped as QuantEcon/benchmarks#1. It covers questions 1, 2 and 6 by kernel type, and carries over the methodology from the 2026-08-04 comment: cold and warm times kept apart, at least five repetitions,
XLA_PYTHON_CLIENT_PREALLOCATE=false, and the instance family as an axis (g6andc7iin its Phase 2).Two parts of it bear on this issue directly. The
sargent_suricoNUTS cell (QuantEcon/lecture-python.myst#1022) is designed to run as a 2 × 2, CPU/GPU × float32/float64, which separates weak FP64 from launch latency. And a first data point: on an M1 Pro, JAX 0.12.0.1 runs a 4096² float64 matmul at 251 GFLOPS on the CPU, level with the T4's FP64 peak (254). That fits the reading of the NUTS incident above.mmcky commentedon Oct 25, 2026
Question 1, measured on the CI runner itself (2026-10-26). All 28 lecture-jax lectures with code ran as written, three times each, on RunsOn's
g4dn.2xlarge: on its T4, and on its own Xeon Platinum 8259CL (4 cores, 8 threads, 32 GB) withJAX_PLATFORMS=cpu. Each lecture ran in a fresh process, compile included, as a build pays it. The tables are in QuantEcon/benchmarks'lectures/whole/README.md(QuantEcon/benchmarks#4, QuantEcon/benchmarks#12).Should
jax_enable_x64lectures default to CPU? For lecture-jax on this runner, no.opt_invest,markov_asset_jax,hopenhayn,opt_savings_2,jax_intro_jax,inventory_ssd,arellano_jaxaiyagari_jax,mle_jax,job_searchnewtons_method,opt_savings_1,ifp_egm_jaxkeras,jax_nn,ifp_dl), a small jitted function called per agent from Python (schelling_jax, 3.0×), and small models, where starting CUDA and compiling cost more than the work.aiyagari_jax,ifp_dl,jax_nn,keras,schelling_jax, 1.7× to 3.0× faster on the CPU). That is a tidy-up rather than a fix, and it should wait for question 3: these runs are sequential, and a build shares the one T4 and the 8 threads across several notebooks.Question 6, in part: this runner's CPU alone would not do. A CPU-only build takes 3.3× as long (2,946 s against 901 s, without
overborrowing).overborrowingfails outright: one cell asks for 33.4 GB on the CPU, and the runner has 32 GB. The T4 runs that cell in 8.4 s.g5,g6and larger CPU instances are not measured yet.Two side results:
Still to come under QuantEcon/benchmarks#4: float32 runs of the 13 float64 lectures, which give the precision penalty lecture by lecture; and the JAX lectures in lecture-python.myst, with
sargent_surico's NUTS cell (QuantEcon/lecture-python.myst#1022).mmcky commentedon Nov 1, 2026
Question 1, the precision penalty lecture by lecture (2026-11-01). The 13 lecture-jax lectures that set
jax_enable_x64also ran in float32, three times each, on a TITAN RTX (the T4's Turing generation), the Threadripper beside it, and two Macs. The results are in QuantEcon/benchmarks#16, with the causes in QuantEcon/benchmarks#18, and the tables in QuantEcon/benchmarks'lectures/whole/README.md.The penalty runs the other way: float32 would make these lectures slower. On the TITAN RTX, float64 costs any one lecture at most 1.21× (
hopenhayn). Over the 12 that ran in both precisions, float32 takes 3.3× as long (1,850 s against 556 s), because loops that stop at a tolerance run longer, or to their caps. At the lectures' sizes, float64 arithmetic isn't what limits them on the card. Sojax_enable_x64is no reason to move a lecture, either to the CPU (the comment above) or to float32.float32 also changes one lecture's answers.
arellano_jax's borrowing policy differs at a third of its states. The other 12 reach float64's answers, though three look as if they don't:jax.randomdraws a different sample in float32, and that alone moveshopenhayn's price by 12%, sendsmle_jax's estimate to NaN, and failsmarkov_asset_jax's stability check.For the guidance to lecture authors (deliverable 2):
For the audit of existing lectures (deliverable 4): QuantEcon/lecture-jax#361 to QuantEcon/lecture-jax#364 came out of this, one for each of
arellano_jax,hopenhayn,mle_jaxandmarkov_asset_jax.Not measured: the T4 itself in float32. Running now: lecture-python.myst's 33 JAX lectures on the T4 and on its runner's CPU (QuantEcon/benchmarks#19),
sargent_surico's NUTS cell among them (QuantEcon/lecture-python.myst#1022).mmcky commentedon Nov 1, 2026
Question 6: a
g5is about TITAN-class for float64 work (2026-11-01). Phase 2 of QuantEcon/benchmarks#1 rented an A10 24 GB on Lambda, as a stand-in for the A10G in RunsOn'sg5(QuantEcon/benchmarks#14; the runs are inprecision/runs/2026-10-26/README.md).aiyagari_jax'sget_greedyat a 10,000-point grid at 0.9× the TITAN's speed.wealth_dynamics_jax, a float32 simulation: 168 s on the T4, against 59 s on the A10.g5would speed up large float32 simulations, and float64 lectures little. On those five alone it would save about 130 s of the T4's 922 s for the whole set, at a higher hourly rate. The other 23 lectures didn't run on the A10.Not measured: the A10G itself (its clocks differ from the A10's), the L4 in
g6, or a whole build on either.