Skip to content

perf(smoke): persist sub-second XLA compiles for the two slowest JAX scripts - #314

Closed
Jammy2211 wants to merge 3 commits into
mainfrom
claude/ci-smoke-test-speed-rzu8bg
Closed

Jammy2211 wants to merge 3 commits into
mainfrom
claude/ci-smoke-test-speed-rzu8bg

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Found by /ci_speedup auditing the five slowest entries on the CI smoke gate.
These are ranks #1 and #3 across all of CI.

What changes

config/build/profile_smoke.yaml only — two set: overrides, both
JAX_PERSISTENT_CACHE_MIN_COMPILE_TIME_SECS: "0":

pattern
imaging/jax_likelihood/delaunay.py rank #1, 32.8s py3.13
misc/jax_assertions/delaunay_nn.py rank #3, 31.8s py3.13

No script is touched. No assertion, tolerance, dataset size, or sizing knob
changes. Nothing is skipped, disabled or quarantined.

Why

Both scripts compile a long tail of small XLA executables. JAX's default
jax_persistent_cache_min_compile_time_secs is 1.0s, so those compiles are
never written to the persistent cache that PyAutoHeart's smoke-tests.yml
already restores and saves. The board's cache_jax: HIT is a hit on a cache
holding a handful of entries, so CI re-pays the same compile work every run —
which is why a "hit" sits next to a cold-looking number.

  • delaunay.py — 504 distinct executables, 471 compiled from scratch, 11.0s in
    backend_compile_and_load, ~50% of the run. jax.jit(analysis_jit.fit_from)
    traces only the FitImaging constructor (the jitted call is 0.018s); the
    cached_property chain that computes the likelihood runs eagerly outside it.
  • delaunay_nn.py — 312 compiles, 20.7s of 32.9s; 308 of them take under one
    second
    (15.0s) and only 4 clear the threshold.

Measured

Locally under this profile, libs from source, 4 cores, timing runs serialised
under a lock. Warm cache in both regimes:

script threshold 1.0 (CI today) threshold 0 (this PR)
delaunay.py 22.7 / 23.0 / 24.2 / 31.2s 10.1 / 10.3 / 10.6 / 10.6s
delaunay_nn.py 29.0 / 25.2s 13.5 / 13.6s

Cold cache is unchanged either way (delaunay.py 26.3 vs 28.0s;
delaunay_nn.py 32.9 vs 33.0s) — writing the extra entries costs nothing
measurable. The "before" bracket reproduces CI: the board has these at 32.8s and
31.8s on py3.13, both with cache_jax: HIT.

Why the assertions survive

The persistent cache is a memo of XLA compilation keyed on the lowered HLO, so a
hit returns the executable the compiler would have built. Printed output was
diffed byte-for-byte across both regimes and is identical — [-541.50627819 ×3],
NumPy -44.32005541739227, JIT -44.32005541740216, all PASS lines; and for
delaunay_nn.py the reconstruction parity, chunk-invariance 6/6, and
cap-headroom diagnostics are unchanged. RC=0 under smoke and under the release
profile. profile_smoke.yaml is smoke-only, so release is untouched.

Rejected, with measurements

The six SIBSON_* knobs delaunay_nn.py reads were all measured and rejected:
SIBSON_POINTS/QUERIES buy only 1.5s and weaken the headroom
assert not overflow.any() demonstrates; SIBSON_CAVITY/NEIGHBORS are caps
assertions compare against, so lowering them changes what is checked;
SIBSON_REPEATS is already 1; SIBSON_CHUNK 1024 is slower.

Note for review

The general fix is one line in PyAutoHeart's smoke-tests.yml beside
JAX_COMPILATION_CACHE_DIR — every JAX smoke script pays this tax. That is a
wider trade (it grows the cached artefact by ~500 entries per script), so it is
filed for a human as draft/refactor/pyautoheart/smoke_jax_cache_threshold.md
rather than taken here. This per-script override does not preclude it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ARBtVPNAVEZmdG2iDTqfMk


Generated by Claude Code

Jammy2211 and others added 3 commits September 10, 2026 04:27
…scripts

The board's two slowest entries in this workspace are dominated by XLA
compiles that the persistent cache never stores. JAX's default
jax_persistent_cache_min_compile_time_secs is 1.0s and PyAutoHeart's
smoke-tests.yml sets no threshold, so only executables taking >1s are written
to JAX_COMPILATION_CACHE_DIR. Both scripts compile hundreds of small ones:

  imaging/jax_likelihood/delaunay.py   504 executables, 471 compiled cold
  misc/jax_assertions/delaunay_nn.py   312 executables, 308 of them under 1s

CI therefore re-pays them on every run, which is why the board reports
cache_jax: HIT beside a number that matches a cold run -- the cache it hit
holds 2-4 entries.

Setting the threshold to 0 for these two scripts lets those executables be
persisted and reloaded. Measured locally, smoke profile, cache built and read
under each regime (timings serialised, n=3):

  imaging/jax_likelihood/delaunay.py
    threshold 1.0 (CI today)  23.4 / 24.6 / 27.1s   cache 2 entries, 480K
    threshold 0   (this)      10.4 / 10.5s          cache 513 entries, 2.9M
  misc/jax_assertions/delaunay_nn.py
    threshold 1.0 (CI today)  27.2 / 27.8s          cache 4 entries
    threshold 0   (this)      13.0 / 13.5s          cache 299 entries

First run against an empty cache is unchanged (32.6s vs 33.0s): writing the
extra entries costs nothing measurable. Board reference: 32.8s and 31.8s py3.13.

Neither script is touched, so the release profile is unaffected and every
assertion is untouched: this changes which XLA executables are persisted, not
the graph, dtypes, backend or arithmetic. Printed output diffed byte-for-byte
across both regimes, RC=0 throughout.

Verified with PyAutoHands' own tooling: env_config.build_env_for_script
resolves the override for exactly these two scripts and no others (jax_grad/
and delaunay_nn_caps.py correctly do not match), and validate_env_profiles
reports 0 errors, including under --strict-declarations.

The same tax is paid by every jax_likelihood/jax_grad script in the leg, so
the general fix is one line in defaults: or in PyAutoHeart's smoke-tests.yml
beside the cache step. That grows the cached artefact ~500 entries per script,
so it is left as a human's call; this is the minimal in-lane form.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ARBtVPNAVEZmdG2iDTqfMk
The previous commit on this branch un-ignored `test-results/` and committed
three generated files with it. They are build artefacts, not source:

  - test-results/smoke_timings.json
  - test-results/autolens_workspace_test__scripts__script.json
  - test-results/autolens_workspace_test__scripts__script.md

They are also stale and not from this branch's work -- the report bodies carry
laptop paths (/home/jammy/Code/PyAutoLabs-wt/...) and a 2026-09-08 timestamp,
and record three failing scripts unrelated to this change.

`test-results/` is gitignored on main deliberately; restoring that line is the
whole fix. This branch's actual change is the profile_smoke.yaml override and
nothing else.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ARBtVPNAVEZmdG2iDTqfMk
Two leftovers from how these blocks were drafted, comments only -- no
override, pattern or value changes:

  - a "append this entry to overrides: in ..." instruction header that was
    part of the proposal, not the file
  - an unresolved "the delaunay_nn_caps.py entry below/above it" -> "above it"

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ARBtVPNAVEZmdG2iDTqfMk

Copy link
Copy Markdown
Collaborator Author

Superseded on both halves, closing without merge:


Generated by Claude Code

@Jammy2211 Jammy2211 closed this Sep 10, 2026
@Jammy2211
Jammy2211 deleted the claude/ci-smoke-test-speed-rzu8bg branch November 25, 2026 20:21
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.

1 participant