From 9e344d13e6fef945ebde21097701943ad290beca Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Tue, 8 Sep 2026 09:33:58 -0400 Subject: [PATCH 1/2] results: XLA autotune vs Triton GEMM probe (job 342333) + doc corrections (PyAutoNerves#161) Add the pure-jax five-arm GEMM probe and its A100 submit script, and the results note showing that --xla_gpu_autotune_level=0 lowers the fp64 curvature GEMM to an un-tuned Triton kernel (25.5 ms vs 4.8 ms cuBLAS), that a level-4 run seeds the node-local per-fusion autotune cache so later level-0 runs look fixed, and that --xla_gpu_enable_triton_gemm=false alone restores cuBLAS. Correct the README "Settings suffice" bullet, amend the jax_compile close-out, and add an addendum to the delaunay_nn_breakdown autotune A/B section. No existing submit scripts touched. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01Jbzb2yHwJn5ScwqxngKPqi --- README.md | 9 +- hpc/batch_gpu/submit_xla_autotune_gemm_probe | 116 +++++++++++++++ results/notes/delaunay_nn_breakdown.md | 15 ++ results/notes/xla_autotune_triton_gemm.md | 127 ++++++++++++++++ scripts/misc/jax_compile/README.md | 13 ++ scripts/misc/jax_compile/gemm_probe.py | 147 +++++++++++++++++++ 6 files changed, 424 insertions(+), 3 deletions(-) create mode 100644 hpc/batch_gpu/submit_xla_autotune_gemm_probe create mode 100644 results/notes/xla_autotune_triton_gemm.md create mode 100644 scripts/misc/jax_compile/gemm_probe.py diff --git a/README.md b/README.md index 3d945499d..a5456a06b 100644 --- a/README.md +++ b/README.md @@ -114,9 +114,12 @@ likelihoods XLA compilation is a first-class cost in its own right — `scripts/misc/jax_compile/` measures trace / compile / first-call / steady-state separately per likelihood × transform. Standing conclusions: -- **Settings suffice** — the persistent compilation cache and `--xla_gpu_autotune_level=0` - (both shipped as autonerves defaults) take the worst measured first fit from - ~70 min to ~35 s. Never restructure a likelihood or sampler for compile time +- **Settings suffice** — the persistent compilation cache, `--xla_gpu_autotune_level=0` + and `--xla_gpu_enable_triton_gemm=false` (all shipped as autonerves defaults) take the + worst measured first fit from ~70 min to ~35 s; the Triton flag is there because at + autotune level 0 XLA's default Triton tile makes dense fp64 GEMMs ~5× slower than + cuBLAS ([`results/notes/xla_autotune_triton_gemm.md`](./results/notes/xla_autotune_triton_gemm.md)). + Never restructure a likelihood or sampler for compile time ([`scripts/misc/jax_compile/README.md`](./scripts/misc/jax_compile/README.md)). - **`af.MultiStartProdigy` compile is a non-problem** on MGE and every pixelized mesh (rectangular / KNN / Delaunay) — ≤ 75 s cold, ≤ 2 s warm on a 32-core diff --git a/hpc/batch_gpu/submit_xla_autotune_gemm_probe b/hpc/batch_gpu/submit_xla_autotune_gemm_probe new file mode 100644 index 000000000..4bf98d570 --- /dev/null +++ b/hpc/batch_gpu/submit_xla_autotune_gemm_probe @@ -0,0 +1,116 @@ +#!/bin/bash -l +# +# XLA GPU autotuning / Triton-GEMM probe (autolens_profiling, 2026-09-08). +# +# Five arms of one dense fp64 GEMM — the (15361 x 1560) mapping-matrix shape of +# the HST / Delaunay-1500 imaging cell's Curvature matrix (F) step — run in one +# job on one node, to separate the effect of --xla_gpu_autotune_level from the +# effect of the per-fusion autotune cache JAX persists under +# JAX_COMPILATION_CACHE_DIR. +# +# A level 0, fresh cache -- the shipped default on a virgin node +# B level 4, fresh cache -- XLA's default; writes autotune entries +# C level 0, reading B's cache -- the trap: level 0 gets B's kernel +# D level 0, reading its own -- level 0 stays slow when nothing seeded it +# E level 0 + triton_gemm=false -- the cure; cuBLAS without autotuning +# +# Each arm prints a RESULT line (compile_s / first_ms / steady_mean_ms), then +# the arm's cache listing and its autotune-entry count (AUTOTUNE_ENTRIES), and +# the job ends with an HLO pass reporting whether each arm's dot lowered to a +# Triton __triton_nested_gemm_fusion or to the __cublas$lt$matmul custom call. +# +# Findings: results/notes/xla_autotune_triton_gemm.md (job 342333). + +#SBATCH -J xla_autotune_gemm_probe +#SBATCH --partition=gpu +#SBATCH --gres=gpu:1 +#SBATCH --ntasks=1 +#SBATCH --cpus-per-task=4 +#SBATCH --mem=64gb +#SBATCH --time=00:30:00 +#SBATCH -o output/output.%A.out +#SBATCH -e error/error.%A.err + +# Derive the repo root from where this was submitted (hpc/batch_gpu/../..) +# rather than hardcoding the RAL checkout path, so this runs from a worktree. +export AP_ROOT="$(cd "${SLURM_SUBMIT_DIR:-$(dirname "$0")}/../.." && pwd)" +echo "AP_ROOT=$AP_ROOT" +source $AP_ROOT/activate.sh + +export JAX_PLATFORM_NAME=cuda +export JAX_PLATFORMS=cuda,cpu +export XLA_PYTHON_CLIENT_PREALLOCATE=false +export JAX_ENABLE_X64=True +export NUMBA_CACHE_DIR=/tmp/numba_cache +export MPLCONFIGDIR=/tmp/matplotlib + +# Per-arm scratch: compilation caches and HLO dumps. Wiped at the start of every +# job — arms A, B and E must each begin from an empty cache or the A/B is void. +S=$AP_ROOT/output/xla_autotune_probe +mkdir -p $S + +echo "=== node ===" +hostname +date +nvidia-smi +echo "python3: $(which python3)" +echo "scratch: $S" + +rm -rf $S/cache_A $S/cache_B $S/cache_E +rm -rf $S/hlo_A $S/hlo_B $S/hlo_C $S/hlo_D $S/hlo_E +mkdir -p $S/cache_A $S/cache_B $S/cache_E +mkdir -p $S/hlo_A $S/hlo_B $S/hlo_C $S/hlo_D $S/hlo_E + +BASE="--xla_disable_hlo_passes=constant_folding" + +run_arm () { + ARM=$1 + LEVELFLAGS=$2 + CACHE=$3 + echo "" + echo "############################################################" + echo "### ARM $ARM flags=[$LEVELFLAGS] cache=$CACHE" + echo "############################################################" + export XLA_FLAGS="$BASE $LEVELFLAGS --xla_dump_to=$S/hlo_$ARM --xla_dump_hlo_as_text" + export JAX_COMPILATION_CACHE_DIR=$CACHE + python3 -u $AP_ROOT/scripts/misc/jax_compile/gemm_probe.py $ARM || echo "ARM $ARM FAILED" + echo "--- cache listing for $CACHE ---" + ls -R $CACHE 2>/dev/null | head -20 + echo "--- autotune cache entry count ---" + echo -n "AUTOTUNE_ENTRIES arm=$ARM count=" + ls $CACHE/xla_gpu_per_fusion_autotune_cache_dir 2>/dev/null | wc -l +} + +run_arm A "--xla_gpu_autotune_level=0" $S/cache_A +run_arm B "--xla_gpu_autotune_level=4" $S/cache_B +run_arm C "--xla_gpu_autotune_level=0" $S/cache_B +run_arm D "--xla_gpu_autotune_level=0" $S/cache_A +run_arm E "--xla_gpu_autotune_level=0 --xla_gpu_enable_triton_gemm=false" $S/cache_E + +echo "" +echo "############################################################" +echo "### HLO lowering analysis" +echo "############################################################" +for ARM in A B C D E; do + D=$S/hlo_$ARM + echo "--- arm $ARM ($D) ---" + ls $D 2>/dev/null | head -20 + CUB=$(cd $D 2>/dev/null && grep -l -E 'custom_call_target="__cublas\$gemm"|__cublas\$lt\$matmul' *after_optimizations*.txt 2>/dev/null | head) + TRI=$(cd $D 2>/dev/null && grep -l -E 'triton_gemm|__triton' *after_optimizations*.txt 2>/dev/null | head) + echo "LOWERING arm=$ARM cublas_files=[$CUB] triton_files=[$TRI]" + if [ -n "$CUB" ] && [ -z "$TRI" ]; then echo "LOWERING_VERDICT arm=$ARM cuBLAS" + elif [ -n "$TRI" ] && [ -z "$CUB" ]; then echo "LOWERING_VERDICT arm=$ARM Triton" + elif [ -n "$TRI" ] && [ -n "$CUB" ]; then echo "LOWERING_VERDICT arm=$ARM both" + else echo "LOWERING_VERDICT arm=$ARM unknown"; fi + echo "--- dot lines arm=$ARM ---" + for f in $D/*after_optimizations*.txt; do + [ -e "$f" ] || continue + echo " file: $(basename $f)" + grep -E 'custom-call|kind=kCustom' "$f" 2>/dev/null | head -5 + done +done + +echo "" +echo "=== RESULT LINES ===" +date +echo "Finished." diff --git a/results/notes/delaunay_nn_breakdown.md b/results/notes/delaunay_nn_breakdown.md index 97ad85bd6..43fda4ad6 100644 --- a/results/notes/delaunay_nn_breakdown.md +++ b/results/notes/delaunay_nn_breakdown.md @@ -490,6 +490,21 @@ program alone, +1.59 s across all breakdown compiles and +8.75 s across the runt cell's lower/compile/first-call phases — so the flag pays for itself after ~68 calls of the F step and ~453 batched likelihood evaluations respectively. +### Addendum (2026-09-08) + +The pair above is real, but the level-0 rows recorded after it — 342315, 342316, 342321 +and 342322, all measuring F at 4.80–4.83 ms with autotuning still off — do **not** +contradict it. They were reading a per-fusion autotune cache that jobs 342282/342283 +seeded on `euclid-ral-gpu-2`: JAX persists XLA's autotune cache under +`JAX_COMPILATION_CACHE_DIR` keyed by fusion fingerprint rather than by the autotune +flag, and RAL `$HOME` is node-local. The controlled fresh-cache-per-arm probe (job +342333, 2026-09-08) reproduces the pair on a bare GEMM — 25.52 ms at level 0 against +4.92 ms at level 4 — and shows the level-0 arm lowering to an un-autotuned Triton +fusion. The cure is not to re-enable autotuning but to add +`--xla_gpu_enable_triton_gemm=false`, which reaches cuBLAS (4.79 ms) with no autotune +compile cost; adopted in PyAutoNerves#161. Full write-up: +[`xla_autotune_triton_gemm.md`](./xla_autotune_triton_gemm.md). + ## See also - `results/notes/preopt_breakdown_baseline.md` — the 2026-07-10 A100 tier this note diff --git a/results/notes/xla_autotune_triton_gemm.md b/results/notes/xla_autotune_triton_gemm.md new file mode 100644 index 000000000..3b9bb2a57 --- /dev/null +++ b/results/notes/xla_autotune_triton_gemm.md @@ -0,0 +1,127 @@ +# XLA autotuning, Triton GEMM and the persistent autotune cache (A100, 2026-09-08) + +PyAutoNerves issue #161, task `xla-triton-gemm-off`. Controlled probe: +`scripts/misc/jax_compile/gemm_probe.py` via +`hpc/batch_gpu/submit_xla_autotune_gemm_probe`. + +## What was measured and why + +The 2026-09-05 A/B in [`delaunay_nn_breakdown.md`](./delaunay_nn_breakdown.md) +("XLA GPU autotuning A/B") measured the Curvature matrix (F) step at **25.63 ms** +with the shipped `--xla_gpu_autotune_level=0` against **4.90 ms** at XLA's default +level 4 — a 5.2× penalty on one dense fp64 GEMM. But four later jobs (342315, +342316, 342321, 342322), all with autotuning still at level 0, measured F at +**4.80–4.83 ms** with `curvature_matrix_jit_compile` at 0.066 s. Both cannot be +explained by the flag alone, so the flag was not the whole story. This note is the +controlled experiment that separates the flag from the state it leaves behind. + +## Job + +| Job | Node | GPU | Start (2026-09-08) | Elapsed | State | +|---|---|---|---|---:|---| +| 342333 | `euclid-ral-gpu-2` | NVIDIA A100 80GB PCIe | 13:32:26 | 0:14 | COMPLETED | + +`jax 0.10.2`, `jax_persistent_cache_min_compile_time_secs=0`, +`jax_persistent_cache_enable_xla_caches = xla_gpu_per_fusion_autotune_cache_dir`. The +timed program is `F = (M*w[:,None]).T @ (M*w[:,None])` with `M` a (15361, 1560) float64 +array from `default_rng(0)` — the masked-pixel × mesh-vertex mapping-matrix shape of the +HST / Delaunay-1500 cell, likelihood stripped away. All five arms in one job, one node. + +## Arms + +Every arm carries `--xla_disable_hlo_passes=constant_folding` plus the HLO dump +flags; the arms differ only in the autotune/Triton flags and in which +`JAX_COMPILATION_CACHE_DIR` they are pointed at. **A** is level 0 on a fresh cache +(the shipped default on a node nothing has seeded); **B** is level 4 on a fresh +cache (XLA's own default); **C** is level 0 pointed at the cache **B** just wrote; +**D** is level 0 pointed at its own cache **A** wrote; **E** is level 0 plus +`--xla_gpu_enable_triton_gemm=false` on a fresh cache. + +## Results + +| arm | flags beyond the base | cache | compile s | first ms | steady mean ms | steady min ms | autotune entries after | lowering | +|---|---|---|---:|---:|---:|---:|---:|---| +| A | level 0 | fresh `cache_A` | 0.461 | 25.99 | 25.523 | 25.338 | 0 | Triton `__triton_nested_gemm_fusion`, num_warps=2, output_tiles [16,8], num_stages=1 | +| B | level 4 | fresh `cache_B` | 2.080 | 5.50 | 4.918 | 4.815 | 3 | cuBLASLt `__cublas$lt$matmul`, selected_algorithm 1 | +| C | level 0 | `cache_B` (seeded by B) | 0.072 | 43.8 | 4.832 | 4.711 | 3 | cuBLASLt algorithm 1 | +| D | level 0 | `cache_A` (own) | 0.005 | 25.76 | 25.510 | 25.326 | 0 | Triton (executable-cache hit) | +| E | level 0 + `--xla_gpu_enable_triton_gemm=false` | fresh `cache_E` | 0.074 | 43.4 | 4.789 | 4.696 | 0 | cuBLASLt, `autotune_workspace_size` 0 | + +## HLO lowering + +Arm A (and D) lower the dot to a Triton fusion carrying XLA's *default* tile +configuration — never measured, because nothing autotuned it: + +``` +%gemm_fusion_dot_general.1 = f64[1560,1560]{1,0} fusion(...), kind=kCustom, + backend_config={..."fusion_backend_config":{"kind":"__triton_nested_gemm_fusion", + "block_level_fusion_config":{"num_warps":"2","output_tiles":[{"sizes":["16","8"]}], + "num_ctas":1,"num_stages":1,...}}...} +``` + +Arms B, C and E lower it to the cuBLASLt custom call instead: + +``` +%custom-call.1 = (f64[1560,1560]{1,0}, s8[4194304]{0}) custom-call(...), + custom_call_target="__cublas$lt$matmul", + backend_config={..."gemm_backend_config":{"selected_algorithm":"1","alpha_real":1, + "beta":0,...,"autotune_workspace_size":"4194304",...}...} +``` + +In arm E the same call carries `"autotune_workspace_size":"0"` and no +`selected_algorithm` — cuBLAS is reached without the autotuner running at all. + +## Mechanism + +JAX persists XLA's **per-fusion autotune cache** under `JAX_COMPILATION_CACHE_DIR` by +default, in `xla_gpu_per_fusion_autotune_cache_dir/`, keyed by fusion fingerprint — +*not* by the autotune flag. The flag **is** part of the executable-cache key, so arm C +was a genuine recompile (0.072 s, no executable hit) that nevertheless read arm B's +autotune entry and emitted B's cuBLAS kernel. Arm D hit the executable cache outright +(0.005 s) and stayed on Triton. + +RAL `$HOME` — hence the default cache root `~/.cache/pyauto_jax` — is **node-local**. The +2026-09-05 level-4 jobs 342282 and 342283 therefore seeded `euclid-ral-gpu-2`, and every +later level-0 run on that node (342315, 342316, 342321, 342322) read that seeded entry: +F 4.80–4.83 ms, `curvature_matrix_jit_compile` 0.066 s. The two 2026-09-05 level-0 rows +(342277 on `gpu-1`, 342278 on `gpu-2`) predate any level-4 run on their nodes, which is +why they measured 25.6 ms. A level-0 run never writes autotune entries itself, so a +fresh node — or a new fusion shape on a seeded node — always pays the un-tuned Triton +default. + +## Numerics + +`F[0,0]` is `7685.1171726898065` in arms A, D and E (bit-identical) and +`7685.1171726897901` in arms B and C — about 2 ULP apart. The cure (arm E) +reproduces the Triton arms bit-for-bit, so adopting it changes no pinned value; it +is the autotuned cuBLAS kernel that sits 2 ULP away. + +## Consequences + +- **The A/B trap.** A valid autotune A/B needs a **fresh `JAX_COMPILATION_CACHE_DIR` per + arm**, or a node no level-4 run has ever touched; otherwise the level-0 arm quietly + inherits the level-4 arm's kernel and the comparison collapses — exactly what happened + to the four post-09-05 `gpu-2` rows. +- **Read the F compile time.** ~2 s means the autotuner ran; ~0.4 s means a real compile + without it (and so the slow Triton default); ~0.07 s or less means a cache hit and + tells you nothing about which kernel is underneath — check the HLO. +- **Dashboard rows recorded 2026-07-17 → 2026-09-08** (the window in which + `--xla_gpu_autotune_level=0` shipped without the Triton flag) are slow on GEMM-bound + steps *unless* the node's cache happened to be seeded. The `_autotune4` rows, and the + post-09-05 `gpu-2` rows, are the fast reference. + +## Cure + +Adopted in PyAutoNerves#161: keep `--xla_gpu_autotune_level=0` and also append +`--xla_gpu_enable_triton_gemm=false` by default, so dense fp64 GEMMs reach cuBLAS +without paying autotune compile time (an explicit autotune level or an explicit +Triton flag in `XLA_FLAGS` is still respected). + +## Files + +- `scripts/misc/jax_compile/gemm_probe.py` — the probe. +- `hpc/batch_gpu/submit_xla_autotune_gemm_probe` — the five-arm submit script. +- `results/notes/xla_autotune_triton_gemm.md` — this note. + +The raw job output lives on RAL under `/mnt/ral/jnightin/scratch_xla_autotune/` and is +not committed. diff --git a/scripts/misc/jax_compile/README.md b/scripts/misc/jax_compile/README.md index 39e277cd9..ec7d3942d 100644 --- a/scripts/misc/jax_compile/README.md +++ b/scripts/misc/jax_compile/README.md @@ -348,6 +348,19 @@ every point in the lifecycle. Any further reduction would come from upstream JAX (tracing speed, compile speed), not from this stack — no further engineering is warranted here. The compile-time arc (#71 → #74 → #77) is done. +**Amendment (2026-09-08) — autotune-off stays, but it needed a companion flag.** +Autotuning off remains the right compile-time call; finding 7's "no measurable +evaluation penalty", however, was measured on cells whose GEMMs were not the +bottleneck, or on a node whose per-fusion autotune cache a level-4 run had +already seeded (JAX persists that cache under `JAX_COMPILATION_CACHE_DIR` +keyed by fusion fingerprint, not by the autotune flag). The controlled +fresh-cache probe of 2026-09-08 (job 342333) found the un-autotuned Triton +kernel **5× slower than cuBLAS on a dense fp64 GEMM** — 25.52 vs 4.79 ms on the +(15361×1560) mapping-matrix shape — cured by additionally passing +`--xla_gpu_enable_triton_gemm=false`, which reaches cuBLAS with no autotune +compile cost at all (PyAutoNerves#161). Details, arms and HLO evidence: +[`results/notes/xla_autotune_triton_gemm.md`](../../../results/notes/xla_autotune_triton_gemm.md). + ## Multi-band `FactorGraphModel` `value_and_grad` — the heterogeneous-shape cliff The #71 → #77 census measured **single-band** cells only. Real multi-wavelength diff --git a/scripts/misc/jax_compile/gemm_probe.py b/scripts/misc/jax_compile/gemm_probe.py new file mode 100644 index 000000000..e23de59fa --- /dev/null +++ b/scripts/misc/jax_compile/gemm_probe.py @@ -0,0 +1,147 @@ +""" +XLA GPU autotuning / Triton-GEMM probe: one dense fp64 GEMM, one arm per run. + +Research instrument for the 2026-09-08 A/B that resolved why the 2026-09-05 +autotune pair in ``results/notes/delaunay_nn_breakdown.md`` (Curvature matrix F +at 25.63 ms with ``--xla_gpu_autotune_level=0`` vs 4.90 ms at level 4) appeared +to be contradicted by four later level-0 runs that measured F at ~4.8 ms. +The finding, the measured table and the cure are written up in +``results/notes/xla_autotune_triton_gemm.md``. + +The probe strips the likelihood away and times only the shape that moved: + + F = (M * w[:, None]).T @ (M * w[:, None]) + +with ``M`` a (15361, 1560) float64 array from ``numpy.random.default_rng(0)`` — +the masked-pixel x mesh-vertex mapping-matrix shape of the HST / Delaunay-1500 +imaging cell. It compiles that under ``jax.jit`` via the AOT API (``lower`` then +``compile``), times the first call and ten steady-state calls, and prints +``F[0, 0]`` at full float64 precision so the numerics of the two backends can be +compared. + +**Arms.** The script itself takes a single positional argument, the arm label, +and reads everything else from the environment — the caller (see +``hpc/batch_gpu/submit_xla_autotune_gemm_probe``) sets ``XLA_FLAGS`` and +``JAX_COMPILATION_CACHE_DIR`` per arm. What matters is the pairing of the two: + + A level 0, fresh cache -- the shipped default on a virgin node + B level 4, fresh cache -- XLA's own default, writes autotune entries + C level 0, B's cache -- level 0 reading an autotune cache B seeded + D level 0, A's cache -- level 0 re-reading its own (empty) cache + E level 0 + triton_gemm=false -- the cure, no autotuning needed + +Arms C and D are what make this a controlled experiment: JAX persists XLA's +per-fusion autotune cache under ``JAX_COMPILATION_CACHE_DIR`` (see +``jax_persistent_cache_enable_xla_caches``, printed below), keyed by fusion +fingerprint rather than by the autotune flag, so a level-0 run on a node whose +cache a level-4 run already seeded silently gets the autotuned kernel. A valid +autotune A/B therefore needs a **fresh cache directory per arm**, or a node no +level-4 run has ever touched. + +**Reading the output.** Each run ends with one machine-greppable line: + + RESULT arm= level= \ + compile_s=... first_ms=... steady_mean_ms=... steady_min_ms=... \ + cache_dir=... + +``compile_s`` is the tell for what happened: ~2 s means the autotuner actually +ran, ~0.4 s means a real compile without it, and ~0.07 s (or less) means a cache +hit. ``steady_mean_ms`` is the number the note tabulates. Set +``--xla_dump_to= --xla_dump_hlo_as_text`` in ``XLA_FLAGS`` to have the +submit script's HLO pass report whether the dot lowered to a Triton +``__triton_nested_gemm_fusion`` or to the ``__cublas$lt$matmul`` custom call. +""" + +import os +import socket +import subprocess +import sys +import time + +os.environ["JAX_ENABLE_X64"] = "True" + +ARM = sys.argv[1] if len(sys.argv) > 1 else "?" + +print(f"=== ARM {ARM} ===", flush=True) +print("hostname:", socket.gethostname(), flush=True) +print("XLA_FLAGS:", os.environ.get("XLA_FLAGS"), flush=True) +cache_dir = os.environ.get("JAX_COMPILATION_CACHE_DIR") +print("JAX_COMPILATION_CACHE_DIR:", cache_dir, flush=True) +try: + print(subprocess.run( + ["nvidia-smi", "--query-gpu=name,uuid", "--format=csv"], + capture_output=True, text=True, timeout=120).stdout, flush=True) +except Exception as e: + print("nvidia-smi failed:", e, flush=True) + +import numpy as np +import jax +import jax.numpy as jnp + +print("jax.__version__:", jax.__version__, flush=True) + +# Enable the persistent compilation cache the way autonerves does. +if cache_dir: + jax.config.update("jax_compilation_cache_dir", cache_dir) +jax.config.update("jax_persistent_cache_min_compile_time_secs", 0) +print("jax_persistent_cache_enable_xla_caches:", + jax.config.jax_persistent_cache_enable_xla_caches, flush=True) +print("jax.devices():", jax.devices(), flush=True) + +rng = np.random.default_rng(0) +M_np = rng.standard_normal((15361, 1560)).astype(np.float64) +w_np = (1.0 / (1.0 + rng.random(15361))).astype(np.float64) +M = jnp.asarray(M_np) +w = jnp.asarray(w_np) +jax.block_until_ready(M) +jax.block_until_ready(w) +print("dtypes:", M.dtype, w.dtype, "shapes:", M.shape, w.shape, flush=True) + + +def f(M, w): + A = M * w[:, None] + return jnp.dot(A.T, A) + + +jitted = jax.jit(f) + +t0 = time.perf_counter() +lowered = jitted.lower(M, w) +t1 = time.perf_counter() +compiled = lowered.compile() +t2 = time.perf_counter() +lower_s = t1 - t0 +compile_s = t2 - t1 +print(f"lower_s={lower_s:.4f} compile_s={compile_s:.4f}", flush=True) + +t3 = time.perf_counter() +out = compiled(M, w) +out.block_until_ready() +t4 = time.perf_counter() +first_ms = (t4 - t3) * 1e3 +print(f"first_ms={first_ms:.4f}", flush=True) + +times = [] +for _ in range(10): + ta = time.perf_counter() + o = compiled(M, w) + o.block_until_ready() + tb = time.perf_counter() + times.append((tb - ta) * 1e3) +steady_mean = float(np.mean(times)) +steady_min = float(np.min(times)) +print("per-call ms:", ["%.3f" % t for t in times], flush=True) + +val = np.float64(np.asarray(compiled(M, w))[0, 0]) +print("F[0,0] = %.17g" % val, flush=True) + +level = "?" +for tok in (os.environ.get("XLA_FLAGS") or "").split(): + if tok.startswith("--xla_gpu_autotune_level="): + level = tok.split("=", 1)[1] +print( + f"RESULT arm={ARM} level={level} compile_s={compile_s:.4f} " + f"first_ms={first_ms:.4f} steady_mean_ms={steady_mean:.4f} " + f"steady_min_ms={steady_min:.4f} cache_dir={cache_dir}", + flush=True, +) From e1ee55641f8cc056f72bca5d2994be8f102c5bbc Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Tue, 8 Sep 2026 09:43:34 -0400 Subject: [PATCH 2/2] lint(gemm_probe): sort imports, f-strings, ruff format Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01Jbzb2yHwJn5ScwqxngKPqi --- scripts/misc/jax_compile/gemm_probe.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/misc/jax_compile/gemm_probe.py b/scripts/misc/jax_compile/gemm_probe.py index e23de59fa..f715c807a 100644 --- a/scripts/misc/jax_compile/gemm_probe.py +++ b/scripts/misc/jax_compile/gemm_probe.py @@ -68,15 +68,21 @@ cache_dir = os.environ.get("JAX_COMPILATION_CACHE_DIR") print("JAX_COMPILATION_CACHE_DIR:", cache_dir, flush=True) try: - print(subprocess.run( - ["nvidia-smi", "--query-gpu=name,uuid", "--format=csv"], - capture_output=True, text=True, timeout=120).stdout, flush=True) + print( + subprocess.run( + ["nvidia-smi", "--query-gpu=name,uuid", "--format=csv"], + capture_output=True, + text=True, + timeout=120, + ).stdout, + flush=True, + ) except Exception as e: print("nvidia-smi failed:", e, flush=True) -import numpy as np import jax import jax.numpy as jnp +import numpy as np print("jax.__version__:", jax.__version__, flush=True) @@ -84,8 +90,11 @@ if cache_dir: jax.config.update("jax_compilation_cache_dir", cache_dir) jax.config.update("jax_persistent_cache_min_compile_time_secs", 0) -print("jax_persistent_cache_enable_xla_caches:", - jax.config.jax_persistent_cache_enable_xla_caches, flush=True) +print( + "jax_persistent_cache_enable_xla_caches:", + jax.config.jax_persistent_cache_enable_xla_caches, + flush=True, +) print("jax.devices():", jax.devices(), flush=True) rng = np.random.default_rng(0) @@ -130,10 +139,10 @@ def f(M, w): times.append((tb - ta) * 1e3) steady_mean = float(np.mean(times)) steady_min = float(np.min(times)) -print("per-call ms:", ["%.3f" % t for t in times], flush=True) +print("per-call ms:", [f"{t:.3f}" for t in times], flush=True) val = np.float64(np.asarray(compiled(M, w))[0, 0]) -print("F[0,0] = %.17g" % val, flush=True) +print(f"F[0,0] = {val:.17g}", flush=True) level = "?" for tok in (os.environ.get("XLA_FLAGS") or "").split():