Skip to content
New issue

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

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

Already on GitHub? # to your account

IndexResidualQuantizer doesn't work when it is move to GPU #3024

Closed
2 of 4 tasks
HansiZeng opened this issue Aug 23, 2023 · 2 comments
Closed
2 of 4 tasks

IndexResidualQuantizer doesn't work when it is move to GPU #3024

HansiZeng opened this issue Aug 23, 2023 · 2 comments
Assignees

Comments

@HansiZeng
Copy link

HansiZeng commented Aug 23, 2023

Summary

I would like to use ResidualQuantizer for ANN search.

Platform

OS: GNU/Linux

Faiss version: 1.7.2

Installed from: conda

Faiss compilation options:

Running on:

  • CPU
  • GPU

Interface:

  • C++
  • Python

Reproduction instructions

import faiss 
import torch 
import numpy as np

N = 10_000
M = 16

res = faiss.StandardGpuResources()
res.setTempMemory(1024*1024*512)
co = faiss.GpuClonerOptions()
co.useFloat16 = False 

corpus_embeds = np.random.random((N, 768)).astype('float32')
corpus_embeds[:, 0] += np.arange(N) / 1000.
text_ids = np.arange(N)

faiss.omp_set_num_threads(32)
index = faiss.IndexResidualQuantizer(768, M, 8, faiss.METRIC_INNER_PRODUCT)

index.verbose = True
index = faiss.index_cpu_to_gpu(res, 0, index, co)    
index.train(corpus_embeds)
index.add(corpus_embeds)
index = faiss.index_gpu_to_cpu(index)

rq = index.rq

for i in range(0, N, 8):
    batch_ids = text_ids[i:i+8]
    batch_embeds = corpus_embeds[i:i+8]

    nn_scores, nn_ids = index.search(batch_embeds, 10)
    codes = rq.compute_codes(batch_embeds)

    for query_id, docids in zip(batch_ids, nn_ids):
        print("query_id: ", query_id, "docids: ", docids)
    print(nn_scores)
    #print(codes.shape, codes, codes.dtype)
    break

The error:

pure virtual method called                                                                                                                                                │·····
terminate called without an active exception                                                                                                                              │·····
Aborted

When I comment the lines index = faiss.index_cpu_to_gpu(res, 0, index, co) and index = faiss.index_gpu_to_cpu(index), it works fine.

@mdouze
Copy link
Contributor

mdouze commented Aug 28, 2023

IndexResidualQuantizer is not supported on GPU.
However, it is true that the error message could be clearer. There is probably a bug in the cloning method. Marking as enhancement.

@mdouze mdouze added the GPU label Aug 28, 2023
@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
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants