Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9fd71ef
add CAGRA ANN to replace brute force kmeans for prediction + test cas…
HowardHuang1 Mar 18, 2026
80070c4
fix test cases + fix threshold
HowardHuang1 Mar 18, 2026
fa6fd70
add test cases for entire IVF-PQ pipeline
HowardHuang1 Mar 18, 2026
d8543a6
rename variable to use_ann_for_extend since previous changes are only…
HowardHuang1 Mar 19, 2026
d26e916
Replace brute force with CAGRA ANN in build()
HowardHuang1 Mar 20, 2026
ad054af
add test cases
HowardHuang1 Mar 24, 2026
0f14da1
Merge remote-tracking branch 'upstream' into HH-ANNs-for-clustering-a…
HowardHuang1 Jun 25, 2026
e69259f
rename use_cagra and use_ann variables to use_cagra_for_cluster_assig…
HowardHuang1 Jun 25, 2026
1d76516
fix null list or empty trained indices error for IVF-PQ serialize cau…
HowardHuang1 Jun 25, 2026
8e62682
rename benchmark names so that Build_NearestCentroidLookup_Speedup mi…
HowardHuang1 Jun 25, 2026
167f0c4
refactor out common code shared by BM_IVFPQ_Build_NearestCentroidLook…
HowardHuang1 Jun 26, 2026
64586ad
add ann for cluster assignment to postfit. Added use_ann_for_build_po…
HowardHuang1 Jun 26, 2026
de80d26
Merge remote-tracking branch 'upstream' into HH-ANNs-for-clustering-a…
HowardHuang1 Jun 27, 2026
7daf9cb
add tuning script for ann_rebuild_interval balancing recall and speedup
HowardHuang1 Jun 27, 2026
76ebb73
Merge remote-tracking branch 'upstream' into HH-ANNs-for-clustering-a…
HowardHuang1 Jun 27, 2026
525cd4c
Merge remote-tracking branch 'upstream/main' into HH-ANNs-for-cluster…
HowardHuang1 Sep 5, 2026
1673e39
fix merge conflict with build now taking only dataset views and not d…
HowardHuang1 Sep 7, 2026
3951248
Replace hand-picked cluster-assignment bench args with controlled K s…
HowardHuang1 Sep 7, 2026
1daabbe
Add controlled fixed-K/vary-N, grid, search-only, dim, and rebuild-in…
HowardHuang1 Sep 8, 2026
52ddd3d
Merge remote-tracking branch 'upstream/main' into HH-ANNs-for-cluster…
HowardHuang1 Oct 27, 2026
3de0823
Fix benchmark plots and make fit-tuning quality metrics meaningful
HowardHuang1 Oct 28, 2026
73825bd
Read benchmark datasets from .fbin files and redesign plot panel 4
HowardHuang1 Nov 3, 2026
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
Prev Previous commit
Read benchmark datasets from .fbin files and redesign plot panel 4
The cluster-assignment and fit-tuning benchmarks used uniform random data, which has no
cluster structure, and the assignment benchmark used independent random vectors as centroids.
Both now read every dataset, real or synthetic, from a big-ann style .fbin file, so there is
one code path. Centroids are always trained from the dataset rather than drawn at random.

Dataset input (cpp/bench/ann/src/cuvs/bench_dataset.hpp, new)
  CUVS_BENCH_DATA_FBIN names the dataset and CUVS_BENCH_CENTROIDS_FBIN the trained centroids.
  - data_path, centroids_path: the two environment variables.
  - read_header: row count and dim from the 8-byte .fbin header.
  - read_first_rows: first N rows to the host, checking row count and dim.
  - load_data: copies the first N points to the GPU. Used by both benchmarks.
  - load_centroids: copies K centroids, taken at an even stride, to the GPU. Used by the
    assignment benchmark, so a smaller K still spans the whole centroid set.
  - write_fbin: writes trained centroids. Used by centroid training.

cuvs_cluster_assignment_bench.cu (panels 1-6, 8)
  - Removed the uniform-random data and random-centroid paths.
  - load_benchmark_data: loads the points and centroids for each benchmark.
  - size_is_supported, g_dim, g_n_rows, g_n_centroids, kMaxDataBytes: every sweep skips
    (N, K, dim) combinations the files cannot serve or that do not fit on the GPU.
  - configure_dataset_from_env: reads both headers in main and fails with instructions if
    either file is missing.
  - train_centroids_from_env: with CUVS_BENCH_TRAIN_CENTROIDS_OUT set, trains K centroids
    (CUVS_BENCH_TRAIN_K, default 300K) on the first CUVS_BENCH_TRAIN_N rows (default 5M)
    using brute-force balanced k-means, so the centroids are not biased by the ANN path being
    measured, then writes them as .fbin and exits.
  - The dimension sweep (panel 8) only runs for the dataset's own dim.

cuvs_fit_ann_rebuild_tuning_bench.cu (panel 7)
  - Loads points with load_data instead of generating random ones.
  - register_all replaces the BENCHMARK macros so dim can come from the file. It requires
    CUVS_BENCH_DATA_FBIN and skips sizes the file cannot serve.
  - New counter ann_1nn_agreement_pct_itopk32 next to 64 and 256; 32 is CAGRA's minimum.

scripts/generate_clustered_dataset.py (new)
  Writes a synthetic .fbin from a Gaussian mixture with uneven component weights and spreads,
  for use when no real dataset is available.

scripts/plot_all_cluster_assignment_benchmarks.py
  - Panel 4: replaced the (N, K) heatmap with panel4_speedup_by_n, a line chart of
    speedup (brute-force time / CAGRA time) against K with one line per N, a 1x break-even
    line and shaded "CAGRA faster" / "brute force faster" regions. Lines for different N
    show how much N matters at each K.
  - --dim argument replaces the hard-coded 128 in panels 1-6.
  - Panel 8 prints a placeholder when the data has a single dim.
  - Panel 7: shows the itopk_size 32 agreement; both y axes now contain 1.0 at the same
    height so one dashed line means "same as brute force" for quality and speed; the
    distance-ratio axis spans at least +/-5% so run-to-run noise is not stretched to fill
    the plot, and every point stays inside the axes.
  • Loading branch information
HowardHuang1 committed Nov 3, 2026
commit 73825bd3c50b7f43dbb92f42998dc9265b068bdd
87 changes: 87 additions & 0 deletions cpp/bench/ann/scripts/generate_clustered_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Generate a synthetic clustered dataset as a big-ann style .fbin file.

The cluster-assignment and fit-tuning benchmarks read every dataset, synthetic or real, from an
.fbin file (uint32 n_rows, uint32 dim, then row-major float32). Use this script when no real
dataset is at hand: it draws points from a Gaussian mixture, so unlike uniform random data the
points form clusters of uneven size and spread, which is closer to real embeddings.

Each point is its component's center plus Gaussian noise:
- centers are drawn from N(0, I)
- component weights are log-normal, so cluster sizes are uneven
- each component has its own noise std, drawn uniformly from [--min-std, --max-std]

Usage:
python generate_clustered_dataset.py --n-rows 10000000 --dim 128 --out synthetic_10M_128.fbin
"""

import argparse
import struct

import numpy as np

CHUNK_ROWS = 1 << 20


def generate(
out_path: str,
n_rows: int,
dim: int,
n_components: int,
min_std: float,
max_std: float,
seed: int,
) -> None:
rng = np.random.default_rng(seed)
centers = rng.standard_normal((n_components, dim), dtype=np.float32)
stds = rng.uniform(min_std, max_std, n_components).astype(np.float32)
weights = rng.lognormal(mean=0.0, sigma=1.0, size=n_components)
weights /= weights.sum()

with open(out_path, "wb") as f:
f.write(struct.pack("<II", n_rows, dim))
for first in range(0, n_rows, CHUNK_ROWS):
count = min(CHUNK_ROWS, n_rows - first)
comp = rng.choice(n_components, size=count, p=weights)
noise = rng.standard_normal((count, dim), dtype=np.float32)
points = centers[comp] + noise * stds[comp, None]
f.write(np.ascontiguousarray(points, dtype=np.float32).tobytes())
print(
f"wrote {n_rows:,} x {dim} points from {n_components} components "
f"-> {out_path}"
)


def main() -> None:
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument("--out", required=True, help="output .fbin path")
parser.add_argument("--n-rows", type=int, required=True)
parser.add_argument("--dim", type=int, required=True)
parser.add_argument(
"--n-components",
type=int,
default=2000,
help="number of mixture components (true clusters in the data)",
)
parser.add_argument("--min-std", type=float, default=0.2)
parser.add_argument("--max-std", type=float, default=0.6)
parser.add_argument("--seed", type=int, default=12345)
args = parser.parse_args()
generate(
args.out,
args.n_rows,
args.dim,
args.n_components,
args.min_std,
args.max_std,
args.seed,
)


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