-
Notifications
You must be signed in to change notification settings - Fork 197
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
Separate CAGRA index type from internal idx type #1664
Conversation
This change is partially consistent with the IVF-Flat API, that also uses I recommend that we update IVF-PQ user facing API to use the same int64_t as mdspan IndexType. @achirkin. |
Oh, I actually wanted to change IVF-Flat api to match IVF-PQ for quite some time. The logic of the API in IVF-PQ is simply to use the extent types (
I strongly suggest to follow the same logic in IVF-Flat. In fact, it almost follows the same logic, except with bugs. (1) it does not support larger-than-uint32_t batch sizes as well, (2) its I'm not sure if that's the case with CAGRA though, as I am not so familiar with this code. However, I believe the logic I outline above makes most sense independent of implementation: the extent types guide the user, telling them what range of inputs is supported without unexpected failures at runtime (when e.g. the input size suddenly goes beyond the magical 4B after months of use). There's also not much sense in supporting search batch sizes beyond |
Thanks @achirkin for the detailed comment!
It is logical what you write, but I am not convinced that this is the best way to communicate the restrictions to both our users and developers.
Theoretically we still support a queries array with
The same issue is present with ivf_pq::build: if someone would instantiate IVF-PQ build with The points above tell me that it for IVF-PQ, we shall fix
Adding few runtime checks is a small price to pay for a less error prone implementation. |
I believe encoding restrictions in types is always the best way, because it guarantees correctness and saves everybody from tracking tons of assertions across the codebase and duplicating (and forgetting to do so) these assertions in the docs. The issue with having overflows in while using Therefore I think the runtime checks are neither a small price nor the less error-prone option. |
While I agree with the above statement, I would also add that this is not only a raft implementation detail: Having I do not agree that having
But that would also need to be documented in developer docs and diligently followed by raft developers. This will definitely lead to errors further down the road. Note that we still keep uint32_t everywhere it is applicable in the critical code path. |
Ok then if we don't want to encode the possible range of inputs in the type of extents, I agree, we should just replace extents type (mdspan |
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.
LGTM.
/merge |
First verstion of a CAGRA API in pylibraft. Todos: - [x] C++ raft_runtime instantiations and void overloads - [x] Cython API - [x] Solve issue of `cagra_types.hpp` including `#include <raft/util/pow2_utils.cuh>` that makes it need nvcc, blocking a clean C++ only cython build - [x] Check in pytests - [x] Add examples to docstrings - [x] Accommodate for parameter rename of #1676 - [x] Accomodate changes of #1664 - [x] Move out of experimental namespace Authors: - Dante Gama Dessavre (https://github.com/dantegd) - Corey J. Nolet (https://github.com/cjnolet) Approvers: - Corey J. Nolet (https://github.com/cjnolet)
This PR decouples CAGRA
IdxT
from the mdspanIndexType
used in CAGRA API, by making the following changemdspan<Type, IdxT> -> mdspan<Type, int64_t>
.In
cagra::index<T, IdxT>
the index typeIdxT
is the type that represents the neighbor indices returned during the ANN search, and the same type is also used as to store the neighborhood graph.The build and search method take
mdspan
objects as input/output argument. Thesemdspan
s have anIndexType
that is used during offset calculation when indexing the matrix. Prior to this PR, we usedIdxT
as the mdspan index type.There is a strong motivation to keep
IdxT
asuint32_t
in order to minimize the memory footprint of the KNN graph. At the same time, the size and offset calculations of mdspans that represent dataset and knn graph require 64-bit indexing for large datasets. This PR changes the mdspan extentIndexType
toint64_t
.This PR does not affect the performance of CAGRA: the search kernels already used correct index type. Only a few operations are affected by this change, and these are outside perf sensitive regions.