-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify cuvs-bench to be able to generate ground truth in CPU systems #466
base: branch-24.12
Are you sure you want to change the base?
Modify cuvs-bench to be able to generate ground truth in CPU systems #466
Conversation
Thanks for opening this. I think it looks good. Should we also add the cuvs and cupy dependencies to the gpu cuvs-bench python package? Right now users get a module not found error because those aren't installed w/ the gpu-enabled package. |
if metric == "squeclidean": | ||
diff = queries[:, xp.newaxis, :] - dataset[xp.newaxis, :, :] | ||
dist_sq = xp.sum(diff**2, axis=2) # Shape: (n_queries, n_samples) | ||
|
||
indices = xp.argpartition(dist_sq, kth=k - 1, axis=1)[:, :k] | ||
distances = xp.take_along_axis(dist_sq, indices, axis=1) | ||
|
||
sorted_idx = xp.argsort(distances, axis=1) | ||
distances = xp.take_along_axis(distances, sorted_idx, axis=1) | ||
indices = xp.take_along_axis(indices, sorted_idx, axis=1) | ||
|
||
elif metric == "inner_product": | ||
similarities = xp.dot( | ||
queries, dataset.T | ||
) # Shape: (n_queries, n_samples) | ||
|
||
neg_similarities = -similarities | ||
indices = xp.argpartition(neg_similarities, kth=k - 1, axis=1)[:, :k] | ||
distances = xp.take_along_axis(similarities, indices, axis=1) | ||
|
||
sorted_idx = xp.argsort(-distances, axis=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you been able to verify that this works as expected?
PR allows calculating ground truth for cuvs-bench on CPU systems. Current version uses a simple NumPy brute force, perhaps we should consider using faiss? cc @cjnolet @divyegala