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

[Feature Request] Allow GPU for query embedding #19

Open
miikatoi opened this issue Jul 4, 2023 · 1 comment
Open

[Feature Request] Allow GPU for query embedding #19

miikatoi opened this issue Jul 4, 2023 · 1 comment

Comments

@miikatoi
Copy link

miikatoi commented Jul 4, 2023

Hi,

Really great and useful library. Thanks for making it available for everyone.

I am mostly applying this for quick evaluation of search models and realized that DenseRetriever is only applying GPU for the documents when building the index, but not for the queries when running search, which makes it a bit slow for larger sets of queries.

Would you consider adding use_gpu keyword argument to search, msearch and bsearch methods of DenseRetriever and HybridRetriever? Looks like it could be handled similarly as in the index method.

Just in case someone else is having the same issue, this problem can be avoided by directly setting the encoder device before running search as follows:

use_gpu = True

dr = dr.index(collection, use_gpu=use_gpu)

if use_gpu:
    dr.encoder.change_device('cuda')

r = dr.bsearch(queries=queries)
dr.encoder.change_device('cpu')

Thanks!

@AmenRa
Copy link
Owner

AmenRa commented Jul 7, 2023

Hi, thanks for the kind words!

I did not expose an option for using GPU at query time because autofaiss did not detect my GPU correctly. I think it would be inconsistent to have the query encoding on the GPU and the neighbor search on the CPU.

By changing the device of the encoder, you are only changing where the queries are encoded but not where the nearest neighbor search happens.

I want to make an overall of the dense retriever and closely look into the issue with autofaiss I had.
Unfortunately, I have been quite busy (or on vacation) lately. I hope to have the time to work on it soon.

Best,

Elias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants