Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/facebookresearch/faiss into…
Browse files Browse the repository at this point in the history
… cuvs-migrate
  • Loading branch information
tarang-jain committed Nov 6, 2024
2 parents cf5d46a + adb1884 commit ef22fa2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
9 changes: 9 additions & 0 deletions benchs/bench_fw/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ class DatasetDescriptor:

embedding_id_column: Optional[str] = None

# unused in open-source
splits_distribution: Optional[List[List[bytes]]] = None

# unused in open-source
splits: Optional[List[bytes]] = None

# unused in open-source
serialized_df: Optional[str] = None

sampling_rate: Optional[float] = None

# sampling column for xdb
Expand Down
8 changes: 4 additions & 4 deletions faiss/IndexAdditiveQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,23 +528,23 @@ void ResidualCoarseQuantizer::search(
float* distances,
idx_t* labels,
const SearchParameters* params_in) const {
float beam_factor = this->beam_factor;
float beam_factor_2 = this->beam_factor;
if (params_in) {
auto params =
dynamic_cast<const SearchParametersResidualCoarseQuantizer*>(
params_in);
FAISS_THROW_IF_NOT_MSG(
params,
"need SearchParametersResidualCoarseQuantizer parameters");
beam_factor = params->beam_factor;
beam_factor_2 = params->beam_factor;
}

if (beam_factor < 0) {
if (beam_factor_2 < 0) {
AdditiveCoarseQuantizer::search(n, x, k, distances, labels);
return;
}

int beam_size = int(k * beam_factor);
int beam_size = int(k * beam_factor_2);
if (beam_size > ntotal) {
beam_size = ntotal;
}
Expand Down
36 changes: 18 additions & 18 deletions faiss/IndexIVFFastScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ IndexIVFFastScan::IndexIVFFastScan() {

void IndexIVFFastScan::init_fastscan(
size_t M,
size_t nbits,
size_t nbits_2,
size_t nlist,
MetricType /* metric */,
int bbs) {
FAISS_THROW_IF_NOT(bbs % 32 == 0);
FAISS_THROW_IF_NOT(nbits == 4);
int bbs_2) {
FAISS_THROW_IF_NOT(bbs_2 % 32 == 0);
FAISS_THROW_IF_NOT(nbits_2 == 4);

this->M = M;
this->nbits = nbits;
this->bbs = bbs;
ksub = (1 << nbits);
this->nbits = nbits_2;
this->bbs = bbs_2;
ksub = (1 << nbits_2);
M2 = roundup(M, 2);
code_size = M2 / 2;

Expand Down Expand Up @@ -1029,11 +1029,11 @@ void IndexIVFFastScan::search_implem_12(

// prepare the result handlers

int qbs2 = this->qbs2 ? this->qbs2 : 11;
int qbs2_2 = this->qbs2 ? this->qbs2 : 11;

std::vector<uint16_t> tmp_bias;
if (biases.get()) {
tmp_bias.resize(qbs2);
tmp_bias.resize(qbs2_2);
handler.dbias = tmp_bias.data();
}

Expand All @@ -1046,7 +1046,7 @@ void IndexIVFFastScan::search_implem_12(
int list_no = qcs[i0].list_no;
size_t i1 = i0 + 1;

while (i1 < qcs.size() && i1 < i0 + qbs2) {
while (i1 < qcs.size() && i1 < i0 + qbs2_2) {
if (qcs[i1].list_no != list_no) {
break;
}
Expand All @@ -1066,7 +1066,7 @@ void IndexIVFFastScan::search_implem_12(
std::vector<int> q_map(nc), lut_entries(nc);
AlignedTable<uint8_t> LUT(nc * dim12);
memset(LUT.get(), -1, nc * dim12);
int qbs = pq4_preferred_qbs(nc);
int qbs_2 = pq4_preferred_qbs(nc);

for (size_t i = i0; i < i1; i++) {
const QC& qc = qcs[i];
Expand All @@ -1078,7 +1078,7 @@ void IndexIVFFastScan::search_implem_12(
}
}
pq4_pack_LUT_qbs_q_map(
qbs, M2, dis_tables.get(), lut_entries.data(), LUT.get());
qbs_2, M2, dis_tables.get(), lut_entries.data(), LUT.get());

// access the inverted list

Expand All @@ -1094,7 +1094,7 @@ void IndexIVFFastScan::search_implem_12(
handler.id_map = ids.get();

pq4_accumulate_loop_qbs(
qbs, list_size, M2, codes.get(), LUT.get(), handler, scaler);
qbs_2, list_size, M2, codes.get(), LUT.get(), handler, scaler);
// prepare for next loop
i0 = i1;
}
Expand Down Expand Up @@ -1232,11 +1232,11 @@ void IndexIVFFastScan::search_implem_14(
is_max, impl, n, k, local_dis.data(), local_idx.data(), sel));
handler->begin(normalizers.get());

int qbs2 = this->qbs2 ? this->qbs2 : 11;
int qbs2_2 = this->qbs2 ? this->qbs2 : 11;

std::vector<uint16_t> tmp_bias;
if (biases.get()) {
tmp_bias.resize(qbs2);
tmp_bias.resize(qbs2_2);
handler->dbias = tmp_bias.data();
}

Expand All @@ -1256,7 +1256,7 @@ void IndexIVFFastScan::search_implem_14(
std::vector<int> q_map(nc), lut_entries(nc);
AlignedTable<uint8_t> LUT(nc * dim12);
memset(LUT.get(), -1, nc * dim12);
int qbs = pq4_preferred_qbs(nc);
int qbs_2 = pq4_preferred_qbs(nc);

for (size_t i = i0; i < i1; i++) {
const QC& qc = qcs[i];
Expand All @@ -1269,7 +1269,7 @@ void IndexIVFFastScan::search_implem_14(
}
}
pq4_pack_LUT_qbs_q_map(
qbs, M2, dis_tables.get(), lut_entries.data(), LUT.get());
qbs_2, M2, dis_tables.get(), lut_entries.data(), LUT.get());

// access the inverted list

Expand All @@ -1285,7 +1285,7 @@ void IndexIVFFastScan::search_implem_14(
handler->id_map = ids.get();

pq4_accumulate_loop_qbs(
qbs,
qbs_2,
list_size,
M2,
codes.get(),
Expand Down
4 changes: 2 additions & 2 deletions faiss/impl/NSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ void NSG::search_on_graph(
retset[k].flag = false;
int n = retset[k].id;

size_t nneigh = graph.get_neighbors(n, neighbors.data());
for (int m = 0; m < nneigh; m++) {
size_t nneigh_2 = graph.get_neighbors(n, neighbors.data());
for (int m = 0; m < nneigh_2; m++) {
int id = neighbors[m];
if (id > ntotal || vt.get(id)) {
continue;
Expand Down

0 comments on commit ef22fa2

Please sign in to comment.