perf(efficient_did): dispatch conditional Omega* ridge solves to a Rust batched-Cholesky kernel (fits 1.4-1.8x)#632
Conversation
…l Omega* weights _ridge_solve_weights' batched np.linalg.solve (serial LAPACK LU over the (units x H x H) ridged Omega* stacks; the top stage at every scale after the kcov-table hoisting) now dispatches to a new Rust kernel batched_ridge_chol_solve_ones: hand-rolled unblocked Cholesky (the ridged Omega* is SPD by construction) in a reused per-thread scratch buffer, rayon-parallel over the unit axis, with an in-kernel faer LU fallback for non-SPD rows (NaN-poisoned on an exactly-zero pivot) and per-row legacy numpy recompute of any non-finite row, so pinv edge-case semantics are unchanged. Dispatch is on backend availability + float64 only - no batch-size cutoff (tile-invariance twins force one-unit batches through the same kernel). Measured (3-rep medians, 20p/5-cohort/5-cov, aggregate="all"): 2k 7.1 -> 4.3s (1.65x) | 10k 36.2 -> 22.7s (1.60x) 30k 129 -> 90s (1.43x) | 100k 17.8 -> 15.9 min | survey_1k 1.8x Ridge stage at 10k 17.1 -> 3.7s (kernel alone 9.6x); maxrss flat/lower. Deltas: post cells ~2e-12 rel, overall ATT ~1e-13; pure-python backend byte-identical; nocov path untouched; omega_ridge=0 never reaches the kernel. New tests: kernel parity vs numpy (well/ill-conditioned, NaN, exact singular, batch-split bit-identity, degenerate shapes) in test_rust_backend.py; dispatch contracts (kernel-called spy, in-process backend A/B, symbol-None degradation, bad-row-only exact recompute, exact-singular pinv arm, f32 declines) in test_efficient_did.py; 5 cargo tests. REGISTRY ridge Note extended (pure implementation change); CHANGELOG + performance-plan tables; TODO row swapped to the remaining Python-prep shave. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X4AzrFUMqJxcUumSH31mSr
Overall Assessment✅ Looks good. I found no unmitigated P0/P1 methodology, correctness, inference, or edge-case issues in the PR diff. Executive Summary
MethodologyFinding: Documented Implementation Change, Not A Defect
Finding: Legacy Ridge-Off Path Preserved
Code QualityNo blocking findings. The Python fallback is factored into PerformanceFinding: Remaining Prep Overhead Is Tracked
MaintainabilityNo findings. The new Rust module is isolated in Tech DebtNo untracked blocking tech debt found. The only newly documented follow-up is the performance item in SecurityNo findings. I saw no unsafe Rust, secrets, credential material, or new external I/O paths in the changed files. Documentation/TestsNo blocking findings. The PR adds targeted coverage for dispatch, Rust-vs-NumPy parity, bad-row recompute, singular pinv fallback, dtype dispatch refusal, split determinism, strided input, degenerate shapes, and shape validation at I did not execute the test suite in this read-only review environment. |
Summary
_ridge_solve_weights' batchednp.linalg.solve— a serial LAPACK LU sweep over the(units x H x H)ridged Omega* stacks, and the top stage at every scale after perf(efficient_did): cross-cell kcov-table hoisting + per-group W lifecycle (100k: 86 -> 18 min) #629's kcov-table hoisting — now dispatches to a new Rust kernelbatched_ridge_chol_solve_oneson the Rust backend: hand-rolled unblocked Cholesky (the ridged Omega* is SPD by construction) in a reused per-thread scratch buffer, rayon-parallel over the unit axis.aggregate="all"): 2k 7.1 -> 4.3s (1.65x), 10k 36.2 -> 22.7s (1.60x), 30k 129 -> 90s (1.43x), 100k 17.8 -> 15.9 min, survey 1k 1.8x; ridge stage at 10k 17.1 -> 3.7s (kernel alone 9.6x); maxrss flat or lower.omega_ridge=0never reaches the kernel.Methodology references (required if estimator / math changes)
docs/methodology/REGISTRY.mdOmega* ridge Note (extended with the Rust batched-Cholesky follow-up sentence)(Omega* + lam * max(trace/H, 0) * I) x = 1and weight normalization are unchanged, Cholesky vs LU differ only at the condition-bounded floating-point level.Validation
tests/test_rust_backend.py(newTestBatchedRidgeCholSolve: parity vs numpy on well-/ill-conditioned stacks, NaN/exact-singular rows, batch-split bit-identity, degenerate shapes, strided input, shape validation),tests/test_efficient_did.py(newTestRidgeSolveRustDispatch: kernel-called spy, in-process backend A/B, symbol-None degradation, bad-row-only exact recompute, exact-singular pinv arm, f32 declines dispatch), 5 Rustcargo testunits. All existing EfficientDiD locks (dense-reference oracle, tile twins, 1-ulp stability, hand-computed weights, HRS anchors) re-run UNMODIFIED on both backends.docs/performance-plan.md(BEFORE = main 81d53f5 via pristine worktree); tutorial 15 executes clean via nbmake.Security / privacy
Generated with Claude Code