Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling for indexes not supported on GPU? #3269

Closed
mlomeli1 opened this issue Feb 28, 2024 · 3 comments
Closed

Error handling for indexes not supported on GPU? #3269

mlomeli1 opened this issue Feb 28, 2024 · 3 comments
Assignees

Comments

@mlomeli1
Copy link
Contributor

mlomeli1 commented Feb 28, 2024

Summary

Currently, the indexes that are supported in GPU are clearly listed in the wiki: https://github.com/facebookresearch/faiss/wiki/Faiss-on-the-GPU#implemented-indexes, however, it would be great if we could throw an error when the user attempts to move an unsupported GPU index instead of failing silently and running in the CPU.

Platform

Faiss version: faiss-gpu 1.7.4

Installed from: conda

Running on:

  • GPU

Interface:

  • Python

Reproduction instructions

I have created an IndexPQ, attempted to move it to the GPU and conducted search. This results in the knn search taking a long time 236.77 seconds plus nvidia-smi pmon showcases we indeed never use the GPU:

# gpu         pid  type    sm    mem    enc    dec    command
# Idx           #   C/G     %      %      %      %    name
    0    2711586     C     0     0     -     -   python3.10
    1          -     -     -     -     -     -   -
    0    2711586     C     0     0     -     -   python3.10
    1          -     -     -     -     -     -   -
    0    2711586     C     0     0     -     -   python3.10
import faiss
import numpy as np
import time

dimension = 128                          
n = 1000000                
db_vectors = np.random.random((n, dimension)).astype('float32') 
k = 3 
dimension=128
query_vectors = np.random.random((n, dimension)).astype('float32')
code_size=16
res = faiss.StandardGpuResources()
start = time.time()
#define the pq index in cpu
index_pq = faiss.IndexPQ(dimension, code_size, 8) 
index_pq.train(db_vectors)  
index_pq.add(db_vectors)  
gpu_index_pq = faiss.index_cpu_to_gpu(res, 0, index_pq)
distances_pq, indices_pq = gpu_index_pq.search(query_vectors, k)
end = time.time()
total_time = end - start
print("\n"+ str(total_time))

In contrast, with an IVFPQ (which is GPU supported) the run time is 3.48 seconds utilising the same number of vectors and we use the GPU according to nvidia-smi pmon as expected.

gpu         pid  type    sm    mem    enc    dec    command
# Idx           #   C/G     %      %      %      %    name
    0    2711586     C     0     0     -     -   python3.10
    1          -     -     -     -     -     -   -
    0    2711586     C     0     0     -     -   python3.10
    1          -     -     -     -     -     -   -
    0    2711586     C     0     0     -     -   python3.10
    1          -     -     -     -     -     -   -
    0    2711586     C    25     6     -     -   python3.10
    1          -     -     -     -     -     -   -
    0    2711586     C    10     3     -     -   python3.10
dimension = 128                          
n = 1000000                
db_vectors = np.random.random((n, dimension)).astype('float32') 
k = 3 
dimension=128
query_vectors = np.random.random((n, dimension)).astype('float32')
code_size=16
nlist=math.floor(math.sqrt(n))
res = faiss.StandardGpuResources()
#define the ivfpq index in cpu
start = time.time()
quantizer = faiss.IndexFlatL2(dimension)  # coarse quantizer
#define the inverted index 
index_ivfpq = faiss.IndexIVFPQ(quantizer, dimension, nlist, code_size, 8)
index_ivfpq.train(db_vectors) 
index_ivfpq.add(db_vectors) 
gpu_index_ivfpq = faiss.index_cpu_to_gpu(res, 0, index_ivfpq)
distances_ivfpq, indices_ivfpq = gpu_index_ivfpq.search(query_vectors, k)
end = time.time()
total_time = end - start
print("\n"+ str(total_time))
@mdouze
Copy link
Contributor

mdouze commented Mar 1, 2024

+1

@mdouze
Copy link
Contributor

mdouze commented Mar 20, 2024

The issue here is that wrapped indexes (like IDMap and Pretransform) should be cloned on CPU, that's normal but indexes that contain actual data should be moved to GPU (and the cloning function should throw if this is not the case).

facebook-github-bot pushed a commit that referenced this issue Apr 4, 2024
facebook-github-bot pushed a commit that referenced this issue Apr 4, 2024
ramilbakhshyiev added a commit that referenced this issue Apr 4, 2024
@ramilbakhshyiev ramilbakhshyiev self-assigned this Apr 4, 2024
facebook-github-bot pushed a commit that referenced this issue Apr 6, 2024
…3336)

Summary:
Pull Request resolved: #3336

Issues:
#3269
#3024

List of implemented GPU indices: https://github.com/facebookresearch/faiss/wiki/Faiss-on-the-GPU#implemented-indexes

Reviewed By: mdouze

Differential Revision: D55577576

fbshipit-source-id: 49f490cfba6784661e378acf4de3cce4195bb43b
@ramilbakhshyiev
Copy link
Contributor

Fixed in #3336

abhinavdangeti pushed a commit to blevesearch/faiss that referenced this issue Jul 12, 2024
…acebookresearch#3336)

Summary:
Pull Request resolved: facebookresearch#3336

Issues:
facebookresearch#3269
facebookresearch#3024

List of implemented GPU indices: https://github.com/facebookresearch/faiss/wiki/Faiss-on-the-GPU#implemented-indexes

Reviewed By: mdouze

Differential Revision: D55577576

fbshipit-source-id: 49f490cfba6784661e378acf4de3cce4195bb43b
aalekhpatel07 pushed a commit to aalekhpatel07/faiss that referenced this issue Oct 17, 2024
…acebookresearch#3336)

Summary:
Pull Request resolved: facebookresearch#3336

Issues:
facebookresearch#3269
facebookresearch#3024

List of implemented GPU indices: https://github.com/facebookresearch/faiss/wiki/Faiss-on-the-GPU#implemented-indexes

Reviewed By: mdouze

Differential Revision: D55577576

fbshipit-source-id: 49f490cfba6784661e378acf4de3cce4195bb43b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants