Repository navigation
C4 memory, zero certificates for plr, and C5 threads inside one lr/plr fit - #124
Merged
Merged
Conversation
Outcomes whose row IDs are consecutive keep neither the row-ID map nor the row labels: a row's ID is firstRowId + i, checked with unsigned arithmetic, and labels are made on demand. The loaders that add rows or look rows up through the map (stratified time effects, append) fill them first. The engines no longer allocate hYWeight/hYWeightDouble for models without two-way scans, or numerPid3/numerPid4/denomPid2, which only the GPU engines read (they size denomPid2 themselves). About 40 bytes per row in every data copy (cross-validation and bootstrap clones), and 16 bytes per row plus the label strings in the data. No kernel or ordering change: results identical; suite 353 tests / 1921 expectations, 0 failed. New quick test test-consecutiveRowIds.R. NEWS 49. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
plr's coordinate descent visited every Laplace column at zero; lr skips a visit when drift bounds prove its step is zero. plr now keeps the same drift totals over its implicit person-interval rows and certifies columns of 1s, with or without a 0/1 time-basis column (CCW's indicator basis and day0 interactions), in the serial and the concurrent cycle. One definition of a certifiable column (getCertifiableRows), drift structures built lazily (auto/newton fits pay nothing), rounding bounds that stay valid across epochs and non-normal exp values, and the exclusions of lr plus the cloglog link. CYCLOPS_ZVERIFY recomputes the step at every certified visit and fails if it is not zero (debug). Results bitwise identical with certificates on or off and on 1-4 threads; ZVERIFY: 0 violations over 1,105,682 certified visits on a CCW model and on stress data (offsets to +-900, zero weights, 400 columns, CV). CCW fixed-variance plr ccd fit: 96.6 -> 65.0 s on 1 thread, 78.9 -> 62.9 s on 4; auto (2.2 s) and lr (13.7 s) unchanged. Suite 356 tests / 1931 expectations, 0 failed. NEWS 50. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Plan item C5. Within one fit, terms are computed on the fit's threads and added on the calling thread in the serial order with the serial expressions (one template per kernel; the reduction loops are kept scalar so the compiler cannot vectorize one path and fuse the other), so results are bitwise identical on any number of threads, and on one thread unchanged. - plr coordinate descent: a column of at least 4,096 subjects computes its gradient and update on up to 4 threads (about one per 2,048 entries); zero-certificate stores stay on the calling thread - Newton steps: lr row weights, full gradient, Hessian-block transposition, trial log likelihoods and step; plr's per-subject column layout (part-wise column pass), full gradient, direction, log likelihoods and refreshes - WorkerPool runs wake and wait for only the workers they use - ordered sums keep at most 2^19 rows of terms (about 20 MB with threads, whatever the size) - cross-validation folds keep coordinate descent on one thread and give spare threads to the second-order kernels CCW fixed-variance models, 25k persons, medians of 3 paired runs, 1/2/4/8 threads: plr ccd 66.0/63.8/63.9/64.8 -> 64.0/42.8/30.3/29.1 s, plr auto 4.27/2.84/2.16/1.81 -> 4.27/2.45/1.55/1.16 s, lr auto 6.54/3.91/2.68/2.05 -> 6.54/3.57/2.23/1.52 s, lr ccd unchanged; a 10-fold cross-validated plr fit on 4 threads 132 -> 130 s. Identical coefficients, log likelihoods and certified visits at 1, 2, 3, 4 and 8 threads (also with forced small windows). New quick tests test-threadsOneFit.R; suite 363 tests / 1947 expectations, 0 failed. NEWS 51. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #124 +/- ##
===========================================
+ Coverage 85.60% 85.91% +0.30%
===========================================
Files 73 73
Lines 15945 16338 +393
===========================================
+ Hits 13650 14036 +386
- Misses 2295 2302 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 20, 2026
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
Three commits from the Phase 3 scale plan (NEWS 49–51), based on #123. Results are bitwise unchanged throughout. Each item was implemented, then adversarially reviewed, and every confirmed finding was fixed.
1. C4: less memory per data object and per copy (NEWS 49)
Row-ID map. Outcomes with consecutive row IDs keep no row-ID map and no row labels. Row i has ID
firstRowId + i, checked with unsigned arithmetic, and labels are made on demand. The stratified time-effect loader andappendfill the map first.Unused arrays. The engines no longer allocate:
numerPid3,numerPid4anddenomPid2, which only the GPU engines read and now size themselves.That saves about 40 bytes per row in every cross-validation or bootstrap copy.
Deferred:
arrowdependency;2. Zero certificates for plr coordinate descent (NEWS 50)
lr's coordinate descent skips a visit to a Laplace column at zero when drift bounds prove its step is zero. plr now keeps the same drift totals over its implicit person-interval rows. It certifies columns of 1s, with or without a 0/1 time-basis column, which covers CCW's indicator basis and its day-0 interactions. This works in both the serial and the concurrent cycle.
Design:
getCertifiableRows;autoandnewtonfits pay nothing;expvalues;Debug check:
CYCLOPS_ZVERIFYrecomputes the step at every certified visit and fails if it is not zero. It found 0 violations in 1,105,682 certified visits on a CCW model, and in stress data with offsets up to ±900, zero weights, 400 columns and cross-validation.Timings on a fixed-variance CCW model:
ccd, 1 threadccd, 4 threadsauto3. C5: threads inside one lr or plr fit, bitwise identical (NEWS 51)
Inside one fit, terms are computed on the fit's threads and added on the calling thread in the serial order, using the serial expressions. Each kernel uses one template for both paths, and its reduction loops are kept scalar. On Apple clang, identical source expressions had vectorized the threaded sum but fused the serial one, so their last bits differed; the new tests catch that.
WorkerPoolruns wake and wait for only the workers they use;Timings on CCW fixed-variance models, 25,000 persons, medians of 3 paired runs:
ccdautoautoccdA 10-fold cross-validated plr fit on 4 threads went from 132 s to 130 s.
Coefficients, log-likelihoods and certified visits are identical at 1, 2, 3, 4 and 8 threads, including builds with forced small windows. Profiles, confidence intervals and bootstrap samples are identical too.
Not verified
-ffp-contract=fast, on arm64 or with-march=native. The new tests would catch a mismatch.Tests
test-consecutiveRowIds.R;test-pooledLogistic.R: on vs off, threads, large offsets, cloglog and cross-validation;test-threadsOneFit.R: lr and plr, cloglog, weights and offsets, at uneven thread counts.test_dir, withoutNOT_CRAN): 363 tests, 1,947 expectations, 0 failed, 0 errors, 30 skipped.🤖 Generated with Claude Code