Skip to content

Whole lectures: lecture-python.myst on the T4 runner and its CPU - #22

Merged
mmcky merged 1 commit into
mainfrom
whole-lectures-python-t4
Nov 1, 2026
Merged

mmcky merged 1 commit into
mainfrom
whole-lectures-python-t4

Conversation

@mmcky

@mmcky mmcky commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

lecture-python.myst's 33 JAX lectures on the lectures' CI runner, RunsOn's g4dn.2xlarge: three runs of each on the T4 and on its own Xeon, from run 41271786393 of the run_lectures job added in #19. Part of #4. The per-lecture table is in the README's lecture-python section, beside the M5 Pro's.

T4 Xeon M5 Pro
All lectures, median of three runs 1,630 s for 32 6,978 s 1,463 s
As the runner builds them, on the T4 except sargent_surico 2,504 s
  • The T4 wins the large computations and loses the small ones, as in lecture-jax. It is ahead by more than 2× on 9 lectures, by 18× to 39× on imp_sample, kesten_processes, ifp_advanced and aiyagari_egm. Its own CPU is ahead by more than 2× on 5.
  • Building everything on the CPU would take 2.8× as long, mostly imp_sample: 4,050 s on the Xeon, against 104 s on the T4.
  • endogenous_lake takes 499 s on the T4 against 24 s on the Xeon. One cell runs a Python bisection 1,200 times, each step a jitted solve with a lax.while_loop of small iterations, so the card pays its latency at every step. It carries 475 s of the ~840 s that building each lecture on the faster device would save.
  • sargent_surico pins its JAX to the CPU, in the cell that first imports JAX, so its time on the runner is the Xeon's: 874 s, close to the 14m52s 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 reports for it there once pinned.

A harness change in lectures/run_lecture.py. Under the card's JAX_PLATFORMS=cuda, sargent_surico's request for the CPU made the harness's own jax.devices() raise after every cell had run, so the three runs wrote no result (their tracebacks are the cuda-*.err files). It now resets the platform, records the error as platform_error, and keeps the row with its failed cells. Tested locally with a two-cell lecture that asks for a withheld platform: before, no row; after, the row with the failed cell and the error.

A correction to the README. It said sargent_surico's 158 s on the M5 Pro matches #1022's 157 s, but #1022's figure is its NUTS cell, not the lecture. On the M5 Pro that cell takes 67 s, and #1022 reports 309 s for the lecture on a laptop.

The two jobs' environment.txt files are identical, so one is kept. The artifact's 2026-10-25/whole/ directory is the committed lecture-jax results that the upload's path also matched, and is left out.

🤖 Generated with Claude Code

Run 41271786393 of the run_lectures job with lecture-python (#19), on
RunsOn's g4dn.2xlarge, three runs of the 33 lectures on each device.
The README's lecture-python section gains the per-lecture table.

run_lecture.py: a lecture that asks for a platform the run withholds
(sargent_surico sets jax_platform_name to cpu, under JAX_PLATFORMS=cuda)
made jax.devices() raise after the cells had run, so no row was written.
It now resets the platform, records platform_error, and keeps the row.

Also corrects the README's sargent_surico comparison with
QuantEcon/lecture-python.myst#1022, whose 157 s is the NUTS cell, not
the lecture.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 1, 2026 10:10

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.

🟢 Approval recommended

The review surfaced no objective defects, with the lone code change being a small, well-scoped harness fix and the remaining files intentionally committed benchmark artifacts and traceback evidence.

No open issues 🎉

What changed in this PR

This PR records the results of running lecture-python.myst's 33 JAX lectures three times each on the lectures' CI runner (RunsOn g4dn.2xlarge) — on the T4 GPU and on its host Xeon CPU — as part of issue #4, using the run_lectures job added in #19. Alongside the data, it makes one harness fix so that sargent_surico (which pins JAX to the CPU, a backend withheld under JAX_PLATFORMS=cuda) still produces a result row instead of crashing the whole run.

Changes:

  • Harness fix in lectures/run_lecture.py: wrap jax.devices() in a try/except RuntimeError, record the failure as platform_error, reset jax_platform_name, and retry so the row (with its failed cells) is still written.
  • Commit per-lecture benchmark results as cuda-*/cpu-* JSON under lectures/results/runson-g4dn.2xlarge/2026-11-01/lecture-python/.
  • Keep the three pre-fix sargent_surico/cuda-*.err tracebacks as evidence of the failure the harness change addresses.
File Description
lectures/​run_lecture.py Adds try/except around jax.devices() to tolerate a withheld platform, record platform_error, and still write the row. The retry resolves to the available backend under the job's JAX_PLATFORMS, and all cells have already run/been recorded by this point, so the inline comment holds.
.../​lecture-python/​sargent_surico/​cuda-{1,2,3}.err Pre-fix tracebacks (RuntimeError: Unknown backend cpu) kept as the evidence motivating the harness change; not matched by any gitignore rule, so intentionally committed.
.../​lecture-python/​mccall_risk/​{cuda,cpu}-as-written-{1,2,3}.json Three T4 and three Xeon runs of mccall_risk (as-written, float32).
.../​lecture-python/​mccall_persist_trans/​{cuda,cpu}-as-written-{1,2,3}.json Three T4 and three Xeon runs of mccall_persist_trans.
.../​lecture-python/​mccall_model_with_separation/​{cuda,cpu}-as-written-{1,2,3}.json Three T4 and three Xeon runs of mccall_model_with_separation.
.../​lecture-python/​kesten_processes/​{cuda,cpu}-as-written-{1,2,3}.json Runs showing the T4's large lead (GPU ~5 s vs CPU ~150 s on the plotting cell).
.../​lecture-python/​jv/​{cuda,cpu}-as-written-{1,2,3}.json Three T4 and three Xeon runs of jv.
.../​lecture-python/​inventory_dynamics/​{cuda,cpu}-as-written-{1,2,3}.json Three T4 and three Xeon runs of inventory_dynamics.
.../​lecture-python/​ifp_advanced/​{cuda,cpu}-as-written-{1,2,3}.json Runs where the CPU is far slower (~10 min vs ~22 s).
.../​lecture-python/​endogenous_lake/​{cuda,cpu}-as-written-{1,2,3}.json Runs showing the T4 losing badly (~499 s vs ~24 s) due to the Python bisection loop.
.../​lecture-python/​career/​{cuda,cpu}-as-written-{1,2,3}.json Three T4 and three Xeon runs of career.
.../​lecture-python/​ar1_turningpts/​{cuda,cpu}-as-written-{1,2,3}.json Three T4 and three Xeon runs of the NumPyro/ArviZ lecture ar1_turningpts.

Review effort: Balanced

@mmcky
mmcky merged commit 073ff29 into main Nov 1, 2026
1 check passed
@mmcky
mmcky deleted the whole-lectures-python-t4 branch November 1, 2026 10:26
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