Repository navigation
[DO NOT MERGE] IVF-Binary #2864
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
Closed
Closed
Changes from all commits
Commits
Show all changes
181 commits
Select commit
Hold shift + click to select a range
bedcf4c
first commit
tarang-jain 09f9a22
Merge branch 'branch-25.08' of https://github.com/rapidsai/cuvs into …
tarang-jain 51836d4
index header
tarang-jain 23ef877
populate functions;ivf_list type;kmeans_predict
tarang-jain a7fce8e
Merge branch 'branch-25.08' of https://github.com/rapidsai/cuvs into …
tarang-jain 6a98a88
hamming_op
tarang-jain 76c9ee5
Merge branch 'branch-25.08' into binary-kmeans
tarang-jain 916a4cf
rm binary_ivf
tarang-jain 8ec4d59
Merge branch 'binary-kmeans' of https://github.com/tarang-jain/cuvs i…
tarang-jain 1941b2e
modify ivf_flat_build
tarang-jain cd00b83
rm binary_ivf_flat
tarang-jain 4cffe84
rm unused
tarang-jain 2bc9007
updates
tarang-jain 7803850
quantize
tarang-jain ff7be4a
cleanup
tarang-jain 3149192
pre-commit
tarang-jain dd1b0d4
update kmeans_predict
tarang-jain 2b9bef4
src kmeans
tarang-jain 6ec32d8
style
tarang-jain 5c59753
corrections to logic
tarang-jain 2271809
clang
tarang-jain 29388e9
testing
tarang-jain 4a491cd
correct tests
tarang-jain 4c27acd
binary_index flag
tarang-jain 7085405
correct mdspan,reduction_op
tarang-jain 2075bd0
Merge branch 'branch-25.08' into binary-kmeans
tarang-jain d06b4f5
correct checks
tarang-jain 13de163
Merge branch 'branch-25.08' of https://github.com/rapidsai/cuvs into …
tarang-jain e79d520
Merge branch 'binary-kmeans' of https://github.com/tarang-jain/cuvs i…
tarang-jain c7f3ade
Merge branch 'branch-25.10' of https://github.com/rapidsai/cuvs into …
tarang-jain e7fdd4c
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain 3ce25af
fused-kernel
tarang-jain 1f565ef
Merge branch 'binary-kmeans' of https://github.com/tarang-jain/cuvs i…
tarang-jain 2c2a91d
cleeanup;syntax
tarang-jain b9a6a65
cleanup
tarang-jain 0f19648
temp-fix-compilation-errors
tarang-jain 2de4bcc
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain f572e0b
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain 66d8b94
uint32_t for storing dists
tarang-jain 46f9676
Merge branch 'branch-25.10' of https://github.com/rapidsai/cuvs into …
tarang-jain fa2193f
Merge branch 'binary-kmeans' of https://github.com/tarang-jain/cuvs i…
tarang-jain 8f18ce0
no use_norms check
tarang-jain c7084ac
coarse search
tarang-jain 1ca868b
debug; fix dim() error
tarang-jain 42859fb
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain f0597fa
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain ca97da6
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain 8ad530b
Merge branch 'branch-25.10' of https://github.com/rapidsai/cuvs into …
tarang-jain 17449e4
debug
tarang-jain f8e6e86
Merge branch 'branch-25.10' of https://github.com/rapidsai/cuvs into …
tarang-jain 6aa2401
fix float underflow
tarang-jain d1717f5
rm new file
tarang-jain 3b284cd
Merge branch 'branch-25.10' of https://github.com/rapidsai/cuvs into …
tarang-jain f34103d
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain 86a6593
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain ef37c59
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain 5e794fe
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain 359d458
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain d999591
Merge branch 'branch-25.10' into binary-kmeans
tarang-jain f242561
bug fixes
tarang-jain 5517ae3
Merge branch 'binary-kmeans' of https://github.com/tarang-jain/cuvs i…
tarang-jain 4aa2881
Merge branch 'branch-25.12' into binary-kmeans
tarang-jain b0d78b6
Merge branch 'branch-25.12' into binary-kmeans
tarang-jain 184f025
Merge branch 'branch-25.12' into binary-kmeans
tarang-jain 113e242
Merge branch 'branch-25.12' into binary-kmeans
tarang-jain 540db62
correct fused instantiation
tarang-jain d9eed14
Merge branch 'binary-kmeans' of https://github.com/tarang-jain/cuvs i…
tarang-jain 7ceed82
Merge branch 'branch-25.12' into binary-kmeans
tarang-jain ac261be
Merge branch 'branch-25.12' into binary-kmeans
tarang-jain b66b8ee
cleanup
tarang-jain 4a19ec1
Merge branch 'binary-kmeans' of https://github.com/tarang-jain/cuvs i…
tarang-jain 80d5f9c
Merge branch 'branch-25.12' of https://github.com/rapidsai/cuvs into …
tarang-jain d2b1184
Merge branch 'branch-25.12' of https://github.com/rapidsai/cuvs into …
tarang-jain ab1083e
Merge branch 'branch-25.12' into binary-kmeans
tarang-jain 9a26624
thorough equivalence testing checkpoint
tarang-jain 8a2098f
Merge branch 'binary-kmeans' of https://github.com/tarang-jain/cuvs i…
tarang-jain d4aae95
cleanup-1
tarang-jain f5c61dc
cleanup-2
tarang-jain 54ae1a2
cleanup-3
tarang-jain 76fc1f4
cleanup-4 (style
tarang-jain a8a3a0a
cleanup-6 tests
tarang-jain 05363f5
cleanup-7 (tests)
tarang-jain de3bcc1
cleanup-8 tests
tarang-jain a02e563
cleanup-8 (tests)
tarang-jain b6181a0
cleanup-8 (tests)
tarang-jain 5f640c1
use raft ci artifacts from pr
tarang-jain cc0fa18
wheels artifacts from raft pr
tarang-jain de606fa
style
tarang-jain 385d8c7
shell stlye check
tarang-jain ae49732
Remove RAFT Dask channel from conda packages script
tarang-jain 566b247
fix visible sections in simt_kernel
tarang-jain a24d13b
Merge branch 'branch-25.12' of https://github.com/rapidsai/cuvs into …
tarang-jain b4ea915
raft artifact for python build
tarang-jain 34d2ec5
Merge branch 'branch-25.12' of https://github.com/rapidsai/cuvs into …
tarang-jain 55b13d8
add skip flags
tarang-jain f44a7d8
Merge branch 'branch-25.12' of https://github.com/rapidsai/cuvs into …
tarang-jain 942dc96
Merge branch 'main' into binary-kmeans
tarang-jain 8d99bc7
set binary_index_ flag explicitly
tarang-jain 5153555
Merge branch 'main' into binary-kmeans
tarang-jain ca41dc8
Merge branch 'main' of https://github.com/rapidsai/cuvs into binary-k…
tarang-jain 182dadf
correct recall threshold
tarang-jain 99eea8a
merge upstream
tarang-jain 5220772
style and correct tests
tarang-jain 5fc6f4b
rm extra test
tarang-jain 37378d7
Merge branch 'main' into binary-kmeans
tarang-jain b948a33
rm test
tarang-jain c5e07b1
Merge branch 'binary-kmeans' of https://github.com/tarang-jain/cuvs i…
tarang-jain cbf83b8
Merge branch 'main' into binary-kmeans
tarang-jain c14f26f
Merge branch 'main' into binary-kmeans
tarang-jain b3eac6f
Merge branch 'main' into binary-kmeans
tarang-jain 03a01a1
Merge branch 'main' into binary-kmeans
achirkin 7b409c7
on the fly dataset expansion
tarang-jain 080a5ea
Merge branch 'main' into binary-kmeans
tarang-jain 107a3e4
address PR reviews
tarang-jain 1caabeb
Merge branch 'binary-kmeans' of https://github.com/tarang-jain/cuvs i…
tarang-jain 3681320
simplify bitwise_decode_op
tarang-jain 118a3d7
commit suggestion
tarang-jain 3399656
clang
tarang-jain d4fe3fe
Merge branch 'main' into binary-kmeans
tarang-jain 653364e
merge upstream
tarang-jain ef34908
address reviews
tarang-jain d12a211
style
tarang-jain 91c6734
undo ci changes
tarang-jain 42f1bb7
fix kmeans mapping op
tarang-jain e59a357
other fixes to kmeans for binary data
tarang-jain d13c0c9
fix compilation errors
tarang-jain 8162293
fix compilation
tarang-jain fcae247
fix compilation
tarang-jain a9599bd
doc
tarang-jain ffbcdcc
Merge branch 'main' of https://github.com/rapidsai/cuvs into binary-k…
tarang-jain 3ffba85
simplify ivf-flat build
tarang-jain c0a99e2
fix compilation errors
tarang-jain dbb6423
bug fixes
tarang-jain 248911c
debug
tarang-jain 0656ee6
more corrections to kmeans
tarang-jain 1423356
Merge branch 'main' into binary-kmeans
tarang-jain a25ddac
Merge branch 'main' into binary-kmeans
tarang-jain e8a8152
Merge branch 'main' of https://github.com/rapidsai/cuvs into binary-k…
tarang-jain 8feebb8
bug fixes
tarang-jain 997ddde
debug
tarang-jain 89b54a1
working impl;rm debug statements
tarang-jain 07354d1
rm debug prints:
tarang-jain 07e1837
Merge branch 'main' into binary-kmeans
tarang-jain 510bafd
Merge branch 'release/26.02' into binary-kmeans
tarang-jain 0ddce5d
Merge branch 'release/26.02' into binary-kmeans
tarang-jain d546471
Merge branch 'release/26.02' into binary-kmeans
tarang-jain a2f5a8b
REL v26.02.00 release
AyodeAwe 19cfe12
Merge branch 'release/26.02' into binary-kmeans
tarang-jain e143514
rebase
tarang-jain 2505349
fix compilation
tarang-jain 61ca5b7
Merge branch 'main' into binary-kmeans
tarang-jain 18f0caf
Merge branch 'main' into binary-kmeans
tarang-jain 11e91a6
merge upstream, resolve merge conflicts
tarang-jain c5f0252
Fix binary IVF correctness, persistence, and bindings
tarang-jain 27b19a6
Merge upstream main into binary IVF fixes
tarang-jain 7f27206
Merge branch 'main' into binary-kmeans
tarang-jain 2f1fbc5
Keep binary IVF changes in the C++ API
tarang-jain 1de4801
Fix packed k-means template compilation
tarang-jain 1b94be6
Merge branch 'main' of https://github.com/rapidsai/cuvs into pr1099-s…
tarang-jain 759f6e2
Export bitwise Hamming dispatch instantiation
tarang-jain 6b184ab
Make dispatch export template formatter-safe
tarang-jain 47cd1e5
Keep binary Hamming distance support scoped to IVF
tarang-jain ec879d9
Merge branch 'main' into binary-kmeans
tarang-jain f6d6959
Merge branch 'main' into binary-kmeans
tarang-jain ad45abe
Fix CAGRA test for balanced k-means centroid validation
tarang-jain 9ea5739
Merge branch 'main' into fix/kmeans-balanced-centroid-count-cagra-600
tarang-jain a1e1861
fix style
tarang-jain 33e5419
Merge fix/kmeans-balanced-centroid-count-cagra-600 into binary-kmeans
tarang-jain 96147cd
Fix remaining CAGRA balanced k-means test inputs
tarang-jain 939994b
Allow fixed-width IVF-PQ codebooks for small training sets
tarang-jain fe99276
Merge corrected balanced k-means fix into binary-kmeans
tarang-jain e977137
Restore small-dataset IVF-PQ CAGRA coverage
tarang-jain 672ea9e
Merge restored IVF-PQ CAGRA coverage into binary-kmeans
tarang-jain b892dcc
Remove packed cosine norm handling
tarang-jain 70e0746
Trim packed balanced k-means tests
tarang-jain 6db88b9
Merge branch 'main' into binary-kmeans
tarang-jain 1aa722d
Merge branch 'main' into binary-kmeans
tarang-jain 64d103b
update docs
tarang-jain 9e92c01
Clarify adaptive IVF-flat center documentation
tarang-jain 9878f6c
binary dataset
achirkin 9139f52
Restrict IVF-Binary queries to packed bytes and restore adaptive batc…
tarang-jain 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
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,98 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cuvs/core/export.hpp> | ||
| #include <cuvs/preprocessing/quantize/binary.hpp> | ||
|
|
||
| #include <raft/core/device_mdspan.hpp> | ||
| #include <raft/core/error.hpp> | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace CUVS_EXPORT cuvs { | ||
|
|
||
| /** | ||
| * @brief Non-owning view of the dictionary that binarizes a dataset: the per-dimension thresholds | ||
| * of a binary quantizer. An empty threshold vector stands for the zero threshold. | ||
| */ | ||
| template <typename MathT> | ||
| struct binary_dictionary_view { | ||
| raft::device_vector_view<const MathT, int64_t> threshold; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Non-owning view of a binary-quantized dataset. | ||
| * | ||
| * The data are bit-packed codes, `ceil(dim / 8)` bytes per row; bit `i` of a row is stored in bit | ||
| * `i % 8` of byte `i / 8`, and the unused bits of the last byte are zero. The dictionary is the | ||
| * quantizer that produced the codes, so the logical dimension `dim` (the number of bits) never has | ||
| * to be guessed from the padded byte width. | ||
| * | ||
| * @tparam MathT the type of the source (unquantized) values | ||
| * @tparam IdxT the type of the row indices | ||
| */ | ||
| template <typename MathT, typename IdxT> | ||
| struct device_binary_dataset_view { | ||
| using value_type = MathT; | ||
| using index_type = IdxT; | ||
| using code_type = uint8_t; | ||
| using data_view_type = raft::device_matrix_view<const code_type, int64_t, raft::row_major>; | ||
| using dictionary_view_type = binary_dictionary_view<MathT>; | ||
|
|
||
| /** | ||
| * @param codes row-major codes [n_rows, ceil(dim / 8)] | ||
| * @param dictionary the thresholds used to produce the codes; empty or of size `dim` | ||
| * @param dim the number of bits in each vector | ||
| */ | ||
| device_binary_dataset_view(data_view_type codes, dictionary_view_type dictionary, uint32_t dim) | ||
| : codes_{codes}, dictionary_{dictionary}, dim_{dim} | ||
| { | ||
| RAFT_EXPECTS(dim > 0, "The dimension of a binary dataset must be positive"); | ||
| RAFT_EXPECTS(static_cast<int64_t>((uint64_t{dim} + 7) / 8) == codes.extent(1), | ||
| "The row length of the codes must be ceil(dim / 8) bytes"); | ||
| RAFT_EXPECTS(dictionary.threshold.extent(0) == 0 || | ||
| dictionary.threshold.extent(0) == static_cast<int64_t>(dim), | ||
| "The threshold vector must be empty or have one element per dimension"); | ||
| } | ||
|
|
||
| /** The number of vectors. */ | ||
| [[nodiscard]] auto n_rows() const noexcept -> index_type | ||
| { | ||
| return static_cast<index_type>(codes_.extent(0)); | ||
| } | ||
| /** The number of bits in each vector. */ | ||
| [[nodiscard]] auto dim() const noexcept -> uint32_t { return dim_; } | ||
| /** The number of bytes in each row of the codes. */ | ||
| [[nodiscard]] auto encoded_row_length() const noexcept -> int64_t { return codes_.extent(1); } | ||
|
|
||
| [[nodiscard]] auto data_const_view() const noexcept -> data_view_type { return codes_; } | ||
| [[nodiscard]] auto const_dictionary_view() const noexcept -> dictionary_view_type | ||
| { | ||
| return dictionary_; | ||
| } | ||
|
|
||
| private: | ||
| data_view_type codes_; | ||
| dictionary_view_type dictionary_; | ||
| uint32_t dim_; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief View the codes produced by `preprocessing::quantize::binary::transform` together with the | ||
| * quantizer that produced them. | ||
| */ | ||
| template <typename IdxT, typename MathT> | ||
| auto make_device_binary_dataset_view( | ||
| raft::device_matrix_view<const uint8_t, int64_t, raft::row_major> codes, | ||
| const preprocessing::quantize::binary::quantizer<MathT>& quantizer, | ||
| uint32_t dim) -> device_binary_dataset_view<MathT, IdxT> | ||
| { | ||
| return device_binary_dataset_view<MathT, IdxT>{ | ||
| codes, binary_dictionary_view<MathT>{quantizer.threshold.view()}, dim}; | ||
| } | ||
|
|
||
| } // namespace CUVS_EXPORT cuvs | ||
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
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.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: NVIDIA/cuvs
Length of output: 17936
🏁 Script executed:
Repository: NVIDIA/cuvs
Length of output: 44712
🏁 Script executed:
Repository: NVIDIA/cuvs
Length of output: 41597
Reject or mask nonzero padding bits.
device_binary_dataset_viewaccepts nonzero bits outside the logical dimension. The IVF-Binary coarse search passes the encoded byte count tobitwise_hamming_distance_op, whosecorecounts every bit inx ^ y. It does not mask the unused bits of the final byte.For
dim == 1,0x80therefore has Hamming distance1from0x00, although both represent the same logical vector. Reject nonzero padding bits or mask the final byte before the IVF-Binary build and search operations.🤖 Prompt for AI Agents