Repository navigation
Unify the plain-commit and trial add paths - #150
Open
NiklasMelton wants to merge 3 commits into
Open
NiklasMelton wants to merge 3 commits into
NiklasMelton wants to merge 3 commits into
Conversation
Each index now has one add implementation. The base _param_inc plans the single label and applies it, so plain commits, trials and memoized commits share the same formulas: - Counts, centroids and compactness come from shared helpers in _trial that take one vector or one row per slot. - Index-specific statistics needed only for scoring (_plan_add_index) are computed only when a plan is scored. Applying a slot uses its scored row, or computes that one row with the same _add_row. - One-label plans keep per-slot values in one-element lists, converted to arrays only before scoring, to avoid the 1-row array overhead that blocked this in #147. - Inner products use np.inner for one vector and np.vecdot for rows. These run the same inner loop, so plain streaming commits stay bit for bit identical to 0.7.2 and to memoized commits. The trial tests now require exact agreement between plain and memoized commits; the cross-path tolerance is gone. The test that plain commits avoid the planner is replaced by one that they skip scoring.
np.add.reduce gives identical results without np.sum's Python wrapper, which dominates on the short rows of one streaming update (about 0.5 us per call at K=40, d=8).
Times plain incremental updates per index, optionally against another checkout, alternating subprocess rounds so machine drift affects both.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #150 +/- ##
===========================================
- Coverage 96.34% 95.93% -0.42%
===========================================
Files 22 22
Lines 3313 2975 -338
===========================================
- Hits 3192 2854 -338
Misses 121 121 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Closes #148.
What changed
Each incremental index (CH, WB, XB, DB, GD43, GD53, PS, cSIL, rCIP) now has one add implementation. The nine per-index
_param_incmethods are gone (about 640 lines). The base_param_incplans the single label and then applies it, so plain commits, trials and memoized commits all run the same formulas._trial(centroid_update,compactness_update). They accept either one vector or one row per slot. cSIL's centered moments work the same way through its own_moment_update._plan_add_index(CH/WB separation terms, candidate distance or dispersion rows) is now computed only for scored plans. Applying a slot uses the scored row if there is one. Otherwise it computes that slot's row with the same_add_row.AddPlan.vectorize()converts them to arrays only before scoring. Building 1-row arrays was the fixed overhead that blocked this in Trial mode, move, and lifecycle methods #147.np.inner. Rows usenp.vecdot, which runs the same inner-product loop per row. With NumPy < 2, the fallback is an exact per-rownp.innerloop.Numerics
Plain streaming commits are bit for bit identical to 0.7.2/develop. I checked full object state and every returned score with strict types for all nine indices. The check covered both backends, d ∈ {1, 3, 8, 13}, K ∈ {2, 7, 40} and 600-sample streams, plus a remove and an uncached move. The trial tests now require exact agreement between plain and memoized commits, so the 1e-12 cross-path tolerance (
CROSS_PATH) is removed.test_plain_commits_do_not_use_the_trial_pathis replaced by a test that plain commits plan without scoring.Speed
New
benchmarks/benchmark_streaming_add.pytimes_param_incper sample against another checkout, alternating subprocess rounds. Results at K=40, d=8, median of 5 rounds, macOS,OPENBLAS_NUM_THREADS=1, with other load on the machine:This is not quite "within noise". The remaining cost is Python bookkeeping in plan/apply: about 0.3–0.7 µs per update, and about 2 µs for cSIL. Run-to-run noise was about 2–3%. For comparison, the attempt in #147 cost about 10 µs (+85% for CH). The figures above already include a separate commit that makes
centroid_distancescallnp.add.reduceinstead ofnp.sum. That gives identical results and saves about 0.5 µs per call. Without it the overhead would be roughly 0.5 µs higher. Closing the rest would probably take compiling the one-label update (Numba). The issue lists that as an option, but I left it out of scope here.Trials did not regress, except cSIL vectorized at about +4%. Per-call trial times (develop → this PR), with 41 candidates / a single label:
Testing
python -m pytest tests: 1807 passed, 149 skipped (numba installed; JAX tests skipped locally).