Skip to content

Commit 9862686

Browse files
Merge pull request #80 from TheHiddenObserver/codex/survival-gpu-completion
feat(survival): complete GPU Cox phase one
2 parents 7ccf616 + f05a44a commit 9862686

211 files changed

Lines changed: 75569 additions & 7113 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ jobs:
8989
dev/tests/test_logistic.py \
9090
dev/tests/test_cox.py \
9191
dev/tests/test_cox_cv.py \
92+
dev/tests/test_cox_core_completion.py \
93+
dev/tests/test_cox_phase1_completion.py \
94+
dev/tests/test_penalized_cox_completion.py \
95+
dev/tests/test_pr80_all_censored_loss.py \
96+
dev/tests/test_pr80_post_review_fixes.py \
97+
dev/tests/test_pr80_fit_boundary.py \
98+
dev/tests/test_pr80_constructor_boundaries.py \
99+
dev/tests/test_pr80_workspace_estimator.py \
100+
dev/tests/test_pr80_cv_fit_boundary.py \
101+
dev/tests/test_pr80_complete_review_cycle.py \
102+
dev/tests/test_pr80_completion_contract_followup.py \
103+
dev/tests/test_pr80_target_transfer_overflow_cache.py \
104+
dev/tests/test_survival_risk_sets.py \
92105
dev/tests/test_distributions_backend.py \
93106
dev/tests/test_penalties_and_exports.py \
94107
dev/tests/test_ridge_inference.py \
@@ -176,10 +189,12 @@ jobs:
176189
statgpu/linear_model/cv/_ridge_cv.py \
177190
statgpu/linear_model/penalized/_fit_mixin.py \
178191
statgpu/linear_model/penalized/_inference_mixin.py \
192+
statgpu/linear_model/penalized/_penalized_cox.py \
179193
statgpu/linear_model/penalized/_penalized_cv.py \
180194
statgpu/linear_model/penalized/_penalized_linear.py \
181195
statgpu/linear_model/wrappers/_linear.py \
182196
statgpu/linear_model/wrappers/_ridge.py \
197+
statgpu/losses/_cox_ph.py \
183198
statgpu/metrics \
184199
statgpu/nonparametric/kernel_methods \
185200
statgpu/nonparametric/kernel_smoothing \
@@ -189,7 +204,15 @@ jobs:
189204
statgpu/penalties/_base.py \
190205
statgpu/semiparametric \
191206
statgpu/solvers/_fista_lla.py \
207+
statgpu/survival/_concordance.py \
192208
statgpu/survival/_cox.py \
209+
statgpu/survival/_cox_errors.py \
210+
statgpu/survival/_cox_fit_adapter.py \
211+
statgpu/survival/_cox_counting.py \
212+
statgpu/survival/_cox_cv.py \
213+
statgpu/survival/_numeric.py \
214+
statgpu/survival/_cox_score.py \
215+
statgpu/survival/_risk_sets.py \
193216
statgpu/unsupervised/_kmeans.py \
194217
statgpu/unsupervised/_nndescent.py \
195218
statgpu/unsupervised/_umap.py \

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,28 @@ SECURITY.md
1818
.claude/
1919

2020
# Results
21+
# Keep the final PR80 Exact benchmark source available to the PR76 dashboard
22+
# pipeline while continuing to ignore ad-hoc result artifacts.
2123
results/
24+
!results/
25+
results/*
26+
!results/benchmark_frontend_sources/
27+
results/benchmark_frontend_sources/*
28+
!results/benchmark_frontend_sources/coxph_exact_pr80_20260726.json
29+
!results/benchmark_frontend_sources/coxph_exact_strata_pr80_20260726.json
30+
!results/benchmark_frontend_sources/coxph_exact_delayed_entry_strata_pr80_20260727.json
31+
!results/benchmark_frontend_sources/coxph_exact_strata_count_pr80_20260727.json
32+
!results/benchmark_frontend_sources/penalized_cox_trusted_gradient_pr80_20260727.json
2233

2334
# Dev tooling (benchmarks, scripts, plans, docs — not production code)
2435
dev/benchmarks/
2536
# Keep the PR79 evidence pipeline and its reviewed manifest versioned while
2637
# continuing to ignore ad-hoc benchmark artifacts elsewhere.
2738
!dev/benchmarks/
2839
dev/benchmarks/*
40+
!dev/benchmarks/benchmark_exact_ties_scaling.py
41+
!dev/benchmarks/benchmark_exact_strata_count_scaling.py
42+
!dev/benchmarks/benchmark_penalized_cox_trusted_gradient.py
2943
!dev/benchmarks/pr79/
3044
dev/benchmarks/pr79/*
3145
!dev/benchmarks/pr79/aggregate_results.py
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
# Changelog
2+
3+
All notable changes to statgpu are documented here, organized by date and PR.
4+
5+
## 2026-07-27
6+
7+
### PR #80 — Cox review-fix follow-up
8+
- Reused Cox preprocessing across SCAD/MCP iterations and removed redundant objective, metadata, and finite-check transfers.
9+
- Unified CoxPH on stable risk-set objectives with a bounded ordinary suffix fast path, and restored cancellation-safe penalized moments.
10+
- Added Breslow Hessian workspace gates, preserved device/runtime solver errors, rejected complex high-level inputs, and unified no-pair scoring.
11+
- Added optimized stratified Exact and delayed-entry batching paths with maintained P100/R benchmark artifacts.
12+
- Hardened Cox/CV cleanup, packed-target provenance, prepared/fast-path integrity, fold-level metadata reuse, strict hazard-ratio exponentiation, backend-consistent prediction/strata validation, fixed-penalty frequentist inference, stable fit and raw-stop diagnostics, public numerical errors, robust-inference unit/PSD/rank/variance gates, shared inference/backend paths, valid eventless-stratum survival, survival-aware L1/L2/ElasticNet/SCAD/MCP CV with complete-evidence selection, fitted-backend pinning, CompositePenalty cloning, strict CV side-array/fold indices, general disjoint custom splits, promotion-safe scalar alpha-grid validation across all public penalty families, device-native GPU group metadata, scalar actual-fold and Cox evaluable-fold auto-device sizing, ElasticNet KKT alpha grids, operational auto-device fallback, non-tunable no-penalty rejection, and one-sync concordance tiling; inactive legacy kernels remain test-only.
13+
14+
## 2026-07-26
15+
16+
### PR #80 — Complete GPU Cox phase one
17+
- Added Breslow, Efron, and Exact Cox risk sets with delayed entry, start-stop rows, strata, robust inference, and subject-grouped CV across NumPy, CuPy, and Torch.
18+
- Hardened penalized Cox estimation, formula handling, sklearn compatibility, numerical stability, and backend-preserving prediction and scoring.
19+
- Added synchronized GPU and R validation artifacts for coefficients, likelihood, covariance, convergence, and performance.
20+
- Composed optimized Exact kernels across strata, cutting the `n=160` P100 full-fit time from 0.276/4.25/2.58 s to 0.0143/0.174/0.0747 s for NumPy/CuPy/Torch and preserving large-sample GPU acceleration.
21+
22+
## 2026-07-25
23+
24+
### PR #85 — Release statgpu 0.2.2
25+
26+
- Bumped the package version from 0.2.1 to 0.2.2 in `pyproject.toml` and
27+
`statgpu/__init__.py`.
28+
- Based the release candidate on the current `master`, including the PR #79
29+
hardening work and PR #84 maintained-documentation refresh.
30+
- Retained the `STATGPU_NO_EXT=1` pure-Python `py3-none-any` wheel policy and sdist.
31+
- Validated 122 maintained documentation files, the full CPU-only suite, both
32+
distribution formats, `twine check`, artifact contents, and clean installs.
33+
34+
## 2026-07-24
35+
36+
### PR #84 — Refresh maintained documentation contracts
37+
38+
- Refreshed the release-facing README, documentation portals, method inventory,
39+
and bilingual ANOVA, covariance, kernel-method, and PyTorch backend guides.
40+
- Added deterministic bilingual-link normalization and CI validation for
41+
maintained relative links, release-facing content, and Python examples.
42+
43+
### PR #79 — Exact-head review closure and documentation synchronization
44+
45+
- Final reviewed production head `c85750d63d4e6dbc9d988847566c20f5fa862e91`
46+
passed GitHub Actions Tests run #545, including Python 3.9–3.12, static contracts,
47+
canonical smoke, and the full CPU suite.
48+
- The maintained Tesla P100 suite passed 33/33 executed checks with two expected skips;
49+
ignored legacy diagnostic scripts are tracked separately in Issue #83.
50+
- Corrected the documented CoxPH delayed-entry contract: robust/cluster inference raises
51+
when `compute_inference=True`, while `compute_inference=False` permits estimation-only
52+
fits with inference fields unset.
53+
- Documented PooledOLS backend-preserving prediction, stable HAC `time_index` ordering,
54+
effective-rank residual degrees of freedom, and rank-deficient coefficient inference as
55+
`NOT_COMPARABLE` rather than `ERROR`.
56+
- Synchronized README, bilingual model pages, release notes, and the auditable PR79 report.
57+
- Removed stale hard-coded final accuracy artifacts; a new full canonical report may be
58+
committed only after an exact-head full raw campaign is processed by the current
59+
aggregator and renderer.
60+
61+
## 2026-07-23
62+
63+
### PR #79 — Complete review contract and evidence-pipeline hardening
64+
65+
- Unified CoxPH final-KKT, line-search, termination-reason, and public fitted-state
66+
contracts across CPU, CuPy, and Torch; failed CPU line searches no longer update
67+
coefficients or report convergence.
68+
- Made delayed-entry penalty and robust-covariance limitations explicit, added
69+
strict/approx robust inference with provenance fields, and introduced the
70+
`statgpu[survival]` optional dependency.
71+
- Preserved estimator backends in Cox prediction/scoring, vectorized baseline
72+
hazard risk sets, removed the affected Torch `O(n p^2)` Hessian materialization,
73+
and avoided unconditional full training-data host transfers for nonrobust GPU inference.
74+
- Unified complex RBF rejection, Cox chi-square survival-function evaluation, and
75+
CuPy Cholesky inverse solves.
76+
- Rebuilt PR79 diagnostic/canonical-report validation so missing, failed,
77+
duplicate, non-finite, or wrong-SHA evidence fails closed; added CPU smoke CI.
78+
- Canonical evidence now requires clean, stable, exact-head Git provenance; stale
79+
hard-coded final PASS artifacts are not authoritative and must not be regenerated
80+
without a full validated campaign.
81+
- Added behavioral regression coverage and synchronized the English/Chinese Cox
82+
support matrix.
83+
84+
## 2026-07-21
85+
86+
### PR #79 — Final physical GPU validation and correctness hardening
87+
88+
- Completed GPU smoke, three-backend correctness, metamorphic, device-purity,
89+
memory-leak, performance, external-validation, and full CPU/GPU gates on Tesla P100.
90+
- Full campaign result on `2f18e5d`: 1100 passed, 0 failed, 124 skipped, and
91+
1 version-limited strict XFAIL; all 40 initial Gate B failures were eliminated or
92+
formally dispositioned.
93+
- Completed a subsequent review-fix cycle covering backend-native `LinearRegression`,
94+
PooledOLS HAC ordering and effective rank, formula-weight alignment, validator integrity,
95+
weighted CPU/CuPy/Torch fitting, and degenerate GPU F-statistic semantics.
96+
- Exact-head physical GPU acceptance on clean SHA
97+
`786af9e2eb4742a56e5203b4380b03aec63a3ac8`: **17 passed, 0 failed, 0 skipped**
98+
in 7.28 seconds, with CuPy and Torch CUDA tests both executed.
99+
- Degenerate F tests now agree across backends: perfect non-constant fit returns
100+
`(inf, 0.0)`; intercept-only and otherwise undefined overall tests return `(nan, nan)`.
101+
- Follow-up issues #81, #82, and #83 remain non-blocking; see
102+
`dev/reviews/pr79_physical_gpu_validation.md`.
103+
104+
## 2026-07-14
105+
106+
### PR #79 — Third review/fix cycle
107+
108+
- Fixed Torch vector Cholesky solves, Panel string-label/device paths, KernelPCA/RidgeCV/
109+
thin-plate Torch failures, and full-design CPU fallbacks in panel array workflows.
110+
- Added shared finite-input validation for panel, covariance, unsupervised, KernelPCA,
111+
Nystroem, and thin-plate paths plus 21 focused regressions.
112+
- The physical-GPU work pending at this stage was completed on 2026-07-21; see the final
113+
validation entry and `dev/reviews/pr79_physical_gpu_validation.md`.
114+
115+
## 2026-07-12
116+
117+
### PR #79 — Second full-repository review and auto-fix
118+
119+
- Fixed Stepwise backward selection/order/state contracts, backend-native Welch ANOVA,
120+
incomplete-fold CV selection, regression diagnostics, summary-statistic edge cases,
121+
Torch RBF kernels, weighted quadratic SCAD/MCP routing, resampling validation, and
122+
Cox score-test duplication.
123+
- Hardened estimator cloning, knockoff selectors/draw validation, composite penalties,
124+
effect sizes, backend factory semantics, KDE zero-density handling, and dtype/device
125+
preservation; added 40+ focused regression tests and synchronized public docs.
126+
127+
### PR #79 — Native three-backend execution follow-up
128+
129+
- Removed complete numeric-array NumPy fallbacks from `GraphicalLasso`,
130+
`GraphicalLassoCV`, `MinCovDet`, `SplineTransformer`, and `FamaMacBeth`.
131+
- Kept Graphical Lasso block-coordinate descent/CV, FAST-MCD C-steps and
132+
reweighting, spline Cox–de Boor recurrence, and Fama–MacBeth regressions/HAC
133+
covariance on the selected NumPy, CuPy, or Torch backend.
134+
- Kept Tukey/Bonferroni group reductions on-device; only scalar distribution
135+
CDF/quantile evaluations cross the CPU boundary.
136+
- Added NumPy/Torch parity and backend-preservation tests plus optional CuPy CUDA
137+
checks. The physical CuPy/Torch CUDA validation planned at this stage was completed
138+
on 2026-07-21.
139+
- Synchronized README, bilingual implemented-method lists, model pages, and all
140+
three changelogs with the corrected execution and validation boundaries.
141+
142+
### PR #79 — Public module statistical-contract follow-up
143+
144+
- Extended the repository review beyond Ridge to every top-level public module family,
145+
combining full-package high-signal static analysis with targeted numerical invariants,
146+
nested-model checks, and parity comparisons against established reference libraries.
147+
- Corrected two-way ANOVA residual and balance semantics, Welch/post-hoc degenerate cases,
148+
chi-square kernels, KernelRidge/KernelRidgeCV scoring, KernelPCA embedding consistency,
149+
and Nystroem normalization for indefinite kernels.
150+
- Corrected empirical precision estimation, Graphical Lasso block-coordinate updates,
151+
MinCovDet centered semantics, panel cluster/HAC contracts, Patsy side-array alignment,
152+
and rank-deficient panel regression fallbacks.
153+
- Implemented real spline extrapolation modes; hardened B-spline, KDE, kernel regression,
154+
GAM, and binary-metric input contracts.
155+
- Added three focused regression suites and expanded the permanent Python 3.9–3.12,
156+
full-CPU, static-contract, compilation, and complete-collection gates.
157+
- The physical CuPy/Torch CUDA numerical, memory, type/device, and performance validation
158+
planned at this stage was completed on 2026-07-21.
159+
160+
### PR #79 — Ridge objective and weighted-path consistency follow-up
161+
162+
- Confirmed that statgpu Ridge uses the package-wide average-loss objective rather
163+
than scikit-learn's unnormalized residual-sum-of-squares convention.
164+
- Preserved the exact normal equations `X'X + n*alpha*I` for unweighted fits and
165+
`X'WX + sum(w)*alpha*I` for weighted fits; scikit-learn comparisons now use the
166+
explicit corresponding alpha mapping.
167+
- Unified weighted Ridge behavior across the optimized wrapper, generic exact solver,
168+
FISTA, formula fitting, CPU/CuPy/Torch exact paths, Gaussian inference, RidgeCV,
169+
and `PenalizedGLM_CV(loss="squared_error", penalty="l2")`.
170+
- Corrected weighted centering before square-root weighting, weighted intercept and
171+
residual construction for inference, and weighted default alpha-grid generation.
172+
- `PenalizedGLM_CV` now generates weighted alpha grids from the normalized weighted
173+
null gradient and avoids building an unused host-side Gram cache for the default
174+
GPU Newton Ridge route.
175+
- Formula evaluation now exposes retained row positions so sample weights remain
176+
aligned when Patsy drops rows containing missing values.
177+
- GPU sample-weight validation and normalization use device-side reductions and
178+
synchronize only scalar results, avoiding full weight-vector host transfers.
179+
- Added regression coverage for weighted closed forms, weight-rescaling invariance,
180+
exact/FISTA and wrapper/generic equality, formula missing rows, inference covariance,
181+
both Ridge CV implementations, and weighted scikit-learn alpha mapping.
182+
183+
## 2026-07-11
184+
185+
### PR #79 — Full repository review and hardening
186+
187+
- Completed an iterative repository-wide review covering correctness, backend routing,
188+
statistical/API contracts, readability, maintainability, extensibility, performance
189+
risks, test quality, and compliance with `dev/AGENTS.md`.
190+
- Fixed backend/device validation, sklearn-style estimator parameters, Torch inference
191+
routing, UMAP fuzzy-union and random-state semantics, NNDescent correctness, adaptive
192+
L1 and knockoff runtime errors, CV input contracts, KMeans/UMAP edge cases, and Cox
193+
Efron observed-information orientation.
194+
- Hardened tests so optional Torch/CuPy dependencies skip explicitly instead of failing
195+
collection or swallowing unexpected errors; moved the remote GPU runner outside the
196+
pytest test tree.
197+
- Added focused review regression suites and permanent Python 3.9–3.12, full CPU,
198+
compilation, static-contract, and complete test-collection CI gates.
199+
- Added `dev/reviews/pr79_full_repository_review.md` with accepted fixes, deferred
200+
architectural debt, and the physical-GPU validation plan.
201+
- The physical CuPy/Torch CUDA numerical, memory, and performance validation required at
202+
this stage was completed on 2026-07-21.
203+
204+
## 2026-07-08
205+
206+
### v0.2.1 — Packaging / PyPI release hygiene
207+
208+
- **Version bump** 0.2.0 → 0.2.1 (`pyproject.toml`, `statgpu/__init__.py`).
209+
- **Pure-Python wheel policy**: the PyPI release workflow now sets `STATGPU_NO_EXT=1`,
210+
so the published wheel is tagged `py3-none-any` and installs on every OS / Python
211+
version. Previously `python -m build` compiled the optional Cython extensions during
212+
`bdist_wheel`, producing a platform-locked wheel that served almost no one and forced
213+
everyone else onto the sdist.
214+
- **setup.py**: added the `STATGPU_NO_EXT` switch. The Cython extensions remain optional
215+
CPU accelerators with pure-Python fallbacks.
216+
- **publish.yml**: added `twine check dist/*` before upload.
217+
218+
### PR #74 — Ordered Newton-Raphson + Analytical Hessian Inference + Unified Sandwich Engine
219+
220+
- Ordered Logit/Probit: L-BFGS replaced with Newton-Raphson + trust-region (3-backend).
221+
- Ordered inference: analytical Hessian, SE/z/p/CI, loglikelihood/aic/bic (CPU+GPU).
222+
- Sandwich engine: m-estimation inference, Fisher information, and penalty curvature API.
223+
- Penalized inference: sandwich (L2/EN), oracle active-set (SCAD/MCP).
224+
- QuantileRegression standalone class with kernel and bootstrap inference.
225+
- 28 bug fixes across four code-review rounds; scipy distribution calls routed through
226+
the project distribution abstraction where applicable.

0 commit comments

Comments
 (0)