Files
faiss/benchs/bench_fw_ivf.py
T
Tia Lim 0f0f728166 Format faiss Python files with black (line length 80) (#5349)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5349

# this is a no-op change

Ran `black -l 80` over all tracked Python files under `fbcode/faiss/`, using line length 80 to match faiss's documented coding style (`CONTRIBUTING.md`: "80 character line length (both for C++ and Python)"). 172 files were reformatted; 28 were already compliant.

This is a pure-formatting change. `black` runs its AST-equivalence safety check on every file, so no identifiers, string/numeric values, operators, or control flow were altered — only whitespace, indentation, line wrapping, blank lines, trailing commas, and string-quote normalization (single to double quotes).

`fbcode/faiss/` is intentionally excluded from Meta's standard Python autoformatter (`arc f` / `arc lint -a` report no formatter for these paths) because it mirrors to public GitHub, so the Python had drifted out of any consistent style. The C++ is already clang-format-clean (0 of 807 files change), so this effort is Python-only. This diff brings the Python to canonical `black` formatting.

Excluded `demos/index_pq_flat_separate_codes_from_codebook.py`: it contains a Jupyter `!rm` shell-magic line and is not valid Python, so `black` cannot parse it.

This is the base of a 3-diff stack: (1) this black reformat; (2) `.flake8` alignment (max-line-length 80 + black-compatible ignores E203/W503); (3) genuine lint fixes (F401/F403/F841/B011).

Reviewed By: mnorris11

Differential Revision: D109736099

fbshipit-source-id: 9a054635766ed11aa3760a788395babd3d198abf
2026-06-29 17:29:05 -07:00

151 lines
4.1 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 import Benchmark
from faiss.benchs.bench_fw.benchmark_io import BenchmarkIO
from faiss.benchs.bench_fw.descriptors import (
DatasetDescriptor,
IndexDescriptorClassic,
)
logging.basicConfig(level=logging.INFO)
def sift1M(bio):
benchmark = Benchmark(
num_threads=32,
training_vectors=DatasetDescriptor(
namespace="std_d", tablename="sift1M"
),
database_vectors=DatasetDescriptor(
namespace="std_d", tablename="sift1M"
),
query_vectors=DatasetDescriptor(namespace="std_q", tablename="sift1M"),
index_descs=[
IndexDescriptorClassic(
factory=f"IVF{2 ** nlist},Flat",
)
for nlist in range(8, 15)
],
k=1,
distance_metric="L2",
)
benchmark.io = bio
benchmark.benchmark(
result_file="result.json",
local=True,
train=True,
reconstruct=False,
knn=True,
range=False,
)
def bigann(bio):
for scale in [1, 2, 5, 10, 20, 50]:
benchmark = Benchmark(
num_threads=32,
training_vectors=DatasetDescriptor(
namespace="std_t", tablename="bigann1M"
),
database_vectors=DatasetDescriptor(
namespace="std_d", tablename=f"bigann{scale}M"
),
query_vectors=DatasetDescriptor(
namespace="std_q", tablename="bigann1M"
),
index_descs=[
IndexDescriptorClassic(
factory=f"IVF{2 ** nlist},Flat",
)
for nlist in range(11, 19)
]
+ [
IndexDescriptorClassic(
factory=f"IVF{2 ** nlist}_HNSW32,Flat",
construction_params=[
None,
{"efConstruction": 200, "efSearch": 40},
],
)
for nlist in range(11, 19)
],
k=1,
distance_metric="L2",
)
benchmark.set_io(bio)
benchmark.benchmark(
f"result{scale}.json",
local=False,
train=True,
reconstruct=False,
knn=True,
range=False,
)
def ssnpp(bio):
benchmark = Benchmark(
num_threads=32,
training_vectors=DatasetDescriptor(tablename="ssnpp_training_5M.npy"),
database_vectors=DatasetDescriptor(tablename="ssnpp_database_5M.npy"),
query_vectors=DatasetDescriptor(tablename="ssnpp_queries_10K.npy"),
index_descs=[
IndexDescriptorClassic(
factory=f"IVF{2 ** nlist},PQ256x4fs,Refine(SQfp16)",
)
for nlist in range(9, 16)
]
+ [
IndexDescriptorClassic(
factory=f"IVF{2 ** nlist},Flat",
)
for nlist in range(9, 16)
]
+ [
IndexDescriptorClassic(
factory=f"PQ256x4fs,Refine(SQfp16)",
),
IndexDescriptorClassic(
factory=f"HNSW32",
),
],
k=1,
distance_metric="L2",
)
benchmark.set_io(bio)
benchmark.benchmark(
"result.json",
local=False,
train=True,
reconstruct=False,
knn=True,
range=False,
)
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 == "sift1M":
sift1M(bio)
elif args.experiment == "bigann":
bigann(bio)
elif args.experiment == "ssnpp":
ssnpp(bio)