Skip to content

Commit a4ebcb1

Browse files
Michael Norrisfacebook-github-bot
Michael Norris
authored andcommitted
Add error for overflowing nbits during PQ construction (facebookresearch#3833)
Summary: Pull Request resolved: facebookresearch#3833 size_t expands to unsigned long int, so any left shift more than 31 means ksub overflows. So, we can add a check right before it is constructed in ProductQuantizer. Ramil talked to Matthijs and the outcome is that 16 bits isn't really practical, but we can do the check for 24 to be safe. Reviewed By: kuarora, mengdilin Differential Revision: D62153881 fbshipit-source-id: 721db6bf6ad5dd5d336b4498f4750acc4059310c
1 parent 1cafc71 commit a4ebcb1

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

faiss/impl/ProductQuantizer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void ProductQuantizer::set_derived_values() {
6161
"The dimension of the vector (d) should be a multiple of the number of subquantizers (M)");
6262
dsub = d / M;
6363
code_size = (nbits * M + 7) / 8;
64+
FAISS_THROW_IF_MSG(nbits > 24, "nbits larger than 24 is not practical.");
6465
ksub = 1 << nbits;
6566
centroids.resize(d * ksub);
6667
verbose = false;

0 commit comments

Comments
 (0)