Skip to content

research: fixed-light follow-up round 3 — the non-solver levers on numba CPU and the A100 together (phase 3) #267

Closed

Description

@Jammy2211

Overview

Phase 3 of the fixed-lens-light-numba-cpu epic, and the round the human asked for after phase 2
(#265, PR #266) closed the NNLS question. Phase 2's verdict: fixing the lens light is worth
2.03x on the production numba CPU path (HST Delaunay N=1500, RAL job 343311, 1 thread,
932.387 -> 459.220 ms, no library change), and the solver is finished — the library's
cross-evaluation memo is ON by default and already delivers 1.134x against the factor-reuse
kernel's 1.112x, so the conditional nnls_seed_factor_reuse PyAutoArray prompt was deliberately
not filed.

What is left is the non-solver residue: regularization_matrix 111.5 ms, log-det
F + lambda*H 40.2 ms, log-det H 37.5 ms — 189.1 ms, 47 % of the 404.6 ms call, and
every one of them invariant under the memo. This phase attacks those three sites, and — as the
request asks — pairs every lever with an A100 row.

DEFERRED START. The plan is filed and parked: no worktree, no branch, no code change yet.
Resume with /start_dev active/fixed_light_numba_s3_regularization_logdet_levers.md.

Plan

  • Lever 1 — jit the split-regularization assembly on the numpy/numba path.
    reg_split_np_from and pixel_splitted_regularization_matrix_np_from
    (autoarray/inversion/regularization/regularization_util.py:115-168, :274-312) are pure-Python
    loops doing ~120k interpreted scalar writes; the file contains zero numba. PyAutoArray#536
    optimised the JAX branch only. Two @numba_util.jit() kernels replicating the accumulation
    order bit-for-bit, the pure-Python bodies retained as _reference (the JAX tests use
    ..._np_from as ground truth). Three defects fixed as recorded behaviour changes: in-place
    mutation of the interpolators' cached_property tables, the size == 0 j-leak, and the
    unbounded insert. Expected 111.5 ms -> a few ms, whole call ~405 -> ~295 ms, ~1.37x — the
    largest number available in this campaign.
  • Lever 2 — log_det_regularization_matrix_term factorises a sparse matrix densely.
    abstract.py:896-941 falls through to a dense cholesky of a ~20-non-zeros-per-row matrix
    (37.5 ms). The docstring at :903 claiming scipy sparse is stale and is fixed regardless;
    the slogdet shortcut is unreachable on the default path. Options in order: splu log-det,
    banded Cholesky after RCM, or a mesh+weights cache (noting AdaptSplit weights move with the
    adapt image). The JAX/GPU branch stays untouched.
  • Lever 3 — one shared Cholesky of F + lambda*H for the solve, the seed and the log-det. The
    same matrix is factorised three times per call (_log_det_symmetric_from, fnnls_cholesky's
    retained-but-unreturned U_buffer, the dense seed at inversion_util.py:434-436) at a passive
    set of ~1485 of 1500. S3 only. Folds in
    draft/bug/autoarray/curvature_reg_matrix_rebuilt_every_access.md — phase 1's n_calls >= 2
    assertion on that property is the intended handshake and fails loudly if a cache lands.
  • Pairing is per lever, not a follow-up phase. CPU leg: RAL gpu partition CPUs-only
    (no --gres), 1 thread across numba and the whole BLAS family, A/B against a private merge-base
    PyAutoArray on PYTHONPATH — never the shared /mnt/ral/jnightin/PyAuto install. A100 leg:
    fp64, budget 7 on Delaunay, PDIP fallback, positivity never dropped.
  • Pins on every leg of both hosts: log evidence to <= 1e-9 relative; the regularization matrix
    bit-identical to the retained Python reference on the numba path; log_likelihood is not
    comparable across legs; no comparison crosses a thread setting silently.
  • One lever at a time, in order 1 -> 2 -> 3, each landing its own PyAutoArray PR (pending-release)
    plus an autolens_profiling follow-up PR with the cells, JSONs and the note.
Detailed implementation plan

Affected Repositories

  • autolens_profiling (primary — cells, JSONs, results/notes/ verdict note)
  • PyAutoArray (the library edits for all three levers)

Branch Survey

Repository Current Branch Dirty?
./autolens_profiling main clean
./PyAutoArray main clean

Suggested branch: feature/fixed-light-numba-levers (NOT created — deferred start)

Implementation Steps

  1. Lever 1: read autoarray/inversion/mesh/interpolator/knn.py:374 and :428-432 first (the
    in-place growth and reserved pad column are deliberate), then write the two jitted kernels,
    retain the Python bodies as _reference, pin bit-identity in the test suite (precedent:
    autoarray/inversion/mesh/interpolator/rectangular.py:144-160).
  2. Lever 1 A100 row: confirm Profile the Simple cluster on CPU and validate its member catalogue #536's compacted scatter (SPLIT_REG_COMPACT_WIDTH,
    SPLIT_REG_WIDE_ROW_BUDGET, the wide-row supplement, the NaN overflow poison) is the path the
    A100 Delaunay cell actually runs, then measure it.
  3. Lever 2: fix the stale :903 docstring; try splu / banded-Cholesky-after-RCM / cache in that
    order; measure the dense GPU counterpart.
  4. Lever 3: shared full Cholesky — seed via cho_solve, down-date the active columns out of it
    (choldeleteindexes_inplace, cholesky_funcs.py:243), read the log-det off the same factor;
    resolve the curvature_reg_matrix rebuild bug prompt as part of it.
  5. Each lever: one RAL CPU leg + one A100 leg, both with configuration.thread_env /
    numba_thread_env recorded, then the verdict note.

Key Files

  • autoarray/inversion/regularization/regularization_util.py:115-168, :274-312 — lever 1
  • autoarray/inversion/mesh/interpolator/knn.py:374, :391+, :428-432 — the mutated tables
  • autoarray/inversion/inversion/abstract.py:850-880, :882-893, :896-941, :358-370 — levers 2+3
  • autoarray/util/fnnls.py:102-120, autoarray/util/cholesky_funcs.py:243 — lever 3
  • autoarray/inversion/inversion/inversion_util.py:434-436 — the dense seed
  • scripts/imaging/likelihood_breakdown/fixed_light_numba.py, call_accounting.py — phase 2's cells
  • results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_sparse_b_warm_t1.json

Out of scope

Rectangular meshes; Euclid; the sparse-operator / profile-subtracted-image bug; JWST; any
reopening of the NNLS solver scheme; and the memo-robustness question, which is phase 4.

If it must be split

Split along the levers, never between a lever and its A100 row: this phase carries lever 1,
the campaign map holds levers 2 and 3 as phases 3b and 3c. (Intake's sizing faculty derived
too-large, score 15; large is kept per the prompt's own instruction, recorded as a
Sizing-note: header.)

Original Prompt

Click to expand starting prompt

Fixed-light follow-up round 3 — the non-solver levers on numba CPU and the A100 together

Type: research
Target: autolens_profiling
Repos:

  • autolens_profiling
  • PyAutoArray
    Themes:
  • profiling
  • pixelization
  • cpu
  • numba
  • gpu
  • inversion
    Difficulty: large
    Sizing-note: the intake sizing faculty derived too-large (score 15); large is kept per this prompt's own
    instruction under "Scope and guards" — if it must be split, split along the levers (1, then 2, then 3),
    never between a lever and its A100 row.
    Autonomy: human-required
    Priority: high
    Status: formalised
    Epic: fixed-lens-light-numba-cpu
    Phase: 3
    Consequence: judge
    Witness: At HST Delaunay N=1500 on both hosts, each lever returns the library's own log evidence
    to <= 1e-9 relative; the rebuilt regularization matrix is bit-identical to the retained pure-Python
    reference on the numba path; the phase-2 cell's decomposition sums to the measured clean call within
    1 %; and the note carries one before/after whole-call table per host (RAL numba CPU, A100 fp64) with
    every thread and backend block recorded per leg.
    Review-minutes: 30
    Unattended: never
    Filed: 2026-09-16

Original request (verbatim)

Ok so have we finished the nnls speed up? HAppy if so but want to mark that milestone and
complete issue and intake new issue for the next round of follow up (Which will be paired with
A100 speed up)

Where the campaign stands — the NNLS round is closed

Phase 2 (autolens_profiling#265, PR #266) answered the solver question and the answer is no
further solver work
:

  • Fixing the lens light is worth 2.03x on the production numba CPU path — HST Delaunay
    N=1500, sparse numba operator, 1 thread, RAL SLURM job 343311 on an idle gpu-partition node
    used CPUs-only: route a (S0 joint, 1560 params) 932.387 ms -> route b (S3 source-only,
    1500 params) 459.220 ms on medians, with no library change at all, corroborated at
    2.036x on a second host and a different CPU vendor.
  • The solver is finished. The library's own cross-evaluation NNLS memo — ON by default and
    therefore already in production — takes the call to 404.597 ms (1.134x); the factor-reuse
    NNLS built for phase 2 reaches only 412.556 ms (1.112x). They are 1.97 % apart, so the
    conditional nnls_seed_factor_reuse PyAutoArray prompt phase 2 was authorised to file was
    deliberately not filed. What is left inside fnnls_cholesky is ~37.7 ms, 9.3 % of the
    call, against an unconstrained floor — a <= 1.1x lever. This phase does not reopen it.

This phase goes after what phase 2's own verdict named as bigger than the solver, and pairs each
lever with the A100, which is what the request asks for.

The residue this phase attacks

Leg D, route b, memo ON (results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_sparse_b_warm_t1.json),
the 404.597 ms call production actually pays. Exclusive per-site ms:

site ms % of 404.6 ms call
inversion.regularization_matrix 111.501 27.6
sparse_numba.curvature_matrix 87.416 21.6
solver.fnnls_cholesky 62.789 15.5
inversion.log_det_curvature_reg_matrix_term 40.172 9.9
inversion.log_det_regularization_matrix_term 37.468 9.3
delaunay.triangulation 18.508 4.6
inversion.curvature_reg_matrix (n_calls = 2) 4.056 1.0

The three target sites are 189.1 ms, 47 % of the call, and every one of them is invariant
under the memo — Leg A's memo-off decomposition reads 112.252 / 40.803 / 37.753 ms for the same
three. The solver's share moves with the memo; these do not.

The A100 counterpart, from the paired campaign map
(draft/research/autolens_profiling/hst_gpu_non_solver_residue_programme.md, epic
hst-gpu-non-solver-residue): of the certified 25.39 ms Delaunay call at HST N=1500, the
F + lambda*H build is 4.92 ms, the two log-dets 1.17 + 1.20 = 2.37 ms, and
~13.9 ms is mesh, mapper and weights — i.e. ~21 of 25.4 ms is not the solver there either.
Those GPU numbers are that map's phase-1 attribution, not a measured decomposition; this phase
measures its own A100 rows rather than quoting them as truth.

The three levers, in order — 1, then 2, then 3

Lever 1 — jit the split-regularization assembly on the numpy/numba path

AdaptSplit / ConstantSplit / AdaptiveBrightnessSplit build their regularization matrix
through two pure-Python loops in PyAutoArray:

  • reg_split_np_from — autoarray/inversion/regularization/regularization_util.py:115-168
  • pixel_splitted_regularization_matrix_np_from — :274-312, a 4-deep loop doing
    ~120k interpreted scalar writes into a dense (P, P)

The file contains zero numba (grep -n "numba_util\|@numba" returns nothing). PyAutoArray#536
(04152bb7, "compact the ConstantSplit split-stencil scatter") optimised the JAX branch of
pixel_splitted_regularization_matrix_from only
and explicitly left the numpy path alone. That
is why this is the largest site in the numba call and why no cost model in the campaign flagged it.

The fix. Two @numba_util.jit() kernels replicating the accumulation order bit-for-bit:
the 2e-8 diagonal jitter written first, both-triangle adds in the same l / l+m order, the
trailing /= 2.0 on the diagonal last. Wrap them in copy-then-jit functions that keep the public
_np_from names, because test_autoarray/inversion/regularizations/test_pixel_splitted_jax.py
uses pixel_splitted_regularization_matrix_np_from as its ground truth for the JAX branch
(lines 74-75, 121, 139, 152, 181, 221). Three defects to fix while the loops are being rewritten,
each of which must be recorded as a behaviour change rather than smuggled in:

  1. The inputs are mutated in place. reg_split_np_from writes
    splitted_mappings[i][j+1], grows splitted_sizes[i] and writes into splitted_weights, and
    the arrays it is handed come from the interpolators' cached_property _mappings_sizes_weights_split
    tables (autoarray/inversion/mesh/interpolator/knn.py:391+, and the Delaunay sibling). Copy on
    entry. Read knn.py:374 and :428-432 before touching this — those comments document the
    in-place growth and the reserved pad column as deliberate, so the copy must preserve the
    returned (mappings, sizes, weights) contract and the pad column, not remove them.
  2. The size == 0 j-leak. for j in range(splitted_sizes[i]) leaves j from the previous
    row when a row is empty, and the flag-zero branch then writes at j + 1. Use an explicit
    insert = sizes[i].
  3. No bound on the insert. Guard insert < K before writing into the reserved column.

Keep the current pure-Python bodies as _reference implementations and pin the jitted kernels
against them in the test suite — the precedent is
autoarray/inversion/mesh/interpolator/rectangular.py:144-160, where a windowed numba kernel
replaced a blocked numpy sum and the numpy implementation is retained as the JAX-path reference.

Expected. 111.5 ms -> a few ms; whole call ~405 -> ~295 ms, ~1.37x. That is the single
largest number available anywhere in this campaign.

A100 row. Confirm that #536's compacted scatter is the path the A100 Delaunay cell actually
runs (SPLIT_REG_COMPACT_WIDTH, SPLIT_REG_WIDE_ROW_BUDGET, the wide-row supplement and the NaN
overflow poison), then measure it, rather than assuming the GPU map's attributed
F + lambda*H 4.92 ms already covers it. If the compaction is not on the running path, that is
the A100 finding of lever 1.

Lever 2 — log_det_regularization_matrix_term factorises a sparse matrix densely

AbstractInversion.log_det_regularization_matrix_term
(autoarray/inversion/inversion/abstract.py:896-941) falls through to _log_det_symmetric_from
(:850-880), i.e. a dense cholesky of regularization_matrix_reduced — a matrix with
~20 non-zeros per row at N=1500 under the split stencil. 37.5 ms on numba CPU.

Two things to establish before optimising:

  • The docstring at :903 is stale. It claims the term "uses scipy sparse linear algebra to
    solve the determinant efficiently". It does not. Fix the docstring in whatever PR touches this,
    regardless of which option below lands.
  • The shortcut is not reachable by default. log_det_regularization_matrix_term_from is
    consulted only under settings.log_det_method == "slogdet" and
    all_linear_obj_have_regularization, and it returns None for every non-kernel scheme — so on
    the default "cholesky" path with AdaptSplit it never runs.

Options, in the order to try them: scipy.sparse.linalg.splu log-det on the numpy/numba path;
a banded Cholesky after an RCM permutation; or a cache keyed on the mesh and weights — noting that
AdaptSplit's weights move with the adapt image, so a "mesh is fixed" cache is wrong for the
scheme this campaign actually measures. Whichever lands must leave the JAX/GPU branch untouched.

A100 row. Measure the dense counterpart on the GPU (the map attributes 1.20 ms to log det(H)),
so the verdict says whether this lever is CPU-only or worth carrying to both.

Lever 3 — one shared Cholesky of F + lambda*H for the solve, the seed and the log-det

log_det_curvature_reg_matrix_term (abstract.py:882-893) calls _log_det_symmetric_from on
curvature_reg_matrix_reduced, i.e. a full potrf of F + lambda*H. The same matrix is
factorised twice more in the same call:

  • fnnls_cholesky (autoarray/util/fnnls.py:102-120) factorises the warm-start passive set once
    into U_buffer and keeps it — Leg B measured n_passive 1485 of n=1500 on the library's own
    cold row (1483-1490 across the Leg B rows) — and never returns that factor;
  • the dense seed np.linalg.solve(curvature_reg_matrix, data_vector) > 0
    (autoarray/inversion/inversion/inversion_util.py:434-436) factorises it again to decide the
    starting passive set. That seed is exactly what the memo removes: Leg D shows
    solver.reconstruction_positive_only_from collapsing 59.811 -> 7.545 ms while
    fnnls_cholesky is unchanged.

At a passive set of ~1485 of 1500 the three factorisations are bit-identical work. The lever is
one shared full Cholesky: seed via cho_solve from it, have fnnls down-date the handful of
active columns out of it (choldeleteindexes_inplace, autoarray/util/cholesky_funcs.py:243, which
fnnls_cholesky already calls — Leg B's K3 row measured 1 factorisation and 15 downdates)
instead of factorising a fresh k x k, and read the log-det off the same factor.

S3 only. Route a solves 1560 parameters against the reduced system's 1500, and its NNLS runs
23 outer / 10 inner iterations against route b's 0 / 1, so the shared-factor argument holds only
for the source-only system this campaign is about. Do not quote it for S0.

Fold in the curvature_reg_matrix rebuild bug.
draft/bug/autoarray/curvature_reg_matrix_rebuilt_every_access.md is the same matrix, the same
property: AbstractInversion.curvature_reg_matrix (abstract.py:358-370) is a plain @property
doing an out-of-place _xp.add, and the Leg D JSON measures it at n_calls = 2, 4.056 ms. Phase 1's
test asserting n_calls >= 2 on that property is the intended handshake: if this phase lands a
cache, that assertion fails loudly and the published decomposition is updated deliberately. Resolve
the bug prompt's first question (is the stale-cache hazard its docstring describes still real?) as
part of this lever, and if the honest answer is "the hazard is gone, fix the docstring only", that
is a complete outcome for that part.

A100 row. log det(F + lambda*H) is attributed 1.17 ms there; measure whether the shared-factor
saving survives on a device where the factorisation is launch-bound.

Pairing — every lever gets a CPU row and an A100 row

This is the "paired with A100 speed up" the request asks for, and it is a per-lever requirement,
not a follow-up phase.

CPU leg. RAL gpu partition CPUs-only — --partition=gpu --cpus-per-task=4 --mem=32gb
and no --gres, so the A100s stay free; the ral CPU partition has been saturated for days
and the idle imp partition does not mount /mnt/ral. NUMBA_NUM_THREADS=1 and the whole BLAS
family (OMP/OPENBLAS/MKL/VECLIB/NUMEXPR) pinned to 1, recorded per leg in
configuration.thread_env / numba_thread_env. A/B the library change against a private
merge-base PyAutoArray checkout on PYTHONPATH
— never against the shared
/mnt/ral/jnightin/PyAuto install, which other work depends on. Laptop legs are corroboration
only (phase 2 measured 70.9-187.6 % clean spreads there against RAL's 0.77-16.25 %).

A100 leg. fp64, budget 7 on Delaunay, PDIP fallback, positivity never dropped — the same cell
family and settled configuration as the hst-gpu-non-solver-residue map. The A100 legs have a
submit -> wait -> harvest step, which is a human resume point, not a park.

Pins, on every leg of both hosts:

  • the library's own log evidence to <= 1e-9 relative (the standard both epics have met);
  • the regularization matrix bit-identical to the retained pure-Python _reference, asserted
    on the numba path, not merely close;
  • log_likelihood is not comparable across legs — --instances iid rotates a call index and
    route counts differ between legs (phase 2's route b read 19651.457885 in Leg A and 18665.014334
    in Legs C and D). Compare per-instance, per-leg only.
  • no comparison crosses a thread setting silently; route c (positivity off) is a diagnostic and
    never a headline millisecond.

Witness

At HST Delaunay N=1500 on both hosts, each lever returns the library's own log evidence to
<= 1e-9 relative, the regularization matrix is bit-identical to the retained Python reference on
the numba path, the phase-2 cell's decomposition sums to the measured clean call within 1 %, and
the verdict note carries one before/after whole-call table per host with the thread and backend
blocks recorded per leg.

Scope and guards

In. Library edits in PyAutoArray, witnessed from autolens_profiling using phase 2's existing
cells (scripts/imaging/likelihood_breakdown/fixed_light_numba.py, call_accounting.py) and the
A100 Delaunay cell. The JAX branch of the split-regularization assembly is untouched — #536
owns it and its compaction is exact by a different argument.

Out. Rectangular meshes; Euclid; the sparse-operator / profile-subtracted-image bug
(draft/bug/autoarray/sparse_inversion_ignores_profile_subtracted_image.md); JWST; any reopening
of the NNLS solver scheme; and the memo-robustness question, which moves to phase 4 (does
seed_source stay "memo" and warm_start_fallback stay false over the seeded graded draw set,
or does a bad model pay the cold 116 ms path?).

If intake sizes this too-large, split it along the levers rather than along the hosts: this
phase carries lever 1
(the jitted split-regularization assembly, the biggest and most independent
of the three) and the campaign map holds levers 2 and 3 as phases 3b and 3c. The CPU/A100
pairing stays inside whichever phase carries a lever — it is the pairing that makes a lever a
verdict, so never split a lever from its A100 row.

Execution

Fable plans and judges; Opus subagents execute with a progress heartbeat. One lever at a time,
in order 1 -> 2 -> 3
, each landing its own PyAutoArray PR (pending-release) plus an
autolens_profiling follow-up PR carrying the cell changes, the JSONs and the note. /prm is
human. The deliverable is a results/notes/ verdict note in the format of the six GPU notes and
phase 2's own — provenance and gate table, before/after decomposition per host, per-lever verdict,
and a "read this before quoting a number" scope section.

Activity

  1. Jammy2211 commented on Sep 16, 2026

    @Jammy2211
    ContributorAuthor

    Cross-reference from the GPU session: #268 (epic hst-gpu-non-solver-residue, phase 1) traces the production jax.jit of the certified Delaunay call on the A100 and RTX 2060 and will post here the optimized-HLO census answering whether XLA already collapses the duplicate curvature_reg_matrix adds (abstract.py:371, reached at :613 and :894) under the production jit — i.e. the JAX-side verdict on draft/bug/autoarray/curvature_reg_matrix_rebuilt_every_access.md, which is folded into this issue's lever 3 for the numpy/numba fix + docstring. #268 makes no PyAutoArray change and only measures the GPU F+λH / log-det rows; it runs in its own autolens_profiling worktree (feature/hst-gpu-residue-p1) with a disjoint file set from this task (parallel-claim recorded on the PyAutoMind active.md row).

  2. Jammy2211 commented on Sep 16, 2026

    @Jammy2211
    ContributorAuthor

    Lever 1 — measured. 1.38x on the production numba CPU route; A100 identity.

    Library change — PyAutoArray feature/fixed-light-numba-levers @ bae9296e (merge base 5e2bc0f4): reg_split_np_from and pixel_splitted_regularization_matrix_np_from are now @numba_util.jit() kernels, bit-identical to the retained _reg_split_reference / _pixel_splitted_regularization_matrix_reference bodies (pinned with np.array_equal, 8 new tests). Three recorded behaviour changes: no in-place mutation of the interpolators' cached stencil tables (copy on entry); a size == 0 row inserts at column 0 instead of a stale j + 1; a full stencil with no self pixel raises exc.InversionException instead of writing out of bounds. JAX branch untouched. PyAutoArray suites: regularizations 118 / interpolator 58 / inversion 212 passed.

    CPU A/B — RAL job 343345, gpu partition CPUs-only, 1 thread numba + BLAS, private merge-base control on PYTHONPATH, phase-2 Leg D cell (route b, memo ON):

    arm PyAutoArray whole call (ms) inversion.regularization_matrix (ms) gates
    control 5e2bc0f4 413.301 110.599 4/4 PASS
    feature bae9296e 299.709 5.924 4/4 PASS

    1.379x on means, 1.383x on medians; H from 26.8 % to 2.0 % of the call. The control reproduces phase 2's Leg D to +1.3 % / −0.8 %. Both jobs landed on gpu-1 and the feature arm entered at a higher load average, so 1.38x is a lower bound. Witness in the feature arm: H array_equal to the reference chain (max |diff| 0.0), stencil tables unmutated, figure_of_merit relative difference exactly 0.0 (gate 1e-9).

    A100 — RAL job 343346, delaunay.py breakdown, fp64, AdaptSplit: identity to 0.03 % on the H prefix and 0.04 % on the whole call; log_evidence_terms bit-identical. The GPU cell dispatches to the JAX branch, so the numpy kernels are never reached. Finding: with InterpolatorDelaunay the stencil table is K = 4, so SPLIT_REG_COMPACT_WIDTH = 12 / SPLIT_REG_WIDE_ROW_BUDGET = 256 (#536) are inert at HST Delaunay N=1500 and can only be tuned on a K > 12 cell.

    Artifacts — autolens_profiling feature/fixed-light-numba-levers @ 7c7968c4 (two-arm submit scripts, fixed_light_numba_levers_witness.py) and c899326e (4 JSON + 4 PNG + witness JSON, note results/notes/fixed_lens_light_levers_2026_09.md, lever 1 section; levers 2 and 3 append to it).

    Residue after lever 1 (feature arm): sparse_numba.curvature_matrix 87 ms, solver.fnnls_cholesky 63 ms, log_det_curvature_reg_matrix_term ~40 ms, log_det_regularization_matrix_term ~37.5 ms.

    Lever 3 scope refinement (human, 2026-09-16) — PyAutoMind/draft/bug/autoarray/curvature_reg_matrix_rebuilt_every_access.md now carries Folded-into: autolens_profiling#267 (not issued separately): (1) determine whether the docstring hazard on AbstractInversion.curvature_reg_matrix still exists — the in-place curvature_matrix += form was removed around 0766edd4, the body is a plain out-of-place _xp.add; (2) fix or cache on the numpy/numba path only, measured with the phase-1 call_accounting harness, updating the n_calls >= 2 handshake test (scripts/misc/test/test_fixed_light_numba.py:546) deliberately; (3) fix the stale docstring regardless. The JAX branch is not touched here: the GPU session (epic hst-gpu-non-solver-residue, phase 1) is producing an optimized-HLO census on whether XLA already collapses the duplicate adds and will post that verdict on this issue. On the default (edge-zeroed) path the property is reached twice per evaluation (:613, :894), not the 3+ the draft counted.

    PRs (PyAutoArray pending-release + autolens_profiling) open once the Heart RED gate is resolved; levers 2 and 3 follow on stacked branches.

  3. Jammy2211 commented on Sep 16, 2026

    @Jammy2211
    ContributorAuthor

    PRs open for lever 1: library PyAutoLabs/PyAutoArray#553 (pending-release), measurements #269. Heart RED (release-chain reasons) acknowledged by the human for PR-open; merge via /prm.

  4. Jammy2211 commented on Sep 16, 2026

    @Jammy2211
    ContributorAuthor

    JAX/GPU verdict on curvature_reg_matrix_rebuilt_every_access (from #268, RTX 2060 leg, HST Delaunay N=1500, fp64, production jit boundary):

    • In the optimized HLO of the whole AnalysisImaging.log_likelihood_function program, abstract.py:371 (self._xp.add(self.curvature_matrix, self.regularization_matrix)) carries exactly one instruction, a transpose — no add survives. XLA fused the F + λH sum into its consumers; no standalone (n,n) matrix is materialised.
    • Walking back from every consumer (the :613 edge-subset gathers, 7 of them, and the log-det Cholesky at :894) resolves all of them to one shared producer, cublas-lt-matmul.2 sourced at inversion_util.py:139 (the single A.T A GEMM). 0 gathers at :397 (S3, all objects regularized).
    • So on the JAX/GPU path the property's two reaches per evaluation have no measurable cost — CSE + fusion already collapse them. Any fix/cache for this draft is numpy/numba-only (your lever 3), and the docstring fix stands on its own.
    • Method caveat worth carrying to the CPU side: a census predicate that scans the whole Python stack for :371 over-counts massively (15 false "adds") because both arguments of the add are lazily evaluated at that line; key on the innermost frame.

    Evidence artefacts: results/breakdown/imaging/fixed_light_trace_delaunay_local_rtx2060_fp64_fixed_light_trace.json (hlo_census, where_the_sum_lives) on feature/hst-gpu-residue-p1; the A100 confirmation follows in #268's note.

  5. Jammy2211 commented on Sep 16, 2026

    @Jammy2211
    ContributorAuthor

    Lever 2 — measured, PRs open. Lever 3 — implemented, legs in flight. Session paused here.

    Lever 2 (sparse log det H on the numpy path) — PyAutoArray PR #554 (pending-release, stacked on #553; 0b17c292) + autolens_profiling PR #271 (stacked on #269; fd80eb9a). RAL job 343353 (gpu partition CPUs-only, 1 thread, control = lever 1, run alone on the node): route b memo-ON whole call 302.709 → 267.448 ms (1.13x); inversion.log_det_regularization_matrix_term 37.480 → 6.508 ms; every other row flat (sibling log_det_curvature_reg_matrix_term 40.2 → 39.6). 4/4 cell gates; witness W1–W5 PASS (sparse route fires exactly once; log det rel 1.2e-9 on a cond 6.5e12 matrix; figure_of_merit Δ −4.6e-6 nats, rel 2.3e-10, inside the 1e-9 pin). RAL job 343354 (A100, fixed_light.py): all log_evidence_terms bit-identical; the A100's dense Cholesky of the same H is 1.13 ms, 5.6x faster than the CPU sparse route → CPU-only lever by measurement. Two measured regime switches in the library (SPARSE_LOG_DET_MIN_PIXELS = 256, SPARSE_LOG_DET_MAX_NNZ_PER_ROW = 32; a real Matern kernel H is 10x slower sparse and is correctly declined). Cumulative levers 1+2 vs merge base: 413.3 → 267.4 ms, 1.55x. Note: results/notes/fixed_lens_light_levers_2026_09.md (lever 2 sections).

    Lever 3 (one shared Cholesky of F + λH; folds in curvature_reg_matrix_rebuilt_every_access) — design measured first (read-only): down-dating the full factor (option A) loses (1.7 ms per column); the winner is reading log det(F+λH) off the factor fnnls_cholesky already holds via a Schur complement over the ~15 active columns (log det(M) = log det(M_PP) + log det(M_AA − M_APᵀ M_PP⁻¹ M_PA)), agreeing with the dense potrf to ≤ 2e-12 nats with the solve byte-identical. Hazard verdict on the draft: the hazard does not exist — the in-place add went in 0766edd4 (2025-06-26); the cache was collateral of the blanket e819fa12 sweep (2025-11-05); no downstream in-place mutation anywhere. Implemented on PyAutoArray feature/fixed-light-numba-levers-l3 @ b4322c3e (pushed, PR not yet opened): fnnls_cholesky(..., factor=None) out-dict (32 added lines, 0 removed), inversion_util.log_det_from_passive_cholesky_from, guarded fast path in log_det_curvature_reg_matrix_term (numpy, cholesky mode, positive-only solver, all-regularised, factor present, shape + index coverage incl. the arange(n) identity-subset trap), dense fallback on LinAlgError, curvature_reg_matrix → cached_property, stale docstrings fixed (three sites). 35 new tests; inversion 605 / util 127 passed. Local: log evidence bit-identical, log-det Δ +1.8e-12 nats, curvature_reg_matrix 2 → 1 calls. Profiling side on feature/fixed-light-numba-levers-l3 @ 3059992 (pushed): two-arm submit scripts (control = lever 2), witness W1–W5, and the deliberate handshake flip — test_curvature_reg_matrix_is_cached asserts n_calls == 1 (passes against lever 3's library, fails against lever 2's, so the lever 3 profiling PR is gated on PyAutoArray lever 3 merging first).

    In flight at pause: RAL CPU A/B job 343355 (control PyAutoArray_l2 0b17c292, feature PyAutoArray_l3 b4322c3e); the A100 arm follows on the same script family. Results land in /mnt/ral/jnightin/autolens_profiling_wt/fixed-light-numba-levers/results/breakdown/imaging/ (*lever3*) and output/output.<job>.out.

    Resume: harvest lever 3's rows, append the lever 3 sections to the note, commit on the profiling -l3 branch, open PyAutoArray + autolens_profiling lever 3 PRs (Heart RED already acknowledged by the human for PR-open on levers 2 and 3), then /prm in order #553 → #554 → lever 3 (library) and #269 → #271 → lever 3 (profiling). Follow-ups recorded in the lever 3 PR draft: option A′ (permute active-last) as a candidate lever 4; edge-zeroed systems fall back to dense; reconstruction_covariance_matrix factorises F+λH a third time.

  6. Jammy2211 commented on Sep 16, 2026

    @Jammy2211
    ContributorAuthor

    Lever 3 CPU leg update at pause: RAL job 343355 — control arm (lever 2) fine at 268.681 ms, feature arm (lever 3) FAILED the cell's instrumentation-overhead ABBA gate (1.0366 > 1.03; no JSON written). Likely cause: the whole call is now ~230 ms while the harness's fixed instrumentation cost is unchanged, so the overhead ratio rises past a cap calibrated on a 400 ms call — a harness artefact of a faster call, not a lever 3 defect (the same gate passed at 1.016–1.022 for levers 1–2). Resubmitted as job 343356 with --n-repeats 64 (profiling -l3 @ c6cb80e); the A100 arm was deliberately not submitted so it cannot contaminate the CPU row. On resume: read 343356; if the ratio still trips, the decision is whether the 1.03 cap should scale with call length (a human call on the cell's gate, not a tolerance to loosen silently) — do not read the missing JSON as a lever 3 failure.

  7. Jammy2211 commented on Sep 16, 2026

    @Jammy2211
    ContributorAuthor

    Lever 3 CPU row landed on the rerun: RAL job 343356 (--n-repeats 64, COMPLETED, 2:41) — control (lever 2) 273.194 ms → feature (lever 3) 230.031 ms, 1.188x; inversion.log_det_curvature_reg_matrix_term 40.849 → 6.318 ms; curvature_reg_matrix n_calls 2 → 1; witness W1–W5 PASS. Cumulative levers 1+2+3 vs merge base: 413.3 → 230.0 ms, 1.80x. A100 arm submitted as job 343357 (running). Not yet harvested — session paused; resume = harvest 343356 + 343357, lever 3 note sections, commit on profiling -l3, open both lever 3 PRs.

  8. Jammy2211 commented on Sep 16, 2026

    @Jammy2211
    ContributorAuthor

    Phase 3 complete at PR-open: three levers, 413.3 → 230.0 ms on the production numba CPU route (1.80x).

    lever site site before → after (ms) whole call (ms) increment library PR profiling PR
    1 numba split-regularization kernels inversion.regularization_matrix 110.6 → 5.9 413.3 → 299.7 1.38x PyAutoArray #553 #269
    2 sparse log det H (SuperLU, two measured regime gates) inversion.log_det_regularization_matrix_term 37.5 → 6.5 302.7 → 267.4 1.13x PyAutoArray #554 #271
    3 log det(F+λH) off the NNLS Cholesky factor + cached curvature_reg_matrix inversion.log_det_curvature_reg_matrix_term 40.8 → 6.3 273.2 → 230.0 1.19x PyAutoArray #555 #272

    All library PRs carry pending-release; every lever has a numba-CPU row and an A100 row on RAL with a private merge-base or previous-lever control on PYTHONPATH, 1 thread, all cell gates PASS. Pins: lever 1 bit-identical H and log evidence; lever 2 log evidence 2.3e-10 relative (a cond 6.5e12 matrix, two fp64 factorisations); lever 3 log det and log evidence bit-identical. A100: identity on every lever (the JAX branch was never touched); levers 2 and 3 are CPU-only by measurement (the A100's dense Cholesky of a 1500² SPD matrix is ~1.1 ms, launch-bound). The verdict note results/notes/fixed_lens_light_levers_2026_09.md (on #272's branch) carries per-lever provenance, gate roll-ups, decompositions, a phase-3 roll-up and a re-cut Next.

    Merge order (library-first, stacked): PyAutoArray #553 → #554 → #555; autolens_profiling #269 → #271 → #272 (each rebases onto main as its base merges). Note for #272: its CI will be red on test_curvature_reg_matrix_is_cached until PyAutoArray #555 is on main (the profiling lint workflow checks out PyAutoArray's default branch) — that is the deliberate phase-1 handshake flipping, not a regression.

    Folded-in draft curvature_reg_matrix_rebuilt_every_access.md: resolved by #555. The docstring hazard does not exist (in-place add removed in 0766edd4; the cache was collateral of the blanket e819fa12 sweep); the property is now cached with a truthful docstring; the phase-1 accounting handshake was updated deliberately; the JAX side is left to the hst-gpu-non-solver-residue HLO census still owed on this issue.

    Residue after phase 3 (feature arm, 230 ms): sparse_numba.curvature_matrix 88 ms + solver.fnnls_cholesky 61 ms ≈ 65 % of the call. Lever 4 candidates recorded in the note's Next: option A′ (permute active-last, one potrf for solve + log-det, folds away both 7.6 ms fancy-index copies; perturbs the passive factor at 5e-13 so it needs a knife-edge audit), edge-zeroed generalisation of lever 3, reconstruction_covariance_matrix's third factorisation, the S0 identity, and the harness's fixed 1.03 instrumentation-overhead cap vs call length (tripped once at 224 ms; 64 repeats fixed it without touching the gate).

    Heart was RED (release-chain: install verify testpypi F; release validation integrate) at every ship; acknowledged by the human for PR-open only on all three levers. /prm is the human's.

  9. Jammy2211 commented on Sep 16, 2026

    @Jammy2211
    ContributorAuthor

    Shipped

    Phase 3 is on main in both repos — 413.3 → 230.0 ms = 1.80x on the production numba CPU route (HST Delaunay N=1500, route b, memo ON), A100 identity on every lever.

    lever PyAutoArray autolens_profiling
    1 numba split-regularization kernels (1.38x) #553 MERGED 2f6657a6 #269 (lands via #272)
    2 sparse log det H (1.13x, CPU-only) #554 MERGED 7c230c4c #271 (lands via #272)
    3 log det(F+λH) off the NNLS factor + cached curvature_reg_matrix (1.19x) #555 MERGED 91240e43 #272 MERGED cea41bbc

    All three library PRs are pending-release — the levers reach users on the next PyAutoArray release. Verdict note: results/notes/fixed_lens_light_levers_2026_09.md.

    Merge route. #272 was retargeted to main and merged alone, carrying the whole stack: once #555 was on PyAutoArray main, the lever 1/2 branches' copies of test_fixed_light_numba.py pinned a pre-lever-3 library and their lint could no longer pass on its own (runs 35156146275 / 35156280232: exactly those two tests). GitHub marked #269 and #271 merged when their commits reached main through cea41bbc. Ship-side fixes on the way in: the two-arm A/B submits got their own static contract (test_fixed_light_numba_levers_submits.py, excluded from test_fixed_light_cell.py's single-arm glob), and main's #270 trace exclusion was merged into the same filter. No submit script changed.

    Residue: curvature_matrix 88 ms + fnnls 61 ms ≈ 65 % of the 230 ms. Lever 4 candidates (A′ permute-active-last, edge-zeroed, covariance third factorisation) are in the note's Next and are not filed. RAL leftovers under PyAuto_wt/fixed-light-numba-levers/ and autolens_profiling_wt/fixed-light-numba-levers/ await a hand sweep.

    Mind record: PyAutoMind/complete/2026/09/fixed-light-numba-levers.md.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions