facebookresearch / faiss

A library for efficient similarity search and clustering of dense vectors.
https://faiss.ai
MIT License
31.57k stars 3.65k forks source link

add_with_ids fails on GPU but works after moving the index to the CPU, is this expected? #3631

Open sniklaus opened 4 months ago

sniklaus commented 4 months ago

Summary

add_with_ids fails on GPU but works after moving the index to the CPU, is this expected? Thank you in advance!

Platform

OS: nvidia/cuda:12.1.1-devel-ubuntu22.04

Faiss version: 1.8.0 / py3.11_hedc54c9_0_cuda11.4.4

Installed from: conda install -c pytorch -c nvidia faiss-gpu -y

Faiss compilation options: N/A

Running on:

Interface:

Reproduction instructions

import faiss
import numpy
idx = faiss.index_factory(1024, 'OPQ48_336,IVF131072,PQ48x8', faiss.METRIC_INNER_PRODUCT)
idx = faiss.index_cpu_to_all_gpus(idx)
idx.train(numpy.random.rand(131072, 1024).astype(numpy.float32))
idx.add_with_ids(numpy.random.rand(3, 1024).astype(numpy.float32), numpy.array([4, 5, 6], numpy.int64)) # fails
idx = faiss.index_gpu_to_cpu(objIndex)
idx.add_with_ids(numpy.random.rand(3, 1024).astype(numpy.float32), numpy.array([4, 5, 6], numpy.int64)) # works
ramilbakhshyiev commented 4 months ago

Hi @sniklaus, is this the error message that you're getting?

RuntimeError:Error in virtual void faiss::Index::add_with_ids(faiss::idx_t, const float *, const faiss::idx_t *) at fbcode/faiss/Index.cpp:45: add_with_ids not implemented for this type of index
sniklaus commented 4 months ago

That's exactly it. :+1:

sniklaus commented 4 months ago

It is just surprising that it works just fine on the CPU and I am not sure whether it is by design or whether it is a bug.

ramilbakhshyiev commented 4 months ago

@sniklaus I pinged our GPU group to take a look at this. Thanks for reporting this!