Optimize RaBitQ fastscan query setup + 80% qps#5396
Open
lyang24 wants to merge 1 commit into
Open
Conversation
This was referenced Jul 10, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Two hot-path fixes for RaBitQ FastScan search, from profiling Cohere 1M (d=1024, nprobe=64):
LUT/query quantization:
compute_LUT_uint8andcompute_query_factorscallstd::roundfper element (~330k libm calls per query, 16.9% of cycles in__roundf+PLT alone — half-away-from-zero rounding has no x86 instruction, so itnever inlines). Replaced with an inline
x + 0.5f+ truncate helper, valid sincethese inputs are non-negative and range-bounded by construction. (recall impact was small enough to be unnoticed)
Single-query pretransform:
LinearTransform::apply_noallocalways callssgemm,so for n=1 OpenBLAS repacks the whole rotation matrix every query
(
sgemm_incopywas 12.2% of cycles vs 2.7% for the actual kernel). Added ansgemvpath for n=1.Note: rounding is not bit-exact with
roundffor inputs within 1-2 ulp of ak + 0.5boundary (±1 quantization code); ties agree. gemv also differs from gemmin accumulation order. Neither affects recall (below), 4/10000 result ids changed.
Results
Cohere 1M, IVF_RABITQ_FASTSCAN, k=100, nprobe=64, single thread:
Recall vs exact ground truth (recomputed by brute force; the HDF5-provided
neighbors are invalid for IP/COSINE): recall@1/10/100 = 0.95 / 0.924 / 0.6554,
identical before and after.