Repository navigation
[POC] KMeans With IVF For 1-NN Assignment - #2963
Closed
tarang-jain wants to merge 5 commits into
Closed
tarang-jain wants to merge 5 commits into
tarang-jain wants to merge 5 commits into
Conversation
Apply NVIDIA#2851 at 8d10cec onto current upstream main, preserving the upstream loader implementation.
Rebuild dense centroid lists each iteration, sort and gather query/list pairs, and merge list-local top-1NN results without adding custom distance kernels. Expose IVF settings in C++, C, and Python, preserve exhaustive final inertia, and support weighted and sharded multi-GPU training. Validated 11 single-GPU regression tests, a two-GPU host-sharding test, C parameter defaults/layout, both Cython bindings, and Python test lint.
Contributor
Author
|
Closing in favor of cagra (discussed offline) |
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.
Adds optional IVF-based centroid assignment to KMeans. Each Lloyd iteration rebuilds IVF lists over the current centroids, routes queries to their closest coarse clusters, sorts and gathers queries by list, calls the existing
minClusterAndDistanceCompute/top_1_nnprimitives within each list, and reduces the list results to one original centroid ID per query. No custom CUDA kernels are added.centroid_ivf_paramsreuses the existing IVF-Flat build and search parameter structs fromivf_flat.hpp. The feature is available through C++, C, Python, and multi-GPU KMeans. Omitting it preserves exhaustive assignment. Final public fit inertia and prediction remain exhaustive.Includes the pageable-host double-buffering changes from #2851; the batch loader is unchanged from that PR. The shared
kmeans_typeenum lives inneighbors/common.hpp, retaining its original namespace and values, socommon.hppno longer depends on the KMeans parameter definitions.Single Lloyd iteration: checkpoint 5 → 6
Falcon: 960,000,000 FP32 vectors × 1,024 dimensions, 300,000 centroids, sharded evenly across 3 NVIDIA RTX PRO 6000 Blackwell Server Edition GPUs (devices 5–7, 320M rows each). All methods start from the same saved iteration-5 centroid checkpoint. One measured run per method on a shared host.
Implementation:
d341aee19c533309a7a8ff2d54c0bf1d26a1934a. CUDA 13.3; driver 580.65.06. The benchmark links the current PR assignment primitives, current cuTile 1-NN kernels and current CAGRA search dispatch.IVF is 2.15× faster end to end than exhaustive assignment and 2.18× faster than CAGRA, with first-10M final inertia 0.00157% above exhaustive assignment.
Timing scope: one Lloyd update, including index construction, dataset reading/pageable-to-pinned staging, H2D transfers, norm computation, assignment, standard cuVS FP32 centroid accumulation, NCCL reduction, and centroid finalization. Initial context/buffer setup, JIT warmup, checkpoint writes, and separate final-inertia scoring are excluded; allocations performed within the measured iteration remain included. This measures the iteration primitives with the native batch-loader schedule, rather than the full public
fit()call, which also performs final exhaustive scoring.Search times are CUDA-event elapsed times around every assignment call, including internal host-submission gaps, accumulated separately on each GPU. Their sum is GPU-seconds, not parallel elapsed time. Iteration wall time is measured from the common start until all three GPUs finish the update. The IVF search measurement includes coarse routing, sorting/gathering, list scans, and cross-list top-1 reduction.
Settings:
device_buffer_samples=131072,batch_samples=131072,batch_centroids=0; the full staged batch is grouped by probed IVF list. PR Enable OOC KMeans transfer/compute overlap for pageable input #2851 uses two device buffers and two pinned-host staging buffers with a separate transfer stream.SINGLE_CTA,search_width=2,itopk_size=32,max_queries=16384, top-1 output, ordinary random initialization with no saved-neighbor seeds.Checkpoint-5 SHA256:
ac3b792623987bf04632ee3e5c3806d0422e371ba9d8c3294d283adf0bc1fef9. All runs audit exact shard coverage (960M rows total), save iteration-6 centroids, and retain per-batch CUDA-event timings.Validation
19 focused C++/multi-GPU/C API regression tests passed, including all-probe equivalence, bounded-probe and tail batches, empty lists, original-ID tie handling, host double buffering, weighted fitting, coarse-training subsampling, parameter defaults, and multi-GPU agreement. Public-header include-order compilation passed; the 12 single-GPU cases were also rerun against the final benchmark runtime and passed. Python Cython translation and formatting checks passed earlier in the branch; the full repository CI and Python runtime suite have not been run.