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

Updating the arguments passed to search_preassigned and add_core faiss Python APIs #298

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions benchmark/algorithms/faiss_t3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import resource
import threading
import json

from multiprocessing.pool import ThreadPool

from benchmark.algorithms.base import BaseANN
Expand Down Expand Up @@ -187,6 +186,7 @@ def produce_batches(sno):
print(" adding %d:%d / %d [%.3f s, RSS %d kiB] " % (
i0, i1, ds.nb, time.time() - t0,
faiss.get_mem_usage_kb()))
xblock = xblock.astype('f4')
index.add_core(
len(xblock),
faiss.swig_ptr(xblock),
Expand Down Expand Up @@ -250,13 +250,7 @@ def search(self, x, k):
t0 = time.time()
for i0, xblock, Dc, Ic in stage2:
ni = len(xblock)
self.index_ivf.search_preassigned(
ni, faiss.swig_ptr(xblock),
k, sp(Ic), sp(Dc),
sp(D[i0:]), sp(I[i0:]),
False
)

D[i0:i0+ni], I[i0:i0+ni] = self.index_ivf.search_preassigned(xblock, k, Ic, Dc)
return D, I

def range_search(self, x, radius):
Expand Down
16 changes: 7 additions & 9 deletions neurips21/track3_baseline_faiss/gpu_baseline_faiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def build_index(args, ds):
train_index = faiss.index_cpu_to_all_gpus(
faiss.IndexFlatL2(index_ivf.d))
index_ivf.clustering_index = train_index

index.train(xt2)
print(" Total train time %.3f s" % (time.time() - t0))

Expand Down Expand Up @@ -190,6 +189,9 @@ def produce_batches(sno):
print(" adding %d:%d / %d [%.3f s, RSS %d kiB] " % (
i0, i1, ds.nb, time.time() - t0,
faiss.get_mem_usage_kb()))

xblock = xblock.astype('f4')

index.add_core(
len(xblock),
faiss.swig_ptr(xblock),
Expand Down Expand Up @@ -236,7 +238,7 @@ def eval_setting_knn(index, xq, gt, k, inter, min_time):
ms_per_query = ((t1 - t0) * 1000.0 / nq / nrun)
if inter:
rank = k
inter_measure = compute_inter(gt[:, :rank], I[:, :rank])
inter_measure = compute_inter(gt_I[:, :rank], I[:, :rank])
print("%.4f" % inter_measure, end=' ')
else:
for rank in 1, 10, 100:
Expand Down Expand Up @@ -316,12 +318,7 @@ def search(self, x, k):
t0 = time.time()
for i0, xblock, Dc, Ic in stage2:
ni = len(xblock)
self.index_ivf.search_preassigned(
ni, faiss.swig_ptr(xblock),
k, sp(Ic), sp(Dc),
sp(D[i0:]), sp(I[i0:]),
False
)
D[i0:i0+ni], I[i0:i0+ni] = self.index_ivf.search_preassigned(xblock, k, Ic, Dc)

return D, I

Expand Down Expand Up @@ -513,6 +510,7 @@ def aa(*args, **kwargs):
nq, d = ds.nq, ds.d
nb, d = ds.nq, ds.d


if args.prepare:
print("downloading dataset...")
ds.prepare()
Expand Down Expand Up @@ -571,4 +569,4 @@ def aa(*args, **kwargs):
run_experiments_searchparams(ds, index, args)

if __name__ == "__main__":
main()
main()
Loading