From 657c563604c774461aed0394ae99210713145e03 Mon Sep 17 00:00:00 2001 From: Bhavik Sheth Date: Fri, 14 Feb 2025 10:39:11 -0800 Subject: [PATCH 1/4] Add bounds checking to hnsw nb_neighbors (#4185) Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4185 Based on this users comment it seems like we should do bound checking: https://github.com/facebookresearch/faiss/issues/4177 Reviewed By: mnorris11 Differential Revision: D69497295 fbshipit-source-id: 97025cf29c464afb0f85aa98f4b303489b7fc989 --- faiss/impl/HNSW.cpp | 1 + tests/test_hnsw.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/faiss/impl/HNSW.cpp b/faiss/impl/HNSW.cpp index ece0281221..61afa00231 100644 --- a/faiss/impl/HNSW.cpp +++ b/faiss/impl/HNSW.cpp @@ -32,6 +32,7 @@ namespace faiss { **************************************************************/ int HNSW::nb_neighbors(int layer_no) const { + FAISS_THROW_IF_NOT(layer_no + 1 < cum_nneighbor_per_level.size()); return cum_nneighbor_per_level[layer_no + 1] - cum_nneighbor_per_level[layer_no]; } diff --git a/tests/test_hnsw.cpp b/tests/test_hnsw.cpp index b3c93a861e..9424bd3499 100644 --- a/tests/test_hnsw.cpp +++ b/tests/test_hnsw.cpp @@ -582,6 +582,16 @@ TEST_F(HNSWTest, TEST_search_neighbors_to_add) { } } +TEST_F(HNSWTest, TEST_nb_neighbors_bound) { + omp_set_num_threads(1); + EXPECT_EQ(index->hnsw.nb_neighbors(0), 8); + EXPECT_EQ(index->hnsw.nb_neighbors(1), 4); + EXPECT_EQ(index->hnsw.nb_neighbors(2), 4); + EXPECT_EQ(index->hnsw.nb_neighbors(3), 4); + // picking a large number to trigger an exception based on checking bounds + EXPECT_THROW(index->hnsw.nb_neighbors(100), faiss::FaissException); +} + TEST_F(HNSWTest, TEST_search_level_0) { omp_set_num_threads(1); std::vector I(k * nq); From d72d0cab6b45b705a643070893f25135679516e6 Mon Sep 17 00:00:00 2001 From: Michael Norris Date: Wed, 19 Feb 2025 21:44:03 -0800 Subject: [PATCH 2/4] Fix nightly by installing earlier version of lief (#4198) Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4198 1. pins lief due to `AttributeError: type object 'CLASS' has no attribute 'CLASS64'` (just set it to last passing nightly version) 2. pins mkl in gpu builds due to it trying to pull in 2024.2.2 which conflicts with 2023 in the libfaiss. Added nightlies to make sure they pass https://github.com/facebookresearch/faiss/actions/runs/13422430425/job/37498020894. Not all passed: I'm not sure the `build-pull-request / Linux x86_64 GPU w/ cuVS nightlies (CUDA 12.4.0)` nightly is actually broken, but this unblocks the PR builds for now. Reviewed By: junjieqi Differential Revision: D69860604 fbshipit-source-id: 2da623c71b03c22d581b78655253a863fbafd3ed --- .github/actions/build_conda/action.yml | 2 +- conda/faiss-gpu-cuvs/meta.yaml | 2 ++ conda/faiss-gpu/meta.yaml | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/actions/build_conda/action.yml b/.github/actions/build_conda/action.yml index d2e56d23c3..14c227035f 100644 --- a/.github/actions/build_conda/action.yml +++ b/.github/actions/build_conda/action.yml @@ -44,7 +44,7 @@ runs: # Ensure starting packages are from conda-forge. conda list --show-channel-urls conda install -y -q "conda!=24.11.0" - conda install -y -q "conda-build!=24.11.0" + conda install -y -q "conda-build!=24.11.0" "liblief=0.14.1" conda list --show-channel-urls - name: Enable anaconda uploads if: inputs.label != '' diff --git a/conda/faiss-gpu-cuvs/meta.yaml b/conda/faiss-gpu-cuvs/meta.yaml index 45a757b59b..67488632f6 100644 --- a/conda/faiss-gpu-cuvs/meta.yaml +++ b/conda/faiss-gpu-cuvs/meta.yaml @@ -104,11 +104,13 @@ outputs: - mkl =2023 # [x86_64] - cuda-toolkit {{ cudatoolkit }} host: + - mkl =2023 # [x86_64] - _openmp_mutex =4.5=2_kmp_llvm # [x86_64] - python {{ python }} - numpy >=1.19,<2 - {{ pin_subpackage('libfaiss', exact=True) }} run: + - mkl =2023 # [x86_64] - _openmp_mutex =4.5=2_kmp_llvm # [x86_64] - python {{ python }} - numpy >=1.19,<2 diff --git a/conda/faiss-gpu/meta.yaml b/conda/faiss-gpu/meta.yaml index f15c9556d9..8c8c017ff1 100644 --- a/conda/faiss-gpu/meta.yaml +++ b/conda/faiss-gpu/meta.yaml @@ -89,12 +89,15 @@ outputs: - make =4.4 # [osx and arm64] - _openmp_mutex =4.5=2_kmp_llvm # [x86_64 and not win] - cuda-toolkit {{ cudatoolkit }} + - mkl-devel =2023.0 # [x86_64] host: + - mkl =2023.0 # [x86_64] - python {{ python }} - numpy >=1.19,<2 - _openmp_mutex =4.5=2_kmp_llvm # [x86_64 and not win] - {{ pin_subpackage('libfaiss', exact=True) }} run: + - mkl =2023.0 # [x86_64] - python {{ python }} - numpy >=1.19,<2 - packaging From 6b652892ff3a0d3b3d6640c6cf09a84931f69ddf Mon Sep 17 00:00:00 2001 From: Divye Gala Date: Thu, 20 Feb 2025 19:30:30 -0800 Subject: [PATCH 3/4] Pass `store_dataset` argument along to cuVS CAGRA (#4173) Summary: This is required to enable lazy setting of a device copy of the training dataset to a cuVS CAGRA index. Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4173 Reviewed By: mnorris11 Differential Revision: D69795662 Pulled By: gtwang01 fbshipit-source-id: 68cda198ed7983800b64d3e5fac1b77ff55ecd12 --- faiss/gpu/impl/CuvsCagra.cu | 2 ++ 1 file changed, 2 insertions(+) diff --git a/faiss/gpu/impl/CuvsCagra.cu b/faiss/gpu/impl/CuvsCagra.cu index 82e3007d59..f60e1e3ab5 100644 --- a/faiss/gpu/impl/CuvsCagra.cu +++ b/faiss/gpu/impl/CuvsCagra.cu @@ -69,6 +69,7 @@ CuvsCagra::CuvsCagra( index_params_.intermediate_graph_degree = intermediate_graph_degree; index_params_.graph_degree = graph_degree; + index_params_.attach_dataset_on_build = store_dataset; if (!ivf_pq_search_params_) { ivf_pq_search_params_ = @@ -243,6 +244,7 @@ void CuvsCagra::search( storage_, n_, dim_); cuvs_index->update_dataset(raft_handle, dataset); } + store_dataset_ = true; } auto queries_view = raft::make_device_matrix_view( From 1fe8b8b5f13bc952db1df1df77cda1446e61f7d5 Mon Sep 17 00:00:00 2001 From: Nicolas De Carli Date: Thu, 20 Feb 2025 20:54:22 -0800 Subject: [PATCH 4/4] Remove unused variable (#4205) Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4205 Removing unused variable. This piece of code began to be compiled after armv9a has been set as default compilation profile Reviewed By: andrewjcg Differential Revision: D69946389 fbshipit-source-id: f2b5e57585506eb7cecbf76bf71bc6a2b5cc7133 --- faiss/impl/code_distance/code_distance-sve.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/faiss/impl/code_distance/code_distance-sve.h b/faiss/impl/code_distance/code_distance-sve.h index 713b7d8099..d85e47d279 100644 --- a/faiss/impl/code_distance/code_distance-sve.h +++ b/faiss/impl/code_distance/code_distance-sve.h @@ -217,8 +217,6 @@ static void distance_four_codes_sve_for_small_m( const auto offsets_0 = svindex_u32(0, static_cast(ksub)); - const auto quad_lanes = svcntw(); - // loop const auto pg = svwhilelt_b32_u64(0, M);