Encode vectors using Quantizer not using GPU
Summary
I've trained a GpuIndexIVFScalarQuantizer. The training consumes the GPU correctly.
Next, for my application, I want to encode my vectors using the trained index. I want the encoding call to use the GPU instead of CPU but I couldn't get it to work. I've tried a few options but failed. Options tried:
- Using
GpuIndexIVFScalarQuantizer.sa_code(), I get the error:
File "/opt/conda/lib/python3.10/site-packages/faiss/class_wrappers.py", line 627, in replacement_sa_encode
codes = np.empty((n, self.sa_code_size()), dtype=np.uint8)
File "/opt/conda/lib/python3.10/site-packages/faiss/swigfaiss_avx2.py", line 2294, in sa_code_size
return _swigfaiss_avx2.Index_sa_code_size(self)
RuntimeError: Error in virtual size_t faiss::Index::sa_code_size() const at /home/conda/feedstock_root/build_artifacts/faiss-split_1685210641191/work/faiss/Index.cpp:126: standalone codec not implemented for this type of index
-
I tried using the quantizer attribute of the index, i.e.,
index_gpu.quantizer.compute_codes(). This works, but it uses a single CPU instead of the GPU. I'd like to use the GPU.a. I tried to convert the quantizer to a GPU index, but that isn't supported. I.e.,
quantizer_gpu = faiss.index_cpu_to_gpu(res, 0, index_gpu.quantizer)Results in:
File "/opt/conda/lib/python3.10/site-packages/faiss/swigfaiss_avx2.py", line 11819, in index_cpu_to_gpu
return _swigfaiss_avx2.index_cpu_to_gpu(provider, device, index, options)
RuntimeError: Error in virtual faiss::Index* faiss::Cloner::clone_Index(const faiss::Index*) at /home/conda/feedstock_root/build_artifacts/faiss-split_1685210641191/work/faiss/clone_index.cpp:373: clone not supported for this Index type N5faiss3gpu12GpuIndexFlatE
- I tried using the SQ attribute of the index. I.e.,
index_gpu.sq. Same issues. I couldn't get it to use the GPU; it just uses a single CPU core.
I would really appreciate some help on this. My goal is to use GpuIndexIVFScalarQuantizer, and encode my vectors using GPU. Thanks.
Platform
OS: Ubuntu
Faiss version: 1.7.4
Installed from: Conda
Running on:
- [ ] CPU
- [x] GPU
Interface:
- [ ] C++
- [x] Python
As the error says, GpuIndexIVFScalarQuantizer does not support the sa_codec interface.
NB that scalar quantizer encoding is very cheap, so there is no need to use a GPU to speed up encoding, unless the vectors to encode already reside on GPU. Is this your case?
Thanks for the response. Yes, both are issues: (1) data is on the GPU, and (2) the amount of data is a lot (~200M vectors). So encoding them on CPU was slow.