perf(index): parallelize kmeans centroid recomputation - #8560
Open
isaac-dasari wants to merge 14 commits into
Open
perf(index): parallelize kmeans centroid recomputation#8560isaac-dasari wants to merge 14 commits into
isaac-dasari wants to merge 14 commits into
Conversation
isaac-dasari
marked this pull request as ready for review
August 17, 2026 07:00
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The workload-aware hybrid remains the right trade-off on the updated base: the KMeans patch, its numerical and concurrency dependencies, and direct training callers are unchanged. Fresh current-base/current-head checks preserve every centroid bit pattern, cluster size, and row order. The indexed PQ and low-dimensional max-sample cases remain materially faster, while repeated alternating measurements show no stable regression on fallback or two-thread paths.
Author
|
@Xuanwo kindly review the changes and merge the PR |
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
Closes #6369.
Motivation
The existing parallel recomputation partitions centroids across workers. Each centroid owner then scans the full membership array and only accumulates vectors belonging to its centroid range. This preserves locality and avoids shared writes, but repeats membership scanning across owners.
A naive input-partitioned reduction removes those rescans but requires private
k × dimensionaccumulators and can reduce effective parallelism or spend more time initializing and merging dense grids than doing useful centroid work. A serial membership index also regresses wall-clock time because its setup is not parallelized.This revision keeps the good properties of the existing owner-based algorithm and only removes repeated membership scans when the complete workload makes that worthwhile.
Implementation
Workload-aware strategy selection
The recomputation path considers the actual workload rather than using a row-count-only threshold. The selector accounts for worker count, centroid count, vector dimension/value size, owner count, index traffic, and the amount of work available to amortize index construction.
High-dimensional, low-sample, and low-parallelism workloads remain on the original centroid-owner rescan path. Low-dimensional workloads with enough parallel owner work use the indexed path.
Parallel stable owner index
For the indexed path, membership rows are grouped by centroid owner using contiguous input partitions processed in parallel. Each partition preserves source row order; owner slices are combined in partition order, so every owner sees globally ascending input rows.
Centroid owners then process only their indexed rows while retaining the same disjoint centroid-chunk ownership as the original implementation. This avoids shared centroid writes and preserves accumulation order and numerical results.
The index is proportional to the number of participating rows plus owner metadata; it does not allocate a dense
k × dimensionaccumulator per worker.Correctness coverage
Focused tests cover:
Benchmark coverage
The committed Criterion benchmark covers representative KMeans recomputation shapes:
low_sample_high_dim:N=512, dimension=1024, k=256default_ivf_high_dim:N=16,384, dimension=1024, k=64large_incremental_ivf:N=65,536, dimension=1024, k=4096default_pq_subvector:N=65,536, dimension=64, k=256max_sample_low_dim:N=131,072, dimension=128, k=256The latest Gatekeeper current-base/current-head verification is approved (
K-approved). It reports exact centroid bit patterns, cluster sizes, and row order preserved across the representative envelope. The indexed low-dimensional cases remain about 1.8–1.9× faster, while workloads that select the owner-rescan fallback show no material regression.Validation
Passed locally on the current base:
cargo fmt --all -- --checkcargo check -p lance-index --tests --benches --profile bench -j 1cargo clippy -p lance-index --tests --benches --profile bench -j 1 -- -D warningsgit diff --checkThe PR is ready for maintainer review.