faiss icon indicating copy to clipboard operation
faiss copied to clipboard

[GPU] Adding new vectors to loaded index doesn't work on GPU

Open MarcSzafraniec opened this issue 3 years ago • 1 comments

Summary

Platform

OS: CentOS (Fair Cluster)

Faiss version: Latest version obtain by conda install faiss-gpu (1.7.2)

Installed from:

Faiss compilation options:

Running on:

  • [ ] CPU
  • [x] GPU

Interface:

  • [ ] C++
  • [x] Python

Reproduction instructions

import faiss
import numpy as np

index = faiss.read_index("index.faiss")  # non empty faiss IVF index, specifically OPQ64_256,IVF262144,PQ64 in my case

gpu_options = faiss.GpuMultipleClonerOptions()
gpu_options.useFloat16 =True

chunk = np.array(np.ones((n, d)), dtype=np.float32, copy=True, order="C", ndmin=1,)
index_gpu = faiss.index_cpu_to_gpus_list(index, co=gpu_options, gpus=None)
index_gpu.add(chunk)

Results in

Faiss assertion 'indices->numVecs == oldNumVecs' failed in int faiss::gpu::IVFBase::addVectors(faiss::gpu::Tensor<float, 2, true>&, faiss::gpu::Tensor<long int, 1, true>&) at /home/conda/feedstock_root/build_artifacts/faiss-split_1644327811086/work/faiss/gpu/impl/IVFBase.cu:581

While, if I load a trained but empty index of the exact same type, the add will work. If I try to do the same thing but on CPU, it will also work.

MarcSzafraniec avatar Oct 21 '22 14:10 MarcSzafraniec

We also observe this behavior in faiss-gpu 1.7.2. (using python 3.8 and cuda 11.3 installed via conda -c pytorch)

index = faiss.read_index(filename)
index = faiss.index_cpu_to_gpu(faiss.StandardGpuResources(), gpu_id, index)
index.add(...)

This code works correctly if filename points to a Flat index, but fails with the previously mentioned assert if an IVF index is specified.

umbra-scientia avatar Oct 28 '22 17:10 umbra-scientia

please use add_with_ids.

mdouze avatar Oct 30 '22 09:10 mdouze