Repository navigation
Description
A suite of the problem types QuantEcon's lectures and research use, each written idiomatically in NumPy, Numba and JAX, and timed as used on CPUs and GPUs across problem sizes. The aim is data-driven guidance on which stack to use for which kind of problem, at what size, and on what hardware. This is the experiment for meta#264.
Why
- meta#264 asks for exactly this: crossover points between backends and devices, by problem type and size, to replace rules of thumb.
- Precision and platform: float64 against float32 on CPU, CUDA and Apple Silicon #1 measures JAX only, by kernel type. Its precision matrix (results under
results/) shows how differently kernel types behave on a GPU. On a TITAN RTX, float64 costs 1.3× on a latency-bound recursion, about 4× on a memory-bound step and 20× to 27× on compute or transcendental work. It doesn't say whether Numba on a CPU would beat JAX for the same problem. - The lecture runs (Lectures run as used: aiyagari_jax and ifp_egm_jax in float32 and float64 #3) found that how a problem is written matters as much as the hardware. A vectorised Bellman step and a looped one, or a stored reward array and a recomputed one, land in different regimes.
Problem types
Each type gets a NumPy version as the baseline, a Numba version (CPU, parallel=True where it fits) and a JAX version (CPU and GPU), each written the way a careful author in that stack would write it.
| Problem type | QuantEcon pattern | Shape | |
|---|---|---|---|
| P1 | Value function iteration on a dense grid | Savings and discrete-choice models | Vectorised max over a choice grid; loops in Numba |
| P2 | Policy iteration | Howard improvement with a linear solve | Dense or iterative solves |
| P3 | Endogenous grid method | Income fluctuation problems | Interpolation |
| P4 | Monte Carlo simulation | Many paths of an AR(1) or Markov process | Parallel across paths, sequential in time |
| P5 | Markov chains | Stationary distributions, simulation | Sparse and dense linear algebra |
| P6 | Root finding and optimisation per state | Newton or bisection over a grid | Many small independent solves |
| P7 | Sequential recursions | Kalman filter, lax.scan |
Latency-bound |
| P8 | Gradient-based estimation | Maximum likelihood with autodiff | Where JAX's autodiff should matter |
Dimensions
- Problem size, swept to find the crossovers.
- Precision: float64 throughout, plus float32 where the problem tolerates it.
- Device: CPU and GPU, for JAX. Numba runs on CPU only;
numba.cudais out of scope unless a problem type calls for it. - Dask (in meta#264) is left out, unless a problem type needs data larger than memory or distributed scheduling.
Method
#1's house standard:
- one fresh process per measurement, with compile time counted, and cold and warm times kept apart;
- the result dtype asserted;
- every implementation's answer checked against the NumPy baseline.
The harness extends precision/, with one module per problem type and one function per stack.
Platforms
As in #1: qe-mini1's M6 and qe-wharton1-gpu's Threadripper and TITAN RTX first. Then qe-wharton2's M5 Pro once it is onboarded, and the RunsOn T4 once RunsOn is configured for this repository.
Phases
- P1, P4, P3 and P7 first. They span the regimes Precision and platform: float64 against float32 on CPU, CUDA and Apple Silicon #1 found, and they shake out the harness across three stacks.
- Then P2, P5, P6 and P8.
Output
- results under
results/, as for Precision and platform: float64 against float32 on CPU, CUDA and Apple Silicon #1; - a dashboard view by problem type, showing the fastest stack and device at each size;
- for the lecture series, a short guide of the form "for problem type X at size N, use stack S on device D", with the numbers beside it.
🤖 Generated with Claude Code
Activity
mmcky commentedon Nov 1, 2026
Phase 1's harness is designed (2026-11-01), and built in #24. These are the decisions, as agreed with @mmcky, that refine the plan above. The detail is in
problems/README.md.problems/folder besideprecision/andlectures/. It reusesprecision/'s environment record and GPU telemetry. Results go toproblems/results/<host>/<date>.jsonl, apart fromresults/, which the dashboard reads as the precision matrixopt_savings_1,ifp_egm_jax,wealth_dynamics_jax, andprecision/'s Kalman filteropt_savings_1uses a 4-D broadcast.lectures/already measures the lectures as writtennumpy,numba,numba-parallel,jax-cpuandjax-gpu. Both Numba backends compile the same source, so a small problem's parallel overhead showsvmapat 10 states, and 2 to 200 states for one filter. Every GPU measured pays about 90 to 160 µs a Kalman step, against about 1.4 µs on the M6, so this gives the "how much work a step needs before a GPU wins" rule of thumbPlatforms: the M6, the Threadripper and the TITAN RTX first, as above, once
qe-wharton1-gpuis free of QuantEcon/project-econ-on-ai-hardware's runs, and the M6 run's plan is agreed. Then the M5 Pro and the T4.Problem types: Phase 1's harness, in NumPy, Numba and JAX (#24)
qe-wharton2 2026-11-06: the problem-type suite on an M5 Pro (#48)
mmcky commentedon Nov 7, 2026
Phase 1's M5 Pro step is done (2026-11-06, on
qe-wharton2): the four CPU stacks at every size in both precisions, 200 cells, all ok, inproblems/results/qe-wharton2/2026-11-06.jsonl(#48,133da9b), with the run's notes.mmcky commentedon Nov 21, 2026
Phase 2's four problem types have had their first measured runs, every size in both precisions (P2 in float64 only), on 2026-11-21. They ran on
qe-mini1's M6,qe-wharton2's M5 Pro, andqe-wharton1-gpu's Threadripper 2990WX and TITAN RTX: #83, merged as5e838bf, with each host's run notes underproblems/results/<host>/2026-11-21/. Every cell ran but one, and every answer agreed with NumPy's float64 answer but two, both float32 cells onqe-wharton1-gpu. The finding is QuantEcon/project-benchmarks-jax'sfindings/2026-11-21-phase-2-problem-types.md. In short:shocks) and 1.15× to 20× in float32. The exception is P8 with 1,000 parameters in float64, where the M5 Pro is 1.17× to 2.2× faster: that work is mostly float64 matrix products, and Turing runs float64 at 1/32 of its float32 rate.--xla_gpu_autotune_level=0that compile takes 0.3 s, but the warm solve is 3× to 3.7× slower.prangeoversubscribes the cores: holding OpenBLAS to one thread makes the blocked form up to 11× faster in float64.Where these leave the guide, problem type by problem type, is in the finding's "For a JAX for Economists guide".