forked from lancedb/lance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: use faster kmean find partition routing for pq assignment (lanc…
…edb#2515) * Added benchmark for pq assignment to use fast routing * Use compute_partition for fast kmeans find partition
- Loading branch information
Showing
5 changed files
with
77 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: Copyright The Lance Authors | ||
|
||
//! Benchmark of Building PQ code from Dense Vectors. | ||
use std::sync::Arc; | ||
|
||
use arrow_array::{types::Float32Type, FixedSizeListArray}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use lance_arrow::FixedSizeListArrayExt; | ||
use lance_index::vector::pq::{ProductQuantizer, ProductQuantizerImpl}; | ||
use lance_linalg::distance::DistanceType; | ||
use lance_testing::datagen::generate_random_array_with_seed; | ||
|
||
const PQ: usize = 96; | ||
const DIM: usize = 1536; | ||
const TOTAL: usize = 32 * 1024; | ||
|
||
fn pq_transform(c: &mut Criterion) { | ||
let codebook = Arc::new(generate_random_array_with_seed::<Float32Type>( | ||
256 * DIM, | ||
[88; 32], | ||
)); | ||
|
||
let vectors = generate_random_array_with_seed::<Float32Type>(DIM * TOTAL, [3; 32]); | ||
let fsl = FixedSizeListArray::try_new_from_values(vectors, DIM as i32).unwrap(); | ||
|
||
for dt in [DistanceType::L2, DistanceType::Dot].iter() { | ||
let pq = ProductQuantizerImpl::<Float32Type>::new(PQ, 8, DIM, codebook.clone(), *dt); | ||
|
||
c.bench_function(format!("{},{}", dt, TOTAL).as_str(), |b| { | ||
b.iter(|| { | ||
let _ = pq.transform(&fsl).unwrap(); | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!( | ||
name=benches; | ||
config = Criterion::default().significance_level(0.1).sample_size(10); | ||
targets = pq_transform); | ||
|
||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters