faiss/benchs/bench_fw_optimize.py
Kumar Saurabh Arora da75d03442 Refactor bench_fw to support train, build & search in parallel (#3527)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3527

**Context**
Design Doc: [Faiss Benchmarking](https://docs.google.com/document/d/1c7zziITa4RD6jZsbG9_yOgyRjWdyueldSPH6QdZzL98/edit)

**In this diff**
1. Be able to reference codec and index from blobstore (bucket & path) outside the experiment
2. To support #1, naming is moved to descriptors.
3. Build index can be written as well.
4. You can run benchmark with train and then refer it in index built and then refer index built in knn search. Index serialization is optional. Although not yet exposed through index descriptor.
5. Benchmark can support index with different datasets sizes
6. Working with varying dataset now support multiple ground truth. There may be small fixes before we could use this.
7. Added targets for bench_fw_range, ivf, codecs and optimize.

**Analysis of ivf result**: D58823037

Reviewed By: algoriddle

Differential Revision: D57236543

fbshipit-source-id: ad03b28bae937a35f8c20f12e0a5b0a27c34ff3b
2024-06-21 13:04:09 -07:00

59 lines
1.6 KiB
Python

# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import logging
import os
from faiss.benchs.bench_fw.benchmark_io import BenchmarkIO
from faiss.benchs.bench_fw.descriptors import DatasetDescriptor
from faiss.benchs.bench_fw.optimize import Optimizer
logging.basicConfig(level=logging.INFO)
def bigann(bio):
optimizer = Optimizer(
distance_metric="L2",
num_threads=32,
run_local=False,
)
optimizer.set_io(bio)
query_vectors = DatasetDescriptor(namespace="std_q", tablename="bigann1M")
xt = bio.get_dataset(query_vectors)
optimizer.optimize(
d=xt.shape[1],
training_vectors=DatasetDescriptor(
namespace="std_t",
tablename="bigann1M",
num_vectors=2_000_000,
),
database_vectors_list=[
DatasetDescriptor(
namespace="std_d",
tablename="bigann1M",
),
DatasetDescriptor(namespace="std_d", tablename="bigann10M"),
],
query_vectors=query_vectors,
min_accuracy=0.85,
)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("experiment")
parser.add_argument("path")
args = parser.parse_args()
assert os.path.exists(args.path)
path = os.path.join(args.path, args.experiment)
if not os.path.exists(path):
os.mkdir(path)
bio = BenchmarkIO(
path=path,
)
if args.experiment == "bigann":
bigann(bio)