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

faiss search #491

Open
wangyijun91 opened this issue Jun 18, 2022 · 1 comment · May be fixed by #643
Open

faiss search #491

wangyijun91 opened this issue Jun 18, 2022 · 1 comment · May be fixed by #643
Labels
enhancement New feature or request
Milestone

Comments

@wangyijun91
Copy link

pytorch_metric_learning.utils.inference

in function try_gpu(line258), weather gpu_index or cpu_index, both call function add_to_index_and_search, but this function only use cpu for faiss search

def add_to_index_and_search(index, query, reference, k):
if reference is not None:
index.add(reference.float().cpu())
return index.search(query.float().cpu(), k)

@KevinMusgrave KevinMusgrave added the enhancement New feature or request label Jun 18, 2022
@KevinMusgrave
Copy link
Owner

KevinMusgrave commented Jun 18, 2022

When the faiss index is on multiple GPUs, then the inputs have to be on CPU (see facebookresearch/faiss#1997). Inside the function, faiss moves the tensors back to the GPU.

When the index is on a single GPU, then the input tensor can also be on GPU.

Maybe I can add some code to move the tensor to CPU only if the index is on multiple GPUs.

domenicoMuscill0 pushed a commit to domenicoMuscill0/pytorch-metric-learning that referenced this issue Jun 21, 2023
@KevinMusgrave KevinMusgrave added this to the v3.0 milestone Jul 3, 2023
@KevinMusgrave KevinMusgrave linked a pull request Jul 3, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants