Skip to content
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

Integrate IVF-PQ from RAFT #3044

Closed
wants to merge 253 commits into from
Closed
Show file tree
Hide file tree
Changes from 236 commits
Commits
Show all changes
253 commits
Select commit Hold shift + click to select a range
8baee52
Updating raft ivf flat
cjnolet Jun 3, 2022
2eb94f1
adding raftIVFFlat implementation
cjnolet Jun 14, 2022
f7d4185
Isolating quantizer training
cjnolet Jun 14, 2022
26491cb
iAdding todos where we need to plug in raft functionality
cjnolet Jun 14, 2022
b4d08c4
Invocatino of index building has been compiled successfully. Still ne…
cjnolet Jun 17, 2022
bf876f9
Adding call to search.
cjnolet Jun 17, 2022
9b1fc84
Adding stubs for remaining calls that need to be made from RAFT side in
cjnolet Jul 1, 2022
884bfa5
iUpdating function calls for copyFrom to include populating the quant…
cjnolet Jul 1, 2022
0958d2e
Implement some helpers
achirkin Jul 4, 2022
b7144a9
Make it compile
achirkin Jul 5, 2022
38733bb
Make the tests to not crash... sometimes
achirkin Jul 6, 2022
881fbc3
Merge pull request #1 from achirkin/raft_ivf_flat
cjnolet Jul 28, 2022
173c459
Updates
cjnolet Aug 2, 2022
8b7afe0
Merge branch 'raft_ivf_flat' of github.com:cjnolet/faiss into raft_iv…
cjnolet Aug 2, 2022
548e0f0
More updates
cjnolet Aug 2, 2022
baa34d7
One test running so far.
cjnolet Aug 3, 2022
edc5991
Setting add_data_on_build = false;
cjnolet Aug 3, 2022
10f89b4
Copying centroids directly and adding some prints for the test outputs
cjnolet Aug 8, 2022
7c69020
reconstructions seems to be reasonable
cjnolet Aug 8, 2022
8be7746
iUpdates to tests to compare against brute force as ground truth
cjnolet Aug 9, 2022
933582a
Starting to look at resulting runtimes in raft ivf flat tests
cjnolet Aug 24, 2022
d2a6541
Adding timing info to raft test
cjnolet Aug 24, 2022
986407a
Updating for rapids-cmake updates and RAFT updates
cjnolet Aug 25, 2022
ae4ed98
Adding RaftIndexIVFPQ
cjnolet Oct 10, 2022
d8894b8
Merge branch 'main' into raft_integration
cjnolet Oct 10, 2022
410b2c6
Updates
cjnolet Oct 10, 2022
d7ca6b4
Adding FAISS_ENABLE_RAFT option to INSTALL.md
cjnolet Oct 10, 2022
9875dad
Making build.sh work for quick building of proposal
cjnolet Oct 10, 2022
60388dc
Merge branch 'main' into raft_integration
cjnolet Oct 11, 2022
c09d09b
Merging upstream
cjnolet Oct 11, 2022
0081ed9
Integrating more deeply with `use_raft` option in the index config that
cjnolet Oct 19, 2022
a7e0cdd
IVF Flat
cjnolet Oct 19, 2022
fbf7e34
More updates
cjnolet Oct 19, 2022
a9b6963
Getting things building again. Adding raft handle to gpu resources.
cjnolet Oct 20, 2022
b640ba8
Getting FAISS building again w/ RaftIVFFlat
cjnolet Oct 26, 2022
af6d1e9
Adding the append vectors to raft index IVF flat.
cjnolet Oct 26, 2022
545b3d2
Add ing flatindex for the fused l2 knn
cjnolet Oct 27, 2022
2ac5a5b
Validating dispatch of flatindex
cjnolet Oct 28, 2022
68944a5
1. Verified FlatIndex tests are passing (and using RAFT for k<=64 L2 …
cjnolet Nov 15, 2022
3a37031
Calling train() on copyFrom() with reconstructed vectors and filling in
cjnolet Nov 15, 2022
3f51425
IVFFlat gtests run through to completion without crash. Distances look
cjnolet Nov 15, 2022
db1801e
Some of the IVFFlat tests are passing.
cjnolet Nov 15, 2022
f0bbd41
CLeaning up the diff a bit
cjnolet Nov 16, 2022
f7da008
Removing the RaftIndex* files.
cjnolet Nov 16, 2022
5ab762b
Using current raft 22.12
cjnolet Nov 17, 2022
3684cd3
Checking in a little cleanup
cjnolet Nov 30, 2022
35a46b2
Disabling raft from pulling in nn dependencies (e.g. faiss)
cjnolet Jan 9, 2023
eb9f6e9
Merge branch 'main' into raft_integration
cjnolet Jan 9, 2023
e7bf2e5
Updating raft for 23.02. Still working on failing tests.
cjnolet Jan 11, 2023
a8e2ad0
Isolating differences in results- it looks like it's related to the s…
cjnolet Jan 12, 2023
f19fd00
Add and query results appear to match well. LargeBatch tests are fail…
cjnolet Jan 19, 2023
3ff97ab
Merge branch 'main' into raft_integration
cjnolet Jan 20, 2023
1d2baed
Merge branch 'main' into raft_integration
cjnolet Jan 24, 2023
6269ed1
Using facebook for licenses in cmake files
cjnolet Jan 24, 2023
b13593a
Adding small note to build.sh that the file is temporary.
cjnolet Jan 24, 2023
81fbe64
Merge branch 'main' into raft_integration
cjnolet Jan 27, 2023
333761c
Merge branch 'main' into raft_integration
cjnolet Jan 31, 2023
bc8885d
Fixing style
cjnolet Jan 31, 2023
093579b
Merge branch 'master' into raft_integration
cjnolet Jan 31, 2023
10f8080
Merge branch 'raft_integration' of github.com:cjnolet/faiss into raft…
cjnolet Jan 31, 2023
19f38d4
Second pass of fixing formatting
cjnolet Jan 31, 2023
17df798
Third pass at fixing format style
cjnolet Jan 31, 2023
2993441
Adding nvidia license for traceability
cjnolet Jan 31, 2023
5e7eb6d
Updates
cjnolet Feb 6, 2023
d1b0036
Merge remote-tracking branch 'faiss/main' into raft_integration
cjnolet Feb 6, 2023
ddc75ac
Merging
cjnolet Feb 7, 2023
4ada77c
Merge branch 'main' into raft_integration
cjnolet Feb 7, 2023
ccc3bad
Merge branch 'main' into raft_integration
cjnolet Feb 13, 2023
37ec2fa
Fix PR problems (#2839)
May 4, 2023
c07208e
Merge remote-tracking branch 'faiss/main' into raft_integration
cjnolet May 4, 2023
d3a98cc
Fixing cmakelists
cjnolet May 4, 2023
d91de3c
Merge remote-tracking branch 'alexanderguzhva/export-D45054275' into …
cjnolet May 4, 2023
0af95a4
Updates
cjnolet May 4, 2023
36bed23
Merge branch 'main' into raft_integration
cjnolet Jun 5, 2023
fc7f1f8
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Jun 27, 2023
8769115
Merge branch 'main' into raft_integration
cjnolet Jun 28, 2023
576f58f
Fixing merge
cjnolet Jun 28, 2023
eef2b28
Merge branch 'raft_integration' of https://github.com/cjnolet/faiss i…
tarang-jain Jun 28, 2023
092721f
Removing indexflat tests from changeset
cjnolet Jun 28, 2023
1c621ad
First version of copyFrom and copyTo
tarang-jain Jul 7, 2023
62b568b
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Jul 7, 2023
808f1d1
Merge branch 'raft_integration' of https://github.com/cjnolet/faiss i…
tarang-jain Jul 7, 2023
b8d616d
Update copyFrom and copyTo
tarang-jain Jul 25, 2023
cf87175
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Jul 25, 2023
444c58d
Passing tests
tarang-jain Jul 31, 2023
2887af8
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Jul 31, 2023
f148f09
Passing copyTo
tarang-jain Aug 4, 2023
284937b
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Aug 4, 2023
5756508
All tests passing
tarang-jain Aug 8, 2023
c5edbf7
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Aug 8, 2023
82e9791
cleanup
tarang-jain Aug 8, 2023
8486b9b
cleanup
tarang-jain Aug 9, 2023
38215bc
cleanup
tarang-jain Aug 9, 2023
ac67897
cleanup
tarang-jain Aug 9, 2023
94817aa
cleanup
tarang-jain Aug 9, 2023
91b1e32
cleanup
tarang-jain Aug 9, 2023
613ca7a
cleanup
tarang-jain Aug 9, 2023
c43c83f
Separate out nan filtering
tarang-jain Aug 9, 2023
7eb5209
Add USE_NVIDIA_RAFT
tarang-jain Aug 9, 2023
db1774b
Update test
tarang-jain Aug 14, 2023
8cf7e05
update quantizer
tarang-jain Aug 16, 2023
ad9a596
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Aug 16, 2023
a17b1f3
All except LongIVFList passing
tarang-jain Aug 21, 2023
d90d923
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Aug 21, 2023
3c33ebb
Formatting
tarang-jain Aug 21, 2023
971a6b2
Format
tarang-jain Aug 21, 2023
5c0592e
remove debug statements
tarang-jain Aug 21, 2023
7618b44
LargeBatch test added and now passing
tarang-jain Aug 23, 2023
bd5a217
final update to gtests
tarang-jain Aug 23, 2023
2022a14
Pull latest
tarang-jain Sep 6, 2023
d0f8385
Merge branch 'main' into raft_integration
tarang-jain Sep 6, 2023
5e52aca
im
tarang-jain Sep 21, 2023
a39d208
Initial machinery for RAFT support
tarang-jain Oct 5, 2023
59236cb
merge main
tarang-jain Oct 5, 2023
c5db6cd
some ivf-flat assertions
tarang-jain Oct 6, 2023
15ee365
More changes to IVF-Flat, fill in more funcs for IVF-PQ
tarang-jain Oct 11, 2023
5c1e671
Filling in funcs for copyFrom and copyTo
tarang-jain Oct 12, 2023
c59f551
Update copyfrom
tarang-jain Oct 20, 2023
6170c8c
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Oct 20, 2023
4400d4f
testing
tarang-jain Oct 24, 2023
ff77e55
testing
tarang-jain Oct 24, 2023
f942371
update cmake for testing
tarang-jain Oct 24, 2023
ba2f8d5
expt
tarang-jain Oct 24, 2023
c917c81
Update impl, testing
tarang-jain Oct 26, 2023
3e6fbea
GpuIndexIVF train working
tarang-jain Oct 30, 2023
5943124
Raft index external update successful
tarang-jain Oct 31, 2023
f000652
ivfflat tests passing
tarang-jain Nov 1, 2023
6b790f2
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Nov 1, 2023
4a3254b
all tests passing except assertions
tarang-jain Nov 8, 2023
baaa844
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Nov 8, 2023
22bf90c
cleanup
tarang-jain Nov 10, 2023
66222ff
cleanup
tarang-jain Nov 10, 2023
229ceda
correction
tarang-jain Nov 10, 2023
c63764a
Style
tarang-jain Nov 10, 2023
c4e48bf
cleanup
tarang-jain Nov 10, 2023
e940c75
style
tarang-jain Nov 10, 2023
dfebcb9
remove cudart_utils import
tarang-jain Nov 11, 2023
925682e
Update warning msg
tarang-jain Nov 11, 2023
a718bd5
PQ assign_index WARN
tarang-jain Nov 13, 2023
ae1b243
Mark raft symbols with hidden visibility
robertmaynard Nov 14, 2023
40864df
Update index_cpu_to_gpu
tarang-jain Nov 14, 2023
867c0e8
benchmarking script for ivfflat
tarang-jain Nov 15, 2023
8e5a3dc
Update IVF-PQ BM script
tarang-jain Nov 20, 2023
5b6db4e
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Nov 20, 2023
0a806bb
Update IVF-Flat BM script
tarang-jain Nov 20, 2023
ececb62
Docs, rename API
tarang-jain Nov 21, 2023
217c7a6
format
tarang-jain Nov 21, 2023
15411db
format
tarang-jain Nov 21, 2023
f81a9db
resolve build issue
tarang-jain Nov 21, 2023
7cb7316
resolve failing copyTo_Raft
tarang-jain Nov 21, 2023
e993c01
style
tarang-jain Nov 21, 2023
934a835
resolve failing LargeBatch
tarang-jain Nov 21, 2023
fd7c84d
update BM script, LargeBatch_Raft test
tarang-jain Nov 22, 2023
575fe82
make build with raft-ann-bench, update bench to sift1M
tarang-jain Nov 28, 2023
9a8492f
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Nov 28, 2023
dbcc576
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Dec 1, 2023
c8ea4a4
add sync_stream to search
tarang-jain Dec 5, 2023
a145998
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Dec 5, 2023
0c82e30
Update raft add and search
tarang-jain Dec 7, 2023
53bf4c0
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Dec 7, 2023
4a74523
first commit
tarang-jain Dec 12, 2023
9600fe0
Update AllocRequest
tarang-jain Dec 12, 2023
d73129d
use only custom MR for managed allocs
tarang-jain Dec 13, 2023
480859a
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Dec 13, 2023
05bcf38
remove dbg statements
tarang-jain Dec 13, 2023
990c9d0
remove bugs
tarang-jain Jan 9, 2024
b894248
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Jan 9, 2024
e0c3d05
bug fix
tarang-jain Jan 9, 2024
401e640
address PR reviews
tarang-jain Jan 11, 2024
394738b
Merge branch 'main' into rmm-mem-alloc
tarang-jain Jan 11, 2024
2078c54
Merge branch 'main' into rmm-mem-alloc
tarang-jain Jan 16, 2024
045537b
updated until rmm-pool-alloc cleanup 92e75b52433553d48e27937bf86fd922…
tarang-jain Jan 16, 2024
bb87df3
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Jan 16, 2024
69fcfeb
remove bug due to nullptr indices
tarang-jain Jan 17, 2024
8ce165e
Merge branch 'main' into rmm-mem-alloc
tarang-jain Jan 17, 2024
c9a23a5
update benchmarking, testing scripts
tarang-jain Jan 17, 2024
bc33838
Merge branch 'main' into raft_integration
tarang-jain Jan 17, 2024
366dda3
format
tarang-jain Jan 17, 2024
ebec04c
Merge branch 'raft_integration' of https://github.com/tarang-jain/fai…
tarang-jain Jan 17, 2024
cf98b7d
Merge branch 'rmm-mem-alloc' of https://github.com/tarang-jain/faiss …
tarang-jain Jan 17, 2024
f3cc680
Merge branch 'main' into raft_integration
tarang-jain Jan 17, 2024
e2777d9
Removing build.sh
cjnolet Feb 1, 2024
80742c9
Merge branch 'main' into raft_integration2
cjnolet Feb 1, 2024
83124ae
Trying to pin fmt
cjnolet Feb 2, 2024
130caa8
Merge branch 'raft_integration2' of github.com:cjnolet/faiss into raf…
cjnolet Feb 2, 2024
2065e94
Adding conditional to disable RAFT if arch == pascal
cjnolet Feb 2, 2024
f24272b
Fixing a few more places
cjnolet Feb 2, 2024
abfc0e1
Fixing some syntax errors
cjnolet Feb 2, 2024
d7caab4
Fixing style
cjnolet Feb 2, 2024
9c0ed23
DIsabling below volta
cjnolet Feb 2, 2024
23f3041
A couple additional fixes
cjnolet Feb 2, 2024
f57e467
More updates
cjnolet Feb 2, 2024
4b00a16
Missed one
cjnolet Feb 2, 2024
40e4c11
Fixing style
cjnolet Feb 2, 2024
f66d1fe
More style fixes
cjnolet Feb 2, 2024
24b6b74
Fixing another bug
cjnolet Feb 2, 2024
6234107
Fixing RaftUtils in cmakelists
cjnolet Feb 2, 2024
f0985f4
Updates after PR reviews
tarang-jain Feb 3, 2024
692e9bd
Merge branch 'raft_integration' of https://github.com/tarang-jain/fai…
tarang-jain Feb 3, 2024
0469924
merge
tarang-jain Feb 3, 2024
131b191
Merge branch 'main' into raft_integration
tarang-jain Feb 3, 2024
46afd1e
Updates after PR reviews
tarang-jain Feb 3, 2024
bee418b
merge
tarang-jain Feb 3, 2024
f90b3e6
merge
tarang-jain Feb 3, 2024
44bd50a
FIxing cmakelists
cjnolet Feb 3, 2024
92475aa
changes to gpu CMakeLists
tarang-jain Feb 5, 2024
2397bf3
changes to gpu CMakeLists
tarang-jain Feb 5, 2024
dfb7d32
changes to gpu CMakeLists
tarang-jain Feb 5, 2024
c2afb4c
changes to gpu CMakeLists
tarang-jain Feb 5, 2024
1483389
restore comment
tarang-jain Feb 6, 2024
496e923
changes to gpu CMakeLists
tarang-jain Feb 5, 2024
da6103d
FIxing cmakelists
cjnolet Feb 3, 2024
fcfadd4
changes to gpu CMakeLists
tarang-jain Feb 5, 2024
03e7edb
changes to gpu CMakeLists
tarang-jain Feb 5, 2024
bfbc9a4
rebase
tarang-jain Feb 6, 2024
ca234e7
fix gpu CMakeLists after rebase
tarang-jain Feb 6, 2024
248c1b9
fix gpu CMakeLists after rebase
tarang-jain Feb 6, 2024
8d0eade
update latest changes from upstream to gpu CMakeLists
tarang-jain Feb 6, 2024
ac8c9a1
small style fix
tarang-jain Feb 6, 2024
1d79f3c
GCC visibility for more files
tarang-jain Feb 6, 2024
5790b48
Changes to gtests for default use_raft=true
tarang-jain Feb 6, 2024
7f1d848
more small changes to IVFPQ tests
tarang-jain Feb 7, 2024
5579056
small change in comment
tarang-jain Feb 8, 2024
315d1b8
cleanup
tarang-jain Feb 8, 2024
53329b7
temporary fix for failing CI test
tarang-jain Feb 8, 2024
6125884
some updates to python tests
tarang-jain Feb 9, 2024
b5e8fcc
small change, remove fmt from faiss-gpu-raft meta.yaml
tarang-jain Feb 9, 2024
b4d9b78
use_raft in trainResidualQuantizer_
tarang-jain Feb 9, 2024
77336a8
change interleavedLayout assertion to warning
tarang-jain Feb 9, 2024
a33029f
undo small change
tarang-jain Feb 9, 2024
89368d4
update python tests
tarang-jain Feb 9, 2024
66a8d63
format
tarang-jain Feb 9, 2024
9be05b5
empty commit
tarang-jain Feb 9, 2024
bb9e0a3
more use_raft = False for failing tests
tarang-jain Feb 9, 2024
2d73896
undo last change
tarang-jain Feb 9, 2024
4e0e3de
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Feb 9, 2024
be09adc
small change to ivf training
tarang-jain Feb 10, 2024
a6706dd
format
tarang-jain Feb 10, 2024
da2a425
updates after PR reviews
tarang-jain Feb 13, 2024
24340ab
update niter
tarang-jain Feb 13, 2024
fda9ac8
undo change to getListLength
tarang-jain Feb 14, 2024
1b05400
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Feb 14, 2024
7a0b61c
update should_use_raft, fix typo
tarang-jain Feb 14, 2024
c48f55c
Merge branch 'main' into raft_integration
tarang-jain Feb 15, 2024
1fcd272
Merge branch 'main' into raft_integration
tarang-jain Feb 15, 2024
4db273b
change default use_raft in GpuClonerOptions and GpuDistance
tarang-jain Feb 16, 2024
059d036
Merge branch 'raft_integration' of https://github.com/tarang-jain/fai…
tarang-jain Feb 16, 2024
2b33f28
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
tarang-jain Feb 16, 2024
fad85a1
changes to pass CI
tarang-jain Feb 17, 2024
17203b2
passing py tests
tarang-jain Feb 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ if(FAISS_ENABLE_GPU)
enable_language(CUDA)
endif()

if(FAISS_ENABLE_RAFT)
find_package(raft COMPONENTS compiled distributed)
endif()
if(FAISS_ENABLE_RAFT AND NOT TARGET raft::raft)
find_package(raft COMPONENTS compiled distributed)
endif()

add_subdirectory(faiss)

Expand Down
193 changes: 193 additions & 0 deletions benchs/bench_ivfflat_raft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
# Copyright (c) 2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import numpy as np
import faiss
import time
import argparse
import rmm

######################################################
# Command-line parsing
######################################################

parser = argparse.ArgumentParser()


def aa(*args, **kwargs):
group.add_argument(*args, **kwargs)


group = parser.add_argument_group('benchmarking options')

aa('--bm_train', default=False, action='store_true',
help='whether to benchmark train operation on GPU index')
aa('--bm_add', default=False, action='store_true',
help='whether to benchmark add operation on GPU index')
aa('--bm_search', default=True,
help='whether to benchmark search operation on GPU index')
aa('--raft_only', default=False, action='store_true',
help='whether to only produce RAFT enabled benchmarks')


group = parser.add_argument_group('IVF options')
aa('--n_centroids', default=256, type=int,
help="number of IVF centroids")


group = parser.add_argument_group('searching')

aa('--k', default=100, type=int, help='nb of nearest neighbors')
aa('--nprobe', default=50, help='nb of IVF lists to probe')

args = parser.parse_args()

print("args:", args)

rs = np.random.RandomState(123)

res = faiss.StandardGpuResources()

# Use an RMM pool memory resource for device allocations
mr = rmm.mr.PoolMemoryResource(rmm.mr.CudaMemoryResource())
rmm.mr.set_current_device_resource(mr)

def bench_train_milliseconds(index, trainVecs, use_raft):
co = faiss.GpuMultipleClonerOptions()
co.use_raft = use_raft
index_gpu = faiss.index_cpu_to_gpu(res, 0, index, co)
t0 = time.time()
index_gpu.train(trainVecs)
return 1000*(time.time() - t0)


if args.bm_train:
print("=" * 40)
print("GPU Train Benchmarks")
print("=" * 40)
trainset_sizes = [5000, 10000, 100000, 1000000, 5000000]
dataset_dims = [128, 256, 1024]
for n_rows in trainset_sizes:
for n_cols in dataset_dims:
index = faiss.index_factory(n_cols, "IVF{},Flat".format(args.n_centroids))
trainVecs = rs.rand(n_rows, n_cols).astype('float32')
raft_gpu_train_time = bench_train_milliseconds(
index, trainVecs, True)
if args.raft_only:
print("Method: IVFFlat, Operation: TRAIN, dim: %d, n_centroids %d, numTrain: %d, RAFT enabled GPU train time: %.3f milliseconds" % (
n_cols, args.n_centroids, n_rows, raft_gpu_train_time))
else:
classical_gpu_train_time = bench_train_milliseconds(
index, trainVecs, False)
print("Method: IVFFlat, Operation: TRAIN, dim: %d, n_centroids %d, numTrain: %d, classical GPU train time: %.3f milliseconds, RAFT enabled GPU train time: %.3f milliseconds" % (
n_cols, args.n_centroids, n_rows, classical_gpu_train_time, raft_gpu_train_time))


def bench_add_milliseconds(index, addVecs, use_raft):
co = faiss.GpuMultipleClonerOptions()
co.use_raft = use_raft
index_gpu = faiss.index_cpu_to_gpu(res, 0, index, co)
index_gpu.copyFrom(index)
t0 = time.time()
index_gpu.add(addVecs)
return 1000*(time.time() - t0)


if args.bm_add:
print("=" * 40)
print("GPU Add Benchmarks")
print("=" * 40)
addset_sizes = [5000, 10000, 100000, 1000000]
dataset_dims = [128, 256, 1024]
n_train = 10000
trainVecs = rs.rand(n_train, n_cols).astype('float32')
index = faiss.index_factory(
n_cols, "IVF" + str(args.n_centroids) + ",Flat")
index.train(trainVecs)
for n_rows in addset_sizes:
for n_cols in dataset_dims:
addVecs = rs.rand(n_rows, n_cols).astype('float32')
raft_gpu_add_time = bench_add_milliseconds(index, addVecs, True)
if args.raft_only:
print("Method: IVFFlat, Operation: ADD, dim: %d, n_centroids %d, numAdd: %d, RAFT enabled GPU add time: %.3f milliseconds" % (
n_train, n_rows, n_cols, args.n_centroids, raft_gpu_add_time))
else:
classical_gpu_add_time = bench_add_milliseconds(
index, addVecs, False)
print("Method: IVFFlat, Operation: ADD, dim: %d, n_centroids %d, numAdd: %d, classical GPU add time: %.3f milliseconds, RAFT enabled GPU add time: %.3f milliseconds" % (
n_train, n_rows, n_cols, args.n_centroids, classical_gpu_add_time, raft_gpu_add_time))


def bench_search_milliseconds(index, addVecs, queryVecs, nprobe, k, use_raft):
co = faiss.GpuMultipleClonerOptions()
co.use_raft = use_raft
index_gpu = faiss.index_cpu_to_gpu(res, 0, index, co)
index_gpu.copyFrom(index)
index_gpu.add(addVecs)
index_gpu.nprobe = nprobe
t0 = time.time()
index_gpu.search(queryVecs, k)
return 1000*(time.time() - t0)


if args.bm_search:
print("=" * 40)
print("GPU Search Benchmarks")
print("=" * 40)
queryset_sizes = [5000, 10000, 100000, 500000]
n_train = 10000
n_add = 100000
search_bm_dims = [8, 16, 32]
for n_cols in search_bm_dims:
index = faiss.index_factory(n_cols, "IVF{},Flat".format(args.n_centroids))
trainVecs = rs.rand(n_train, n_cols).astype('float32')
index.train(trainVecs)
addVecs = rs.rand(n_add, n_cols).astype('float32')
for n_rows in queryset_sizes:
queryVecs = rs.rand(n_rows, n_cols).astype('float32')
raft_gpu_search_time = bench_search_milliseconds(
index, addVecs, queryVecs, args.nprobe, args.k, True)
if args.raft_only:
print("Method: IVFFlat, Operation: SEARCH, dim: %d, n_centroids: %d, numVecs: %d, numQuery: %d, nprobe: %d, k: %d, RAFT enabled GPU search time: %.3f milliseconds" % (
n_cols, args.n_centroids, n_add, n_rows, args.nprobe, args.k, raft_gpu_search_time))
else:
classical_gpu_search_time = bench_search_milliseconds(
index, addVecs, queryVecs, args.nprobe, args.k, False)
print("Method: IVFFlat, Operation: SEARCH, dim: %d, n_centroids: %d, numVecs: %d, numQuery: %d, nprobe: %d, k: %d, classical GPU search time: %.3f milliseconds, RAFT enabled GPU search time: %.3f milliseconds" % (
n_cols, args.n_centroids, n_add, n_rows, args.nprobe, args.k, classical_gpu_search_time, raft_gpu_search_time))

print("=" * 40)
print("Large RAFT Enabled Benchmarks")
print("=" * 40)
# Avoid classical GPU Benchmarks for large datasets because of OOM for more than 500000 queries and/or large dims as well as for large k
queryset_sizes = [100000, 500000, 1000000]
large_search_bm_dims = [128, 256, 1024]
for n_cols in large_search_bm_dims:
trainVecs = rs.rand(n_train, n_cols).astype('float32')
index = faiss.index_factory(
n_cols, "IVF" + str(args.n_centroids) + ",Flat")
index.train(trainVecs)
addVecs = rs.rand(n_add, n_cols).astype('float32')
for n_rows in queryset_sizes:
queryVecs = rs.rand(n_rows, n_cols).astype('float32')
raft_gpu_search_time = bench_search_milliseconds(
index, addVecs, queryVecs, args.nprobe, args.k, True)
print("Method: IVFFlat, Operation: SEARCH, numTrain: %d, dim: %d, n_centroids: %d, numVecs: %d, numQuery: %d, nprobe: %d, k: %d, RAFT enabled GPU search time: %.3f milliseconds" % (
n_cols, args.n_centroids, n_add, n_rows, args.nprobe, args.k, raft_gpu_search_time))
168 changes: 168 additions & 0 deletions benchs/bench_ivfpq_raft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
# Copyright (c) 2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import numpy as np
import faiss
import time
import argparse
import rmm

######################################################
# Command-line parsing
######################################################

parser = argparse.ArgumentParser()

from datasets import load_sift1M, evaluate


print("load data")
xb, xq, xt, gt = load_sift1M()

def aa(*args, **kwargs):
group.add_argument(*args, **kwargs)


group = parser.add_argument_group('benchmarking options')
aa('--raft_only', default=False, action='store_true',
help='whether to only produce RAFT enabled benchmarks')

group = parser.add_argument_group('IVF options')
aa('--bits_per_code', default=8, type=int, help='bits per code. Note that < 8 is only supported when RAFT is enabled')
aa('--pq_len', default=2, type=int, help='number of vector elements represented by one PQ code')
aa('--use_precomputed', default=True, type=bool, help='use precomputed codes (not with RAFT enabled)')

group = parser.add_argument_group('searching')
aa('--k', default=10, type=int, help='nb of nearest neighbors')
aa('--nprobe', default=50, type=int, help='nb of IVF lists to probe')

args = parser.parse_args()

print("args:", args)

rs = np.random.RandomState(123)

res = faiss.StandardGpuResources()

# Use an RMM pool memory resource for device allocations
mr = rmm.mr.PoolMemoryResource(rmm.mr.CudaMemoryResource())
rmm.mr.set_current_device_resource(mr)

# A heuristic to select a suitable number of lists
def compute_nlist(numVecs):
nlist = np.sqrt(numVecs)
if (numVecs / nlist < 1000):
nlist = numVecs / 1000
return int(nlist)


def bench_train_milliseconds(index, trainVecs, use_raft):
co = faiss.GpuMultipleClonerOptions()
# use float 16 lookup tables to save space
co.useFloat16LookupTables = True
co.use_raft = use_raft
index_gpu = faiss.index_cpu_to_gpu(res, 0, index, co)
t0 = time.time()
index_gpu.train(trainVecs)
return 1000*(time.time() - t0)

n_rows, n_cols = xb.shape
n_train, _ = xt.shape
M = n_cols // args.pq_len
nlist = compute_nlist(n_rows)
index = faiss.index_factory(n_cols, "IVF{},PQ{}x{}np".format(nlist, M, args.bits_per_code))

print("=" * 40)
print("GPU Train Benchmarks")
print("=" * 40)
raft_gpu_train_time = bench_train_milliseconds(index, xt, True)
if args.raft_only:
print("Method: IVFPQ, Operation: TRAIN, dim: %d, n_centroids %d, numSubQuantizers %d, bitsPerCode %d, numTrain: %d, RAFT enabled GPU train time: %.3f milliseconds" % (
n_cols, nlist, M, args.bits_per_code, n_train, raft_gpu_train_time))
else:
classical_gpu_train_time = bench_train_milliseconds(
index, xt, False)
print("Method: IVFPQ, Operation: TRAIN, dim: %d, n_centroids %d, numSubQuantizers %d, bitsPerCode %d, numTrain: %d, classical GPU train time: %.3f milliseconds, RAFT enabled GPU train time: %.3f milliseconds" % (
n_cols, nlist, M, args.bits_per_code, n_train, classical_gpu_train_time, raft_gpu_train_time))


def bench_add_milliseconds(index, addVecs, use_raft):
co = faiss.GpuMultipleClonerOptions()
# use float 16 lookup tables to save space
co.useFloat16LookupTables = True
co.use_raft = use_raft
index_gpu = faiss.index_cpu_to_gpu(res, 0, index, co)
index_gpu.copyFrom(index)
t0 = time.time()
index_gpu.add(addVecs)
return 1000*(time.time() - t0)

print("=" * 40)
print("GPU Add Benchmarks")
print("=" * 40)
index.train(xt)
raft_gpu_add_time = bench_add_milliseconds(index, xb, True)
if args.raft_only:
print("Method: IVFPQ, Operation: ADD, dim: %d, n_centroids %d numSubQuantizers %d, bitsPerCode %d, numAdd %d, RAFT enabled GPU add time: %.3f milliseconds" % (
n_cols, nlist, M, args.bits_per_code, n_rows, raft_gpu_add_time))
else:
classical_gpu_add_time = bench_add_milliseconds(
index, xb, False)
print("Method: IVFFPQ, Operation: ADD, dim: %d, n_centroids %d, numSubQuantizers %d, bitsPerCode %d, numAdd %d, classical GPU add time: %.3f milliseconds, RAFT enabled GPU add time: %.3f milliseconds" % (
n_cols, nlist, M, args.bits_per_code, n_rows, classical_gpu_add_time, raft_gpu_add_time))


def bench_search_milliseconds(index, addVecs, queryVecs, nprobe, k, use_raft):
co = faiss.GpuMultipleClonerOptions()
co.use_raft = use_raft
co.useFloat16LookupTables = True
index_gpu = faiss.index_cpu_to_gpu(res, 0, index, co)
index_gpu.copyFrom(index)
index_gpu.add(addVecs)
index_gpu.nprobe = nprobe
t0 = time.time()
index_gpu.search(queryVecs, k)
return 1000*(time.time() - t0)


if args.bm_search:
print("=" * 40)
print("GPU Search Benchmarks")
print("=" * 40)
queryset_sizes = [1, 10, 100, 1000, 10000]
n_train, n_cols = xt.shape
n_add, _ = xb.shape
print(xq.shape)
M = n_cols // args.pq_len
nlist = compute_nlist(n_add)
index = faiss.index_factory(n_cols, "IVF{},PQ{}x{}np".format(nlist, M, args.bits_per_code))
index.train(xt)
for n_rows in queryset_sizes:
queryVecs = xq[np.random.choice(xq.shape[0], n_rows, replace=False)]
raft_gpu_search_time = bench_search_milliseconds(
index, xb, queryVecs, args.nprobe, args.k, True)
if args.raft_only:
print("Method: IVFPQ, Operation: SEARCH, dim: %d, n_centroids: %d, numSubQuantizers %d, bitsPerCode %d, numVecs: %d, numQuery: %d, nprobe: %d, k: %d, RAFT enabled GPU search time: %.3f milliseconds" % (
n_cols, nlist, M, args.bits_per_code, n_add, n_rows, args.nprobe, args.k, raft_gpu_search_time))
else:
classical_gpu_search_time = bench_search_milliseconds(
index, xb, queryVecs, args.nprobe, args.k, False)
print("Method: IVFPQ, Operation: SEARCH, dim: %d, n_centroids: %d, numSubQuantizers %d, bitsPerCode %d, numVecs: %d, numQuery: %d, nprobe: %d, k: %d, classical GPU search time: %.3f milliseconds, RAFT enabled GPU search time: %.3f milliseconds" % (
n_cols, nlist, M, args.bits_per_code, n_add, n_rows, args.nprobe, args.k, classical_gpu_search_time, raft_gpu_search_time))
2 changes: 1 addition & 1 deletion cmake/thirdparty/fetch_rapids.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================
set(RAPIDS_VERSION "23.12")
set(RAPIDS_VERSION "24.02")

if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/FAISS_RAPIDS.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-${RAPIDS_VERSION}/RAPIDS.cmake
Expand Down
Loading