Repository navigation
Whole lectures: why float32 changes what seven lectures print - #18
Conversation
Checks that swap one ingredient between the precisions, run on an M1 Pro's CPU against lecture-jax at 4b939ec, with their output in lectures/whole/checks/float32.txt. - hopenhayn, mle_jax and markov_asset_jax change because jax.random draws a different sample in float32. On float64's sample, float32 arithmetic gives float64's answers. - arellano_jax is the one lecture whose answer float32 arithmetic changes: its borrowing policy differs at 4,222 of 12,801 states, while float64's is the same at tolerances from 1e-5 to 1e-10. - opt_invest and opt_savings_2 run to their cap, but their policies are float64's at all but 1 and 70 of 15,000 states. - ifp_egm_jax's Numba solve is slower in float32 because Numba's np.interp is slower on float32 arrays. The README's float32 section now says why each lecture changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Verifying script fidelity and the committed float32.txt/README numbers requires external lecture-jax sources at 4b939ec and a JAX runtime that cannot be fetched or executed in this environment, so a human with that checkout must confirm reproduction.
No open issues 🎉
What changed in this PR
This PR adds a lectures/whole/checks/ directory of diagnostic scripts that explain why float32 changes the printed output of seven lecture-jax lectures (observed in the earlier float32 pass, #16). Each script re-runs the lecture's own code cells at 4b939ec and swaps exactly one ingredient between precisions — the random sample, the arithmetic, or the tolerance — to isolate the cause. The committed output (float32.txt) and an updated README.md turn those results into a cause-attributed table, fitting into the broader float64-vs-float32 investigation (issue #11).
Changes:
- Six check scripts plus
run_checks.shthat reproduce and attribute the float32 differences formle_jax,hopenhayn,markov_asset_jax,arellano_jax,opt_invest/opt_savings_2, andifp_egm_jax, with their captured output infloat32.txt. README.md's float32 table gains a "why" for each lecture, plus two bullets separating random-sample effects from arithmetic effects (arellano_jaxbeing the sole arithmetic-driven case).
| File | Description |
|---|---|
lectures/whole/README.md |
Adds causal explanations to the float32 table's last column and two new bullets distinguishing sample vs arithmetic effects, linking to the new checks. |
lectures/whole/checks/run_checks.sh |
Orchestrates all six checks (~70 s) against a lecture-jax checkout, writing to float32.txt. |
lectures/whole/checks/mle_check.py |
Reproduces mle_jax's Newton–Raphson, drawing data in one precision and solving in another to show the NaN comes from the float32 sample. |
lectures/whole/checks/hopenhayn_check.py |
Swaps Monte Carlo draws between precisions to show the price shift tracks the sample, not the arithmetic. |
lectures/whole/checks/markov_asset_check.py |
Swaps the power-iteration start vector between precisions to show the spectral-radius failure follows the sample. |
lectures/whole/checks/arellano_check.py |
Compares float32-vs-float64 solutions and float64 across tolerances, isolating arithmetic as the cause. |
lectures/whole/checks/policy_check.py |
Compares HPI/VFI/OPI policies across precisions for opt_invest/opt_savings_2, counting near-tie state differences. |
lectures/whole/checks/ifp_numba_check.py |
Times the lecture's Numba operator with np.interp vs a hand-written interp to attribute the float32 slowdown. |
lectures/whole/checks/float32.txt |
Captured diagnostic output that the README numbers are drawn from. |
Review effort: Balanced
Part 1 of #11 asks whether each float64 lecture still reaches its answer in float32. The float32 pass (#16) showed what each lecture prints differently; these checks find out why. Each one runs the lecture's own cells from lecture-jax at
4b939ecand swaps a single ingredient between the precisions: the random sample, the arithmetic, or the tolerance.What they show
hopenhaynmle_jaxmarkov_asset_jaxarellano_jaxopt_invest,opt_savings_2ifp_egm_jaxnp.interp: one application of the operator takes 2.2× as long on float32 arrays, and with a hand-written interpolation the precisions are within 11%In this PR
lectures/whole/checks/: six check scripts,run_checks.sh, which reruns them all in about 70 s, and their output,float32.txt.lectures/whole/README.md: the float32 table's last column now gives the cause, and two new bullets cover the random sample andarellano_jax. The earlier wording, "the equilibrium price comes out 12% higher", read as a precision effect; it is the sample.They ran on an M1 Pro laptop's CPU with jax 0.12.0.1, as diagnostic runs, not measurements.
qe-mini1,qe-wharton1-gpuandqe-wharton2are in use by another project. The float32 runs ofarellano_jaxstop after 361 iterations on the Threadripper and both Macs, and after 342 on the TITAN RTX, so the card's solution may differ from the one checked here.🤖 Generated with Claude Code