Repository navigation
Description
Describe the bug
cuvs::neighbors::brute_force::search on a sparse (CSR) index returns different distances, and different neighbors, for identical inputs from one call to the next.
Downstream impact: cuML's t-SNE (and other kNN-graph consumers such as UMAP and NearestNeighbors) document that a fixed random_state gives reproducible results. On sparse input that isn't true, because the kNN graph changes between runs.
I found this while investigating an intermittent cuML CI failure in test_tsne_distance_metrics_on_sparse_input[euclidean-fft] (NVIDIA/cuml#8939).
Steps/Code to reproduce bug
cuVS's Python API doesn't expose sparse brute-force search, so this goes through cuML's NearestNeighbors. With sparse input it calls cuvs::neighbors::brute_force::build/search with sparse_search_params.
import numpy as np
import scipy.sparse
from sklearn.datasets import make_blobs
from cuml.neighbors import NearestNeighbors
X, _ = make_blobs(n_samples=1000, n_features=64, centers=5, random_state=42)
X = scipy.sparse.csr_matrix(X.astype(np.float32))
def knn():
nn = NearestNeighbors(n_neighbors=90, metric="euclidean").fit(X)
d, i = nn.kneighbors(X)
return np.asarray(d), np.asarray(i)
d0, i0 = knn()
for run in range(1, 6):
d, i = knn()
print(
f"run {run}: dists identical={np.array_equal(d0, d)}, "
f"max |diff|={np.abs(d0 - d).max():.6f}, "
f"rows with different neighbors={(i0 != i).any(axis=1).sum()}"
)Output (RTX A6000):
run 1: dists identical=False, max |diff|=0.038273, rows with different neighbors=33
run 2: dists identical=False, max |diff|=0.038273, rows with different neighbors=38
run 3: dists identical=False, max |diff|=0.038273, rows with different neighbors=32
run 4: dists identical=False, max |diff|=0.038273, rows with different neighbors=24
run 5: dists identical=False, max |diff|=0.038273, rows with different neighbors=27
The same data as a dense array, which goes through the dense brute-force path, returns identical results on every run.
Expected behavior
Repeated calls with the same index, queries and parameters on the same GPU return bit-identical distances and indices, as the dense brute-force path does. If deterministic accumulation costs too much to be the default, an opt-in (e.g. a flag on sparse_search_params) would let callers that promise reproducibility use it.
Environment details (please complete the following information):
- Environment location: Bare-metal, NVIDIA RTX A6000, driver 580.178.04
- Method of cuVS install: conda (
rapidsai-nightly),libcuvs 27.02.00a9 cuda13_261115054142_aac89669, with cuML 27.02 nightly, Python 3.14
The same code is on cuVS release/26.12 (668006e), and the original CI failure was on cuML 26.12 (wheel, CUDA 12.9, H100).
Additional context
The same atomic_add_op / compute_row_*_kernel pattern is shared by other sparse metrics (cosine, correlation, Hellinger, …), so they likely have the same issue.
Claude helped track this down and gave some additional details.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNeeds Triage
Activity
arcusbuilds commentedon Nov 21, 2026
I'd like to take this. The drift comes from two places:
compute_row_norm_kernel/compute_row_sum_kernelinl2_distance.cuh(andbin_distance.cuh)atomicAddevery non-zero intoout[row].coo_spmv_kernel.cuh: a B row can span several warps/blocks, and each partial sum is atomic-added into the same output cell.Plan: PR 1 sums the row norms in a fixed order over
indptr(cheap, so no flag) and adds a test that runs the search twice and checks the output is bit-identical. PR 2 adds an opt-indeterministicoption where one warp owns each output cell, default off. Does that split work for you, and is there a preferred place for the flag?