-
Notifications
You must be signed in to change notification settings - Fork 417
Significantly speed up bitmap computation #1099
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
Open
magdalendobson
wants to merge
30
commits into
main
Choose a base branch
from
users/magdalen/add_filter_utils
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
0a9980f
add specificity utility
e99177a
refactor example, add compute_bitmap
ce447a3
commit to switch
e039051
work out kinks in OrderedFloat
8b47aef
undo change in docstring
962fdf6
Potential fix for pull request finding
magdalendobson 07cb5bd
Potential fix for pull request finding
magdalendobson 80574ca
fix label-filter accelerator doc id mapping for inverted index
Copilot ecc3895
fix: use document ids for numeric btree accelerator postings
Copilot 4fe2935
fix: guard compute_specificities against empty base labels
Copilot 2161a1d
Avoid cloning/silencing errors in query accelerator build
Copilot 164f4b9
change format
cce1a8a
fmt
8c20dc9
Merge branch 'main' of github.com:microsoft/DiskANN into users/magdal…
8f22beb
Revert "Avoid cloning/silencing errors in query accelerator build"
f09f9b8
Revert "fmt"
1696ee3
Reapply "Avoid cloning/silencing errors in query accelerator build"
d631aae
small changes
38688be
Revert "small changes"
9dcca30
fmt
7553b99
fix clippy, fmt
9676dac
update groundtruth calculation to use fast bitmap computation
17d069e
reduce repeated code, reduce instances of pub
287d438
remove roaring
43aefb3
remove crate
50f274b
Revert "remove crate"
1f774bb
remove crate
07b2d2b
move to diskann-tools
0713244
remove from toml file
c205a87
add check that i64 -> f64 conversion is lossless
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,105 @@ | ||
| /* | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT license. | ||
| */ | ||
|
|
||
| use diskann_label_filter::{read_and_parse_queries, read_baselabels}; | ||
| use diskann_tools::utils::compute_bitmap::compute_query_bitmaps; | ||
| use std::env; | ||
| use std::fs::File; | ||
| use std::io::Write; | ||
| use std::process; | ||
|
|
||
| fn main() { | ||
| let args: Vec<String> = env::args().collect(); | ||
| if args.len() != 3 && args.len() != 4 { | ||
| eprintln!( | ||
| "Usage: {} <base_label_file> <query_label_file> [specificity_output_file]", | ||
| args[0] | ||
| ); | ||
| process::exit(1); | ||
| } | ||
| let base_label_file = &args[1]; | ||
| let query_label_file = &args[2]; | ||
| let output_file = if args.len() == 4 { | ||
| Some(&args[3]) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| let base_labels = match read_baselabels(base_label_file) { | ||
| Ok(labels) => labels, | ||
| Err(e) => { | ||
| eprintln!("Error reading base labels: {}", e); | ||
| process::exit(1); | ||
| } | ||
| }; | ||
|
|
||
| let total_base = base_labels.len() as u64; | ||
| if total_base == 0 { | ||
| eprintln!("Base labels are empty: cannot compute specificities."); | ||
| process::exit(1); | ||
| } | ||
|
|
||
| let query_labels = match read_and_parse_queries(query_label_file) { | ||
| Ok(queries) => queries, | ||
| Err(e) => { | ||
| eprintln!("Error reading query labels: {}", e); | ||
| process::exit(1); | ||
| } | ||
| }; | ||
|
|
||
| let start = std::time::Instant::now(); | ||
| let bitmaps = match compute_query_bitmaps(base_labels, query_labels) { | ||
| Ok(b) => b, | ||
| Err(e) => { | ||
| eprintln!("Error computing bitmaps: {}", e); | ||
| process::exit(1); | ||
| } | ||
| }; | ||
| let elapsed = start.elapsed(); | ||
| println!("Computing bitmap took {:.3?} seconds", elapsed); | ||
|
|
||
| let mut specificities: Vec<f64> = bitmaps | ||
| .iter() | ||
| .map(|bitmap| { | ||
| let count = bitmap.len(); | ||
| count as f64 / total_base as f64 | ||
| }) | ||
| .collect(); | ||
|
magdalendobson marked this conversation as resolved.
|
||
|
|
||
| if let Some(path) = output_file { | ||
| let mut file = match File::create(path) { | ||
| Ok(f) => f, | ||
| Err(e) => { | ||
| eprintln!("Failed to create output file {}: {}", path, e); | ||
| process::exit(1); | ||
| } | ||
| }; | ||
| for spec in &specificities { | ||
| if let Err(e) = writeln!(file, "{:.6}", spec) { | ||
| eprintln!("Failed to write to output file: {}", e); | ||
| process::exit(1); | ||
| } | ||
| } | ||
| println!("Specificities written to {}", path); | ||
| } | ||
|
|
||
| if !specificities.is_empty() { | ||
| specificities.sort_by(|a, b| a.partial_cmp(b).unwrap()); | ||
| let min = specificities[0]; | ||
| let max = specificities[specificities.len() - 1]; | ||
| let median = if specificities.len().is_multiple_of(2) { | ||
| let mid = specificities.len() / 2; | ||
| (specificities[mid - 1] + specificities[mid]) / 2.0 | ||
| } else { | ||
| specificities[specificities.len() / 2] | ||
| }; | ||
| let avg = specificities.iter().sum::<f64>() / specificities.len() as f64; | ||
| println!("\nSpecificity stats:"); | ||
| println!(" average: {:.6}", avg); | ||
| println!(" median: {:.6}", median); | ||
| println!(" min: {:.6}", min); | ||
| println!(" max: {:.6}", max); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer input intake with argparse. This is error prone.