Repository navigation
Open
Description
Run the 13 float64 lectures in lecture-jax in float32 and record whether each still reaches its answer, then try a mixed-precision version of aiyagari_jax's greedy step. The aim is to know where QuantEcon's JAX code needs float64, and where it is a precaution.
Why
- The lectures don't say what float64 protects. 13 of the 29 lectures in
lecture-jaxturn it on, each with the same sentence, "to increase the precision". None says what goes wrong without it. - Lectures run as used: aiyagari_jax and ifp_egm_jax in float32 and float64 #3 found that float32 fails
aiyagari_jaxin two ways, and neither is a slightly worse answer.- Two of its 50 solves stall at an error of about 2.5e-4, against the lecture's tolerance of 1e-4, and run to the 10,000-iteration cap. That makes the lecture about 12× slower as used.
- On the TITAN RTX at a 5,000-point grid, its values went NaN in all three runs, from a
bicgstabbreakdown (QuantEcon/project-benchmarks-jax#5). The loop's testerror > tolis false for NaN, so it stopped after two iterations with a policy wrong almost everywhere, and raised no error. Both CPUs stayed finite. - When float32 did converge, equilibrium capital matched float64 to 2e-5.
ifp_egm_jaxconverges in float32, to within 1.6e-4 of the float64 policy.- So float32 fails by not finishing, or by failing silently, and the failure can depend on the device. Two lectures don't say which of the other eleven share that.
- Whole lectures, as used: every JAX lecture on an Apple CPU, a Turing GPU and an x86 CPU #4 runs these lectures in float32 for time. This issue asks whether the answer survives.
- The step that float64 makes expensive may not need it. In dense discrete choice the costly step recomputes rewards and takes the maximum over choices: 26.8× slower in float64 than in float32 on the TITAN RTX (Phase 0 and Phase 1 results, and two diagnoses #6). That step only has to pick the best choice. The value update, the convergence test, policy evaluation and the equilibrium search could stay in float64.
Part 1: the 13 lectures in float32
| Lecture | Solver and tolerance, as written |
|---|---|
aiyagari_jax |
Policy iteration, 1e-4; equilibrium capital by bisection, xtol 1e-4 |
arellano_jax |
Joint iteration on the repay and default value functions, 1e-8 |
hopenhayn |
Value function iteration, 1e-6; the entry price by bisection, 1e-4 |
ifp_egm_jax |
Endogenous grid method, 1e-5 |
inventory_ssd |
Value function iteration, 1e-6 |
jax_intro_jax |
None; it turns float64 on to show the difference |
job_search |
Value function iteration, 1e-4 |
markov_asset_jax |
A linear solve for the price-dividend ratio, after a spectral-radius check |
mle_jax |
Newton–Raphson, 1e-3 and 1e-5 |
newtons_method |
Newton's method, 1e-5; float64 is turned on in exercise 1's solution, for tolerances of 1e-7 and 1e-15 |
opt_invest |
Value function and optimistic policy iteration, 1e-5 |
opt_savings_1 |
Value function iteration, 1e-5 |
opt_savings_2 |
Value function and optimistic policy iteration, 1e-5 |
Also the two float32 lectures that solve to a tolerance, overborrowing (1e-5) and lucas_model_jax (1e-6): whether they meet it, or stop at their iteration cap.
Method:
lectures/run_lecture.pywith--dtype float32and--dtype float64, at thelecture-jaxcommit Whole lectures, as used: every JAX lecture on an Apple CPU, a Turing GPU and an x86 CPU #4 used. Each of the 13 has exactly onejax_enable_x64line, as--dtype float32requires.--recordeach lecture's answer: the equilibrium values, prices, estimates or policies it reports. Choosing the expressions lecture by lecture is part of the work.- For each solve: whether it met its tolerance or stopped at its cap, and how many iterations it took. Where a solver doesn't return these, read them from its printed output.
- Check every recorded value for NaN and Inf. Don't rely on a loop's exit: a NaN error ends
while error > tolas if it had converged. - One run per configuration, and three where results vary between runs.
Platforms:
| Device | Why |
|---|---|
M6 CPU, qe-mini1, with its agents paused |
Seconds per lecture; the CPU answer |
TITAN RTX, qe-wharton1-gpu, card 0b:00.0 |
The silent NaN appeared only on the GPU |
T4, RunsOn g4dn.2xlarge |
The lectures' CI device, if it is cheap to add to #4's job |
Result: one table, lecture by device, giving whether float32 converges (yes, stops at its cap, NaN, or raises), the largest gap from float64 in the recorded answers, and whether that gap is within the lecture's own tolerance.
Part 2: a mixed-precision greedy step for aiyagari_jax
- The variant: with float64 on,
get_greedycasts to float32, computes rewards and the argmax over next-period assets, and returns the policy. The value function,get_value'sbicgstabsolve, the convergence test and the equilibrium bisection stay in float64. - Then one float64 greedy step at the converged solution, counting the policy points that change. That catches choices decided by a near-tie.
- At the grids Lectures run as used: aiyagari_jax and ifp_egm_jax in float32 and float64 #3 used, 200 to 10,000 asset points, on the TITAN RTX and the M6.
- Record: time per policy-iteration loop, against pure float64 and pure float32; the policy points that differ from float64, and by how many grid steps; the gap in equilibrium capital; iterations to converge.
- If it is ready in time, add it to Precision and platform: float64 against float32 on CPU, CUDA and Apple Silicon #1's Phase 2 runs. A Blackwell workstation card does float64 at 1:64 of float32, so that is where the float32 step would matter most.
What the results would change
| If | Then |
|---|---|
| A float64 lecture reaches its answer in float32, within its tolerance, on every device | Float64 is a precaution there. The lecture can say so, or say what it guards against |
| A lecture stalls, goes NaN, or moves its answer past its tolerance in float32 | It needs float64 as written, and the lecture can say why |
| The mixed step gives float64's answer at a fraction of float64's cost | Research-scale discrete-choice models can run their heavy step at a card's float32 rate. That changes which card suits them, which project-compute weighs |
| It doesn't | Dense discrete choice needs float64 throughout, and a card's float64 rate decides |
Deliverables
- the results, under
lectures/results/<host>/<date>/as Whole lectures, as used: every JAX lecture on an Apple CPU, a Turing GPU and an x86 CPU #4's are; - the per-lecture table, and Part 2's table of time and gaps;
- a finding in QuantEcon/project-benchmarks-jax's
findings/, with its hardware consequence going to project-compute.
Related
- Precision and platform: float64 against float32 on CPU, CUDA and Apple Silicon #1, the precision experiment, with Lectures run as used: aiyagari_jax and ifp_egm_jax in float32 and float64 #3 and Phase 0 and Phase 1 results, and two diagnoses #6, which measured
aiyagari_jax's float32 failures and float64's cost by kernel type - Whole lectures, as used: every JAX lecture on an Apple CPU, a Turing GPU and an x86 CPU #4, the whole-lecture run, which times these lectures in float32
- QuantEcon/project-benchmarks-jax#5, the
bicgstabbreakdown
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
No labels
Activity
mmcky commentedon Oct 26, 2026
Part 2 has moved (2026-10-26). The mixed-precision greedy step is now the first experiment of a new QuantEcon project,
project-econ-on-ai-hardware, which asks whether economic models can be restructured to run at the speed of GPUs whose float32 is far faster than their float64, and still give float64's answers. That project's repository is private, so this comment records what changed.The experiment extends Part 2 in four ways:
It runs from the project's own repository. If the approach proves itself, it comes back here as a benchmark to re-run on each new card.
Part 1, the 13 lectures in float32, stays in this issue.
mmcky commentedon Nov 1, 2026
Part 1: the 13 float64 lectures in float32, from what they print (2026-11-01). The float32 pass (#16) ran each lecture three times in each precision on the TITAN RTX, the Threadripper beside it,
qe-mini1's M6 and an M5 Pro. Seven checks (#18) then swapped one ingredient at a time between the precisions (the random sample, the arithmetic, or the tolerance) to find out why each changed lecture changes. The times and what each lecture prints are inlectures/whole/README.md, and the checks' output inlectures/whole/checks/float32.txt.Only
arellano_jaxneeds float64 for its answer.arellano_jaxaiyagari_jaxopt_invest,opt_savings_2hopenhayn,mle_jax,markov_asset_jaxifp_egm_jaxnp.interpis slower on float32 arraysjob_search,opt_savings_1,inventory_ssd,newtons_methodjax_intro_jaxjax.randomdraws a different sample in float32 from the same key. That alone moveshopenhayn's equilibrium price by 12%, sendsmle_jax's Newton–Raphson to NaN, and failsmarkov_asset_jax's stability check. On float64's sample, float32 arithmetic gives float64's answer in all three. On float32's sample, float64 does no better:mle_jaxruns to its 100-iteration cap, andmarkov_asset_jax's 15-step estimate comes out at 1.026 against an exact 0.994. Across seeds in float64 (Whole lectures: float64 sweeps over seeds for four float32 checks #20),hopenhayn's price has a standard deviation of 3.1% at its 200 draws, andmarkov_asset_jax's check fails from 5 of 20 start vectors, whilemle_jaxconverges from all 20 seeds tried: float32's sample is an unusual one for it.mle_jax's NaN is silent. The loop's test,error > tol, is false for NaN, so it stops after two iterations and prints an estimate of NaN without an error: the failure mode this issue describes foraiyagari_jaxon the card.arellano_jaxuses no random numbers. In float32 it stops after 361 iterations, against 399, because its iterates stop changing at float32's resolution, not because it is near float64's solution. float64's solution is identical at tolerances from 1e-5 to 1e-10.Still open in Part 1:
--recordpass over each lecture's answers, as the method above asks: this used the cells' printed output and seven checks;arellano_jaxstops after 342 iterations, against 361 on the CPUs;overborrowingandlucas_model_jax.Filed on lecture-jax: QuantEcon/lecture-jax#361 (
arellano_jaxcould say what float64 protects), QuantEcon/lecture-jax#362 (hopenhayn's Monte Carlo error), QuantEcon/lecture-jax#363 (mle_jax's factorial overflows past 20!, so its printed log-likelihoods are wrong) and QuantEcon/lecture-jax#364 (markov_asset_jax's 15-step check).