[BUG] IVF-FLAT distance computation in FP16 can lead to infinite distances
Open
Nobody has claimed this yet.
bug
- Dominant language
- Cuda
- Stars
- 854
- Forks
- 236
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 62
Description
IVF-Flat in FP16 accumulate distances in FP16, which can lead to infinite distances.
To ensure accurate distance computation, FP32 should be used for accumulation.
This can be reproduced by changing the uniform distribution we're using in test to a uniform between 0.0 and 100.0
Python example
from cuvs.neighbors import ivf_flat
import cupy as cp
a=cp.random.uniform(0,100,(1000,128)).astype(cp.float16)
b=cp.random.uniform(0,100,(20,128)).astype(cp.float16)
index = ivf_flat.build(ivf_flat.IndexParams(n_lists=20), a)
distances, neighbors = index.search(ivf_flat.SearchParams(n_probes=20), index, b, 1)
print(distances.copy_to_host())
# [inf, inf, inf, ...]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Python example with FP16 inputs and the larger uniform distribution described in the issue, using ivf_flat build and search. Inspect the existing uniform-distribution test and the IVF-Flat distance computation path; done means FP32 accumulation prevents infinite distances for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning, search
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100