pytorch-metric-learning icon indicating copy to clipboard operation
pytorch-metric-learning copied to clipboard

faiss search

Open wangyijun91 opened this issue 2 years ago • 1 comments

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)

wangyijun91 avatar Jun 18 '22 01:06 wangyijun91

When the faiss index is on multiple GPUs, then the inputs have to be on CPU (see https://github.com/facebookresearch/faiss/issues/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.

KevinMusgrave avatar Jun 18 '22 10:06 KevinMusgrave