Skip to content

Whole lectures: why float32 changes what seven lectures print - #18

Merged
mmcky merged 1 commit into
mainfrom
float32-causes
Nov 1, 2026
Merged

mmcky merged 1 commit into
mainfrom
float32-causes

Conversation

@mmcky

@mmcky mmcky commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

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 4b939ec and swaps a single ingredient between the precisions: the random sample, the arithmetic, or the tolerance.

What they show

Lecture What changes in float32 Why
hopenhayn The equilibrium price is 1.528, against 1.364 The Monte Carlo draws. float32 arithmetic on float64's draws gives 1.363800, float64's price
mle_jax The estimate ends at NaN after 2 iterations, without an error The sample: float32's draws include y = 250,341. float32 arithmetic on float64's data gives float64's estimate to 7 digits, while float64 on float32's data stops at its 100-iteration cap
markov_asset_jax The stability check fails The power iteration's random start vector. From float64's start vector, float32 gives 0.9051, float64's estimate
arellano_jax The borrowing policy differs at 4,222 of 12,801 states, by up to 8 grid steps; the default region at 34; bond prices by more than 0.1 at 113 The arithmetic. There are no random numbers, and float64's solution is the same at tolerances from 1e-5 to 1e-10
opt_invest, opt_savings_2 Policy iteration runs to its 250-loop cap Near-ties that float32 can't settle. The policy is float64's at all but 1 and 70 of 15,000 states, one grid step away; float64's own VFI and OPI differ from its HPI at 2 and 7
ifp_egm_jax The Numba solve takes 2.5× to 3× as long Numba's np.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 and arellano_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-gpu and qe-wharton2 are in use by another project. The float32 runs of arellano_jax stop 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

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]>
Copilot AI balanced review requested due to automatic review settings November 1, 2026 02:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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.sh that reproduce and attribute the float32 differences for mle_jax, hopenhayn, markov_asset_jax, arellano_jax, opt_invest/opt_savings_2, and ifp_egm_jax, with their captured output in float32.txt.
  • README.md's float32 table gains a "why" for each lecture, plus two bullets separating random-sample effects from arithmetic effects (arellano_jax being 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants