Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
66d7fd3
combine impls
tarang-jain Apr 10, 2026
0a09e6f
rm inertia_check
tarang-jain Apr 13, 2026
99a5730
change to warning
tarang-jain Apr 13, 2026
a077406
style
tarang-jain Apr 13, 2026
d659875
add init_size param
tarang-jain Apr 13, 2026
ec2e8b7
Merge branch 'main' into combine-batch
tarang-jain Apr 13, 2026
03a6473
docs
tarang-jain Apr 13, 2026
42a8d9d
Merge branch 'combine-batch' of https://github.com/tarang-jain/cuvs i…
tarang-jain Apr 13, 2026
86af2fa
rm direct cuda api calls
tarang-jain Apr 13, 2026
d4e4e2c
std::swap instead of raft::copy
tarang-jain Apr 14, 2026
0819af5
cache batch norms
tarang-jain Apr 14, 2026
e0f079c
centroid norms can also be cached per iteration
tarang-jain Apr 14, 2026
c2f7390
mg n_iter
tarang-jain Apr 14, 2026
b9c3102
pre-commit
tarang-jain Apr 14, 2026
e3956c1
do not break c abi
tarang-jain Apr 14, 2026
986d78a
Merge branch 'main' into combine-batch
tarang-jain Apr 14, 2026
a8e1d26
Merge branch 'main' into combine-batch
tarang-jain Apr 16, 2026
384d054
fix checkWeight
tarang-jain Apr 21, 2026
455b286
merge upstream:
tarang-jain Apr 21, 2026
5462809
Merge branch 'combine-batch' of https://github.com/tarang-jain/cuvs i…
tarang-jain Apr 21, 2026
6ba759c
fix compilation
tarang-jain Apr 21, 2026
e76eaac
rel_tol
tarang-jain Apr 22, 2026
afbefdf
pass workspace
tarang-jain Apr 22, 2026
e62a63c
Merge branch 'combine-batch' of https://github.com/tarang-jain/cuvs i…
tarang-jain Apr 22, 2026
e4f08bf
style
tarang-jain Apr 22, 2026
6e4a8f0
Merge branch 'main' of https://github.com/rapidsai/cuvs into combine-…
tarang-jain Apr 22, 2026
4a8a85c
do not use batch scratch space; rm update_centroids
tarang-jain Apr 22, 2026
bbf2a9f
move the debug log
tarang-jain Apr 22, 2026
410092c
add new suffixed param struct
tarang-jain Apr 22, 2026
c515c1e
address pr reviews
tarang-jain Apr 22, 2026
e8e63ab
fix docstring
tarang-jain Apr 22, 2026
30c457c
fix wt_sum warning
tarang-jain Apr 22, 2026
ab96623
rm deprecationwarning and instead add FutureWarning:=
tarang-jain Apr 22, 2026
269f23c
unweighted to never materialize batch weights
tarang-jain Apr 22, 2026
80a22ca
add cpp tests
tarang-jain Apr 23, 2026
ac06b05
update cpp tests
tarang-jain Apr 23, 2026
0569340
revert batch norms cache
tarang-jain Apr 23, 2026
8cac63a
increase zero cost threshold
tarang-jain Apr 24, 2026
f6df4ae
apply cuda event plus re-add h_norm_cache
tarang-jain Apr 24, 2026
9fc74b1
rm cosine expanded stuff
tarang-jain Apr 24, 2026
dec3dc4
resolve merge conflicts
tarang-jain Apr 28, 2026
0d030a2
change suffix of the params struct
tarang-jain Apr 28, 2026
b1c034e
replace 06 by 08, add todo and note
tarang-jain Apr 28, 2026
a482495
update to v2
tarang-jain Apr 28, 2026
8ecfdc1
avoid stream sync inside weight sum
tarang-jain Apr 29, 2026
1e1525e
Merge branch 'combine-batch' of https://github.com/tarang-jain/cuvs i…
tarang-jain Apr 29, 2026
ec22e07
empty
tarang-jain Apr 29, 2026
d2e410d
empty
tarang-jain Apr 29, 2026
b791c38
Merge branch 'main' into combine-batch
tarang-jain Apr 29, 2026
a05a006
new signatures with new struct
tarang-jain Apr 29, 2026
73293cf
Merge branch 'combine-batch' of https://github.com/tarang-jain/cuvs i…
tarang-jain Apr 29, 2026
880c7b9
Merge branch 'main' of https://github.com/rapidsai/cuvs into combine-…
tarang-jain Apr 30, 2026
e2035ec
revert change to calls in py and rust; add c tests
tarang-jain Apr 30, 2026
e28c200
Merge branch 'main' into combine-batch
tarang-jain May 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions c/include/cuvs/cluster/kmeans.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct cuvsKMeansParams {
*/
int batch_centroids;

/** Check inertia during iterations for early convergence. */
/** Deprecated, ignored. Kept for ABI compatibility. */
Comment thread
tarang-jain marked this conversation as resolved.
bool inertia_check;

/**
Expand All @@ -108,7 +108,14 @@ struct cuvsKMeansParams {
* Number of samples to process per GPU batch for the batched (host-data) API.
* When set to 0, defaults to n_samples (process all at once).
*/
int64_t streaming_batch_size;
int64_t streaming_batch_size;

/**
* Number of samples to draw for KMeansPlusPlus initialization.
* When set to 0, uses heuristic min(3 * n_clusters, n_samples) for host data,
* or n_samples for device data.
*/
int64_t init_size;
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.

typedef struct cuvsKMeansParams* cuvsKMeansParams_t;
Expand Down
7 changes: 4 additions & 3 deletions c/src/cluster/kmeans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cuvs::cluster::kmeans::params convert_params(const cuvsKMeansParams& params)
kmeans_params.oversampling_factor = params.oversampling_factor;
kmeans_params.batch_samples = params.batch_samples;
kmeans_params.batch_centroids = params.batch_centroids;
kmeans_params.inertia_check = params.inertia_check;
kmeans_params.init_size = params.init_size;
kmeans_params.streaming_batch_size = params.streaming_batch_size;
return kmeans_params;
}
Expand Down Expand Up @@ -237,10 +237,11 @@ extern "C" cuvsError_t cuvsKMeansParamsCreate(cuvsKMeansParams_t* params)
.oversampling_factor = cpp_params.oversampling_factor,
.batch_samples = cpp_params.batch_samples,
.batch_centroids = cpp_params.batch_centroids,
.inertia_check = cpp_params.inertia_check,
.inertia_check = false,
.hierarchical = false,
.hierarchical_n_iters = static_cast<int>(cpp_balanced_params.n_iters),
.streaming_batch_size = cpp_params.streaming_batch_size};
.streaming_batch_size = cpp_params.streaming_batch_size,
.init_size = cpp_params.init_size};
});
}

Expand Down
9 changes: 7 additions & 2 deletions cpp/include/cuvs/cluster/kmeans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,14 @@ struct params : base_params {
int batch_centroids = 0;

/**
* If true, check inertia during iterations for early convergence.
* Number of samples to randomly draw for the KMeansPlusPlus initialization
* step. A random subset of this size is used for centroid seeding.
* When set to 0 the default depends on the data location:
* - Device data: n_samples (use the full dataset).
* - Host data: min(3 * n_clusters, n_samples).
* Default: 0.
*/
bool inertia_check = false;
int64_t init_size = 0;
Comment on lines 115 to +127
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Breaking removal of inertia_check from the public C++ params struct lacks deprecation/migration notes.

The cuvs::cluster::kmeans::params::inertia_check field has been removed outright (replaced by init_size). Any downstream C++ code that sets or reads params.inertia_check will now fail to compile with a hard error, despite the PR being labeled non-breaking. The C API preserves the field for ABI compatibility (marked deprecated/ignored), but the C++ API does not offer the same grace period.

Please either:

  1. Retain a deprecated [[deprecated("ignored; use init_size instead")]] bool inertia_check = false; stub in the struct for one release cycle so existing call sites keep compiling with a warning, and
  2. Add a migration note in the project docs/CHANGELOG explaining that inertia_check is gone and that inertia-based convergence is now always on.

As per coding guidelines: "API changes flagged for docs/ updates" and "Breaking changes require deprecation warnings and migration guide updates".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cpp/include/cuvs/cluster/kmeans.hpp` around lines 115 - 123, Restore a
deprecated stub for the removed field in the cuvs::cluster::kmeans::params
struct by reintroducing a [[deprecated("ignored; use init_size instead")]] bool
inertia_check = false; member so existing C++ call sites compile with a warning
(reference cuvs::cluster::kmeans::params and inertia_check), and update the
project docs/CHANGELOG with a short migration note stating inertia_check is
deprecated/ignored and that inertia-based convergence is now always on (point
users to use init_size instead); keep the C API behavior unchanged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I soflty agree with this rabbit comment, would be worth to add a not in the PR description and code, C++ callers using the C++ API directly will fail to compile, not warn. That's a real source-API break worth a release-notes line at least

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dantegd, agreed — C++ callers setting params.inertia_check = true/false will get a hard compile error rather than a deprecation warning, which is a real source-level break regardless of ABI stability. The C API handled this gracefully by keeping the field and marking it @deprecated / ignored; the C++ side deserves the same treatment for at least one release cycle.

Concretely, I'd suggest three things:

  1. Add a [[deprecated]] stub in cuvs::cluster::kmeans::params so existing call sites get a compiler warning instead of an error (using current CalVer per repo convention — 26.06):
/**
 * `@deprecated` since 26.06 — ignored. Inertia-based convergence now always runs.
 *             Use `init_size` to control KMeans++ seeding sample count.
 *             Will be removed in a future release.
 */
[[deprecated("inertia_check is ignored since 26.06; inertia-based convergence always runs")]]
bool inertia_check = false;
  1. Add a release-notes / CHANGELOG entry (e.g., in docs/source/api_migration_guides.rst or equivalent) noting:

    • cuvs::cluster::kmeans::params::inertia_check is deprecated (26.06) and ignored — inertia-based convergence always runs.
    • The new init_size field controls KMeans++ initialization sample count for host data.
  2. Update the PR description with a short "Breaking / Migration" note so reviewers and downstream consumers are immediately aware.

Would you like me to plan the code changes for items 1 and 2 above?


🧠 Learnings used
Learnt from: tarang-jain
Repo: rapidsai/cuvs PR: 2001
File: cpp/src/cluster/detail/minClusterDistanceCompute.cu:44-50
Timestamp: 2026-04-22T22:31:00.223Z
Learning: In the cuvs repository (cpp/src/cluster/detail/kmeans.cuh), PR `#2001` adds CosineExpanded metric support to regular (non-balanced) k-means. The functions kmeansPlusPlus, kmeans_fit_main, initScalableKMeansPlusPlus, and kmeans_predict now compute L2NormX with sqrt_op for CosineExpanded. These paths call minClusterAndDistanceCompute passing params.metric, which can be CosineExpanded, but centroids are not L2-normalized in the regular k-means path before those calls.

Learnt from: tarang-jain
Repo: rapidsai/cuvs PR: 2001
File: cpp/src/cluster/detail/kmeans.cuh:735-737
Timestamp: 2026-04-28T15:11:10.465Z
Learning: In rapidsai/cuvs, IVF-PQ (cpp/src/neighbors/ivf_pq/ivf_pq_build.cuh) uses kmeans_balanced exclusively for clustering, not the regular k-means. It includes "../../cluster/kmeans_balanced.cuh" and declares `kmeans_params` as `cuvs::cluster::kmeans::balanced_params`, so calls to `cuvs::cluster::kmeans::fit` and `cuvs::cluster::kmeans::predict` in that file resolve to the balanced overloads (which support CosineExpanded), not the regular k-means functions in kmeans.cuh (which are L2-only). Do not flag these IVF-PQ call sites as incorrectly passing cosine metrics to regular k-means.

Learnt from: CR
Repo: rapidsai/cuvs PR: 0
File: cpp/REVIEW_GUIDELINES.md:0-0
Timestamp: 2026-04-28T15:35:48.940Z
Learning: Applies to cpp/**/*.{cu,cuh,cpp,hpp,h} : Data format parameters (row-major vs column-major, memory layout) must be explicit in function signatures and documentation; ambiguous data layout assumptions should be clarified or eliminated

Learnt from: cjnolet
Repo: rapidsai/cuvs PR: 2015
File: c/include/cuvs/cluster/kmeans.h:126-126
Timestamp: 2026-04-28T16:26:32.708Z
Learning: In the rapidsai/cuvs repository, CalVer deprecation notices use the *current* minor release version (e.g., 26.06), not a future one. This makes it immediately clear exactly when the change/deprecation was introduced. Example: "CalVer for the replacement: 26.06" in c/include/cuvs/cluster/kmeans.h.

Learnt from: CR
Repo: rapidsai/cuvs PR: 0
File: cpp/REVIEW_GUIDELINES.md:0-0
Timestamp: 2026-04-28T15:35:48.940Z
Learning: Applies to cpp/include/cuvs/**/*.{hpp,h} : Public API functions must use stateless interfaces: accept POD types, raft::resources, pointers to POD, or mdspan; avoid exposing stateful objects or breaking changes without deprecation warnings

Learnt from: CR
Repo: rapidsai/cuvs PR: 0
File: cpp/REVIEW_GUIDELINES.md:0-0
Timestamp: 2026-04-28T15:35:48.940Z
Learning: Applies to cpp/**/*.{cu,cuh,cpp,hpp,h} : Deprecated CUDA API calls should be replaced with modern equivalents (e.g., avoid cudaMemcpyToSymbol, use modern memory management APIs)


/**
* Number of samples to process per GPU batch when fitting with host data.
Expand Down
Loading
Loading