Add optimization O05: batched random-direction kernels that reproduce the reference loops, plus validated low-rank sketches with an explicit error budget. The reference loops stay the default. - Batched gate, discovery and subspace nulls keep draw order, generator state, norm matching, pooling, orientation folding and percentile semantics; identical rows are projected once so exact ties survive. Declared tolerance 1e-12 with identical decisions; observed 0.0. - select_rank keeps both residual variance and class-contrast loss within budget, measured exactly, and reports the variance-only rank; it returns inconclusive when no rank qualifies. - The sketch gate null is approximate only when the spectrum test passes, an exact audit stays within 0.005 AUC and no threshold falls inside the band; otherwise it recomputes exactly. It is refused in enforce mode. The observed AUC is never approximated. - A benchmark module reports wall time, peak memory, subspace angles, null errors and decision disagreement (timings host-specific). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4.0 KiB
Batched null kernels and reduced-rank analysis
Optional faster paths for the random-direction nulls used by concept validation, candidate discovery and the subspace report, plus reduced-rank analysis with an explicit error budget. The existing loops remain the default and the reference. A report changes only when a non-default path is selected, and then it records which path was used.
Selecting a kernel
| Entry point | Option | Values |
|---|---|---|
validate_direction |
null_kernel |
reference (default), batched, sketch |
discover_candidates |
null_kernel |
reference (default), batched |
build_subspace_report |
null_kernel |
reference (default), batched |
batched is exact in meaning. It draws the same directions in the same
order from the same generator, so later layers see the same random stream.
It keeps norm matching, average ranks for ties, pooling over control sets,
max(auc, 1 - auc) orientation folding, the strict < percentile, and the
reference folds. Only the projection changes, from one matrix-vector product
per direction to one matrix product per chunk. Values therefore agree within
AUC_TOLERANCE = 1e-12 instead of bitwise. Identical activation rows are
projected once, so their exact ties survive any BLAS blocking. In the
subspace report, the per-rank increment nulls and the Haar-subspace null are
batched. The pair nulls still use the loop.
Reduced rank and the error budget
low_rank.select_rank returns the smallest rank whose residual energy and
class-contrast loss are both within budget (defaults: energy 1%, signal 2%).
Both are measured after the fact, exactly, for whatever basis is used, so a
randomized SVD basis is checked rather than trusted. The report includes the
spectrum, the per-rank tail energy and signal loss, and variance_only_rank,
the rank that explained variance alone would pick. If no rank up to half the
full rank meets the budget, the result is inconclusive and no basis is
returned.
null_kernel="sketch" approximates the gate's random-direction projections
in a randomized low-rank basis of the centred rows. The result is
approximate only when all three checks pass:
- the spectrum test passes;
- an audit of 32 evenly spaced draws, recomputed exactly, stays within the AUC budget (0.005);
- the percentile interval implied by that budget contains no gate threshold.
Otherwise the null is recomputed exactly with the batched kernel, and the
layer's random_null metadata reports reference_fallback with the reason.
The observed AUC is never approximated. Approximate results are labelled as
such in the report.
Benchmark
python -m obliteratus.analysis.kernel_benchmark --output o05.json [--quick] [--repeats N] [--threads N]
The benchmark runs every arm on deterministic fixtures:
- a low-rank planted signal;
- a target signal on a low-variance direction outside a dominant nuisance subspace;
- exact duplicate rows (ties);
- a flat spectrum;
- a low-rank null.
It reports wall time, peak resident-memory growth (sampled from
/proc/self/statm, so coarse), subspace angles between the exact and
randomized bases, AUC and projection errors, tail-signal loss at the
variance-only rank, and gate-decision disagreement. Timings and memory depend
on the host and are not asserted. The agreement fields are the reproducible
part of the report.
On the tail fixture, explained variance selects rank 4 and loses about 43% of the class contrast. The signal-aware rule selects rank 5.
Limits
- Batched kernels hold an
(unique rows × chunk)score block, 256 directions by default. This adds working memory that the gate host-memory admission estimate does not include. - A smaller basis does not mean cheaper inference or a smaller model change. The sketch is only a cheaper estimate of a validation null.
- An approximate null changes what the gate measured, so
sketchis refused in enforce mode and is available in report mode only. Use the reference or batched kernel for any result that will be confirmed.