NVIDIA / NVIDIA/cuvs

[BUG] IVF-FLAT distance computation in FP16 can lead to infinite distances

Open
#914 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.