Skip to content

fix knn_merge_parts for inner product - #2426

Open
qwertyforce wants to merge 2 commits into
NVIDIA:mainfrom
qwertyforce:knn_merge_parts_fix_ip
Open

fix knn_merge_parts for inner product#2426
qwertyforce wants to merge 2 commits into
NVIDIA:mainfrom
qwertyforce:knn_merge_parts_fix_ip

Conversation

@qwertyforce

Copy link
Copy Markdown
Contributor

By default, when merging the results of sharded multigpu index, knn_merge_parts keeps K smallest values. But inner product is not a distance, it is a measure of similarity. Therefore results are wrong for IP.
In this PR we are adding an additional overload, that receives an argument select_min, we keep backward compatibility and add a new test

@copy-pr-bot

copy-pr-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@divyegala divyegala left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @qwertyforce, thank you for the PR! I think this change will severely affect the binary size of cuVS, can you please provide a before-after measurement? Alternatively, we could run an element-wise operation to negate the inner product distances before running the merge kernel.

@qwertyforce

Copy link
Copy Markdown
Contributor Author

Hi! i ran ./build.sh libcuvs --allgpuarch --no-nvtx -n (GCC 13, CUDA 12.8)
main vs patched
libcuvs.so increased from 504MB to 512MB
knn_merge_parts.cu.o increased from 8MB to 16MB

@divyegala

Copy link
Copy Markdown
Contributor

Thanks @qwertyforce , in that case can we please pursue the alternative of running a negation for inner product?

@qwertyforce

Copy link
Copy Markdown
Contributor Author

Yes, will try to implement and benchmark it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants