perf(efficient_did): omega_ridge stabilization + fused tiled GEMM analytical path (43x)#625
Merged
Merged
Conversation
…lytical path Ridge-regularize the Omega* inversion behind the efficient weights (omega_ridge param, default 1e-6 relative to trace/H; 0 = exact legacy inv/pinv path, entire legacy code path preserved verbatim) and rewrite the conditional analytical path as a fused unit-tiled GEMM pass (kernel-covariance tables with (tpre_j, tpre_k) dedup, per-group kernel matrices reused across cells, batched ridge solves replacing the per-unit SVD + pseudoinverse loop). nocov twin: Gram-form omega + the same ridge on global weights; per-cell pseudoinverse warnings consolidate into one fit-level warning. The ridge path drops the identically-zero (g'=g, t_pre=t) self-pair so pre-treatment placebos stay data-driven. Motivation beyond speed: PT-All's telescoping overidentified moments make sample Omega* numerically singular (cond 1e17-1e22, 100% of units), so the legacy pseudoinverse redrew per-cell ATT(g,t) at ~1e-2 rel under ANY floating-point change (1-ulp input perturbation on the shipped code: 1.2e-4). After: 1-ulp per-cell stability ~3e-9. Default calibrated against the HRS Table 6 anchors (all unchanged, worst 0.0257 SE) and Monte Carlo (bias/RMSE/coverage identical to legacy). Conditional fit: 337.3s -> 7.8s at 2k units (43x), 57.7s at 10k, and a 100k-unit fit now completes at 4.0 GB peak (was memory-killed). Survey-weighted 1k: 95.3s -> 3.3s. Docs: REGISTRY Omega* ridge Note (calibration evidence, one-time value shift, degenerate-pair exclusion, diagnostics rationale), CHANGELOG, performance-plan tables, TODO row swap, llms-full line, pseudoinverse-mention sweep. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X4AzrFUMqJxcUumSH31mSr
|
Overall Assessment ✅ Looks good. No unmitigated P0/P1 findings. Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
omega_ridgeparameter (default 1e-6): ridge-regularizes the Omega* inversion behind the efficient weights —(Omega* + omega_ridge * max(trace/H, 0) * I) x = 1— replacing the pseudoinverse of the numerically singular Omega* that PT-All's telescoping overidentified moments produce (measured cond 1e17–1e22 for 100% of units). Per-cell ATT(g,t) becomes numerically well-defined and platform-stable: 1-ulp input perturbation moves per-cell values ≤3e-9 relative (previously ~1e-4 through the pseudoinverse's rcond-cutoff cliff).omega_ridge=0restores the entire legacy code path bit-for-bit.KCov = W@(A0*B0) − (W@A0)*(W@B0)with(t_pre_j, t_pre_k)dedup (1,830 pairs → ~190 columns), per-group kernel matrices computed once per tile and reused across all cells, batched ridge solves replacing the per-unit SVD + pseudoinverse loop, memory bounded by_TARGET_OMEGA_TILE_BYTES(256 MB). nocov twin: Gram-form Omega* + the same ridge on global weights.(g'=g, t_pre=t)moment is identically zero by construction (the exact-null Omega* direction); dropping it keeps pre-treatment placebos data-driven (the legacy pseudoinverse truncation had turned them into ±5%-of-effect-size noise; a naive ridge would have made them deterministically zero and disabled the pre-trend diagnostic).Methodology references (required if estimator / math changes)
docs/methodology/REGISTRY.mdEfficientDiD section)omega_ridgeregularization and the degenerate self-pair exclusion are documented in the new REGISTRY- **Note:**(Omega* ridge regularization). The paper assumes Omega* is invertible and does not prescribe finite-sample handling of numerical singularity; any fixed weights summing to 1 keep the estimator consistent (each moment identifies ATT(g,t)), the plug-in EIF treatment of estimated weights (Remark 4.2) is unaffected, and the default was calibrated against the paper's own HRS Table 6 empirical application (all anchors unchanged, worst deviation 0.0257 SE, shift ≤0.0001 SE) plus Monte Carlo (bias/RMSE/SE-calibration/coverage statistically identical to legacy). One-time value shift on the covariate path is called out in CHANGELOG (worst post cell ~0.6 of its own SE at n=500, shrinking with n).Validation
tests/test_efficient_did.py(TestOmegaRidge: param surface/validation/transactional set_params, aggregate-warning payload vs legacy per-cell, ridge-engaged lock, degenerate-pair drop, data-driven placebos; TestFusedConditionalPath: dense-reference oracle, tile-forced twins incl. survey weights with a multi-tile execution proof, 1-ulp stability contracts for both paths),tests/test_methodology_efficient_did.py(TestOmegaRidgeWeights hand-computed/scale-equivariance/dose-response/uniform-fallbacks, TestNoCovOmegaGram loop-parity incl. n<2 / sum(w)≤1 / zero-weight-cohort / H=0 guards + fit-level twin, TestKernelCovBatch GEMM-identity oracle weighted+unweighted+row-tile). Existing suites green on both backends; full suite 8,466 passed (single failure = known pre-existing order-dependenttest_survey_dcdhitem, passes standalone, TODO.md row from fix(staggered): CS panel reg/ipw influence functions + per-cell SEs to DRDID parity #619).docs/tutorials/15_efficient_did.ipynbexecutes clean; measured perf arms indocs/performance-plan.md.Security / privacy
Generated with Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_01X4AzrFUMqJxcUumSH31mSr