Fix binary IVF reconstruct_n stride#5398
Conversation
|
Hi @mmnhgo! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Fixes #5386.
Summary
Fix
IndexBinaryIVF::reconstruct_nto write reconstructed binary codes usingcode_sizeas the byte stride instead ofd, which is the binary dimension in bits.This matches the documented
IndexBinaryoutput layout (ni * d / 8bytes) and the Python wrapper allocation shape(ni, self.code_size).Root cause
IndexBinaryIVF::reconstruct_ncomputed each output pointer as:For binary indexes,
dis measured in bits, so this skippeddbytes per row and left compact Python output rows unwritten, with possible writes past the caller-provided buffer.Validation
IndexBinaryIVF.reconstruct_n(0, 3)output.git diff --check -- faiss\IndexBinaryIVF.cpp tests\test_index_binary.pysuccessfully.I could not complete a local post-fix Python run because this checkout has no local FAISS build and the Python interpreter loads the installed Anaconda
faisspackage; this environment also lackscmakeandninjacommands for rebuilding the extension.