1065 Commits

Author SHA1 Message Date
spectaclehong
b13f47a4da Fix reconstruct bug when by_residual is false (#2298)
Summary:
When I reconstruct with by_residual turned off, the distance was greatly increased.
This is because the reconstruct_from_offset function did not check if the by_residual option was off.
I fix this bug with simple if statement.
(like this https://github.com/facebookresearch/faiss/blob/main/faiss/IndexIVFPQ.cpp#L365)

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2298

Reviewed By: alexanderguzhva

Differential Revision: D35746566

Pulled By: mdouze

fbshipit-source-id: 50f98c7cc97c7936507573fe41b65a79ecdbc4ca
2022-04-20 01:35:21 -07:00
Matthijs Douze
8ffed8c219 common ancestor for quantizer classes (#2295)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2295

Makes a common ancestor for quantizer classes.
As a first application, adds a clone_Quantizer function

Reviewed By: alexanderguzhva

Differential Revision: D35561960

fbshipit-source-id: 896a4f3fc4ab992511cdc0642689a440f170f683
2022-04-20 01:34:01 -07:00
Check Deng
992d494d4a Support reconstruct() in IndexFastScan (#2287)
Summary:
This diff implemented `reconstruct()` interface in `IndexFastScan`.

unit test: `python -m unittest test_fast_scan_ivf.TestReconstruct`

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2287

Test Plan: buck test //faiss/tests/:test_fast_scan_ivf -- TestReconstruct

Reviewed By: alexanderguzhva

Differential Revision: D35576662

Pulled By: mdouze

fbshipit-source-id: ac584128cd370807182dee06a57efedc23c0f7d4
2022-04-19 03:18:58 -07:00
Alexandr Guzhva
536aa99da7 speedup exhaustive_L2sqr_blas when a single nearest point needed (#2296)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2296

Reviewed By: mdouze

Differential Revision: D35602161

fbshipit-source-id: 5c9bb8a9444ab111708328d60d1080802756bb02
2022-04-13 13:39:15 -07:00
Lucas Hosseini
7c9d979d66 Enable servicelab regression testing.
Summary:
Start migration of existing benchmarks to Google's Benchmark library + register benchmark to servicelab.

The benchmark should be automatically registered to servicelab once this diff lands according to https://www.internalfb.com/intern/wiki/ServiceLab/Use_Cases/Benchmarks_(C++)/#servicelab-job.

Reviewed By: mdouze

Differential Revision: D35397782

fbshipit-source-id: 317db2527f12ddde0631cacc3085c634afdd0e37
2022-04-07 02:45:55 -07:00
Matthijs Douze
bb4c987b5c Demo of residual quantizer distance computer for LaserKNN (#2283)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2283

This is a demonstration for:

- how to use a distance computer to compute query-to-code distances with a residual quantizer

- how to construct a ResidualCoarseQuantizer that uses a prefix of residalquantizer codes

See related doc https://docs.google.com/document/d/1g97lrMXVYh5FcQzw23v_sUE22ybHfCFxtbHyFJwxKKE/edit?usp=sharing

Reviewed By: alexanderguzhva

Differential Revision: D34958088

fbshipit-source-id: edb06ee350de67f855e96ae57a3862fbf14f6e54
2022-04-06 12:42:24 -07:00
Matthijs Douze
1806c6af27 Automatic type conversions for Python API (#2274)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2274

All input matrices needed to be of the correct type and to be C-contiguous. This diff passes the main entry points of the api through `np.ascontiguousarray` so that the function parameters are transparently converted to the suitable format if needed.

We did not have this before because users need to be made aware of the performance impact, but it seems that maybe usability is more useful.

This diff is an alternative to

D35007365
https://github.com/facebookresearch/faiss/pull/2250

Reviewed By: beauby

Differential Revision: D35009612

fbshipit-source-id: fa0d5cfdfbff6b0916d47bd33c620e3ca9d5dd40
2022-03-30 05:42:08 -07:00
Alexandr Guzhva
b32abc95c2 ProductQuantizer::compute_code tracks the nearest vector index in a register rather than stores the distances in a buffer. (#2280)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2280

Add a new function call fvec_L2sqr_ny_nearest and a demonstration of its implementation for 4 bits

Reviewed By: mdouze

Differential Revision: D35189945

fbshipit-source-id: d1b2ba42851df195123c7e318a8dcf26f775eaba
2022-03-29 10:21:23 -07:00
Alexandr Guzhva
438b64cd8b IVFPQ AVX2 optimization for PQ, including polysemous filtering (#2277)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2277

* extend a specialized AVX2 version for IVFPQScannerT::scan_list_with_table to cover  IVFPQScannerT::scan_list_polysemous_hc as well
* lower the comparison precision in test_lowlevel_ivf tests from EXPECT_EQ to EXPECT-FLOAT_EQ because of the AVX2 change in IVFPQScannerT::scan_list_polysemous_hc, otherwise tests fail

Reviewed By: mdouze

Differential Revision: D34964138

fbshipit-source-id: 1d304a8f6eda040fa4c626676b4d492f2c12f04f
2022-03-24 06:35:38 -07:00
Matthijs Douze
291353c5a9 Generalize DistanceComputer for flat indexes (#2255)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2255

The `DistanceComputer` object is derived from an Index (obtained with `get_distance_computer()`). It maintains a current query and quickly computes distances from that query to any item in the database. This is useful, eg. for the IndexHNSW and IndexNSG that rely on query-to-point comparisons in the datasets.

This diff introduces the `FlatCodesDistanceComputer`, that inherits from `DistanceComputer` for Flat indexes. In addition to the distance-to-item function, it adds a `distance_to_code` that computes the distance from any code to the current query, even if it is not stored in the index.

This is implemented for all FlatCode indexes (IndexFlat, IndexPQ, IndexScalarQuantizer and IndexAdditiveQuantizer).

In the process, the two classes were extracted to their own header file `impl/DistanceComputer.h`

Reviewed By: beauby

Differential Revision: D34863609

fbshipit-source-id: 39d8c66475e55c3223c4a6a210827aa48bca292d
2022-03-20 23:43:33 -07:00
Matthijs Douze
add3705c11 make fast scan tests cheaper (#2251)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2251

the fast_scan and fast_scan_ivf tests are irregularly timing out on the FB test infra

This diff:
- breaks down more tests into sub-tests
- makes tests cheaper by reducing the test dataset sizes
- corrects a nasty local variable binding bug that prevented all cases of `implem` to be covered.

I also tried to fix the polysemous tests that also timeout but I could not reproduce the timeout.

https://www.internalfb.com/intern/test/562949978542309?ref_report_id=0

Reviewed By: beauby

Differential Revision: D34852254

fbshipit-source-id: b005ffb3723e7d9df75516a539540d9165249cea
2022-03-16 13:23:07 -07:00
Carter McClellan
e52101689f Summary: Add Binary Index i.o to c_api (#2233)
Summary:
Add Binary Index i.o to c_api

In reference to isse: https://github.com/facebookresearch/faiss/issues/2225

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2233

Test Plan: Only changes to the C API

Reviewed By: beauby

Differential Revision: D34815076

Pulled By: mdouze

fbshipit-source-id: 70e0bb15ff02044995460c274bd50465b44ccc5b
2022-03-16 03:28:46 -07:00
Alexandr Guzhva
8f2a72a8e6 AVX2 optimized IVFPQ scanning code (#2253)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2253

add a specialized AVX2 version for IVFPQScannerT::scan_list_with_table

Reviewed By: mdouze

Differential Revision: D34733503

fbshipit-source-id: a428de04548426b39bc5a092b9f6802eadbd184d
2022-03-15 17:35:11 -07:00
Alexandr Guzhva
80bf6a2bc6 Improve AVX2 distance computations (#2252)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2252

Improve fvec_op_ny_D4 for AVX2.

Reviewed By: mdouze

Differential Revision: D34729914

fbshipit-source-id: ac51eb3804a9df9c0ec56963f477ddc70e44d8fa
2022-03-15 16:51:04 -07:00
Alexandr Guzhva
b2712c2a40 AVX2 implementation of fvec_madd (#2254)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2254

AVX2 version of fmadd_vec.

Reviewed By: mdouze

Differential Revision: D34764024

fbshipit-source-id: 66f694df0302c79f2c295ee10dcc7d564faa4a26
2022-03-15 16:46:19 -07:00
Jeff Johnson
31b0565e16 Fix GPU IVF serialization bug; fix stream issues (#2263)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2263

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2258

GPU IVF indices could not be properly deserialized or copied from CPU then added to after the fact, this resulted in the following C++ assertion:

```
Faiss assertion 'indices->numVecs == oldNumVecs' failed in int faiss::gpu::IVFBase::addVectors(faiss::gpu::Tensor<float, 2, true>&, faiss::gpu::Tensor<long int, 1, true>&) at faiss/gpu/impl/IVFBase.cu:581
```

as the count of vectors present was not updated properly everywhere, as discovered internally by vtantia.

This diff fixes this issue by properly updating the count, as well as cleaning up stream usage in the IVF code. The problem is that the code was previously using `thrust::device_vector` which does not have a means to control on which stream copies or other work is performed. This is fixed by replacing all usage of `thrust::device_vector` with our own `DeviceVector` which was already used to store IVF data but not metadata. `DeviceVector` provides sufficient control over the proper CUDA stream usage.

Reviewed By: vtantia, mdouze

Differential Revision: D34886859

fbshipit-source-id: 70577bb386ff7dc0f4443ec4562d3ee80afc24e3
2022-03-15 13:38:10 -07:00
Ivan Sopin
d50211a38f Break distance ties in heap_replace_top() by ID (#2245)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2245

This changeset makes the `heap_replace_top()` function of the FAISS heap implementation break distance ties by the element's ID, according to the heap's min/max property.

Reviewed By: mdouze

Differential Revision: D34669542

fbshipit-source-id: 0db24fd12442eedeee917fbb3e811ba4a070ce0f
2022-03-09 10:23:48 -08:00
Jeff Johnson
878275f915 Faiss GPU: remove d2h copy from PQ MM debugging
Summary:
If the number of dimensions per sub-quantizer is not in the specialized list, it falls back to the generalized batch GEMM implementation.

When I implemented this, I had in a d2h copy so I could look at the computed distances. I removed the debugging code but not this copy.

Prior to this, PQ16 on 1024 dims was 6x slower than PQ32. Now, it is only 1.5x slower (it is slower because there is a higher number of dims per sub-q, despite there being more sub-qs).

Reviewed By: beauby

Differential Revision: D34526043

fbshipit-source-id: de6f70f0f0b91608eb6ae2a05da2af812546e4bc
2022-02-28 15:43:33 -08:00
Matthijs Douze
b8fe92dfee contrib clustering module (#2217)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2217

This diff introduces a new Faiss contrib module that contains:
- generic k-means implemented in python (was in distributed_ondisk)
- the two-level clustering code, including a simple function that runs it on a Faiss IVF index.
- sparse clustering code (new)

The main idea is that that code is often re-used so better have it in contrib.

Reviewed By: beauby

Differential Revision: D34170932

fbshipit-source-id: cc297cc56d241b5ef421500ed410d8e2be0f1b77
2022-02-28 14:18:47 -08:00
CodemodService FBSourceClangFormatLinterBot
647135ec47 Daily arc lint --take CLANGFORMAT
Reviewed By: zertosh

Differential Revision: D34412981

fbshipit-source-id: a7aa81c0c69bf731db37813f431d9f6ed6a6a355
2022-02-23 02:24:32 -08:00
Check Deng
41007232d6 AQ fastscan (#2169)
Summary:
Work in progress.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2169

Test Plan:
buck test mode/opt //faiss/tests/:test_fast_scan
buck test mode/opt //faiss/tests/:test_fast_scan_ivf

Reviewed By: beauby

Differential Revision: D34208813

Pulled By: mdouze

fbshipit-source-id: 74b72e07dc537667a7def403c4e46d3d05408c27
2022-02-22 15:24:31 -08:00
Check Deng
a03a1eba8b Add IndexNSGPQ and IndexNSGSQ (#2218)
Summary:
This diff added IndexNSGPQ and IndexNSGSQ, including index factory and I/O. And also fixed the ARM CI.

Fixed https://github.com/facebookresearch/faiss/issues/2128

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2218

Reviewed By: beauby

Differential Revision: D34276313

Pulled By: mdouze

fbshipit-source-id: a5014af8447800ad15bd89b4f87204b4b36866d2
2022-02-18 04:51:15 -08:00
Matthijs Douze
06ae6b8a59 Refresh github README (#2219)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2219

Update the readme and add KingLittleQ as an author

Reviewed By: beauby

Differential Revision: D34195947

fbshipit-source-id: f99a01f825e17ceba960063d10a9d93e324336fb
2022-02-14 02:01:20 -08:00
Matthijs Douze
eb8781557f Fix exhaustive search GT computation with IP distance (#2212)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2212

Fixes issue

https://github.com/facebookresearch/faiss/issues/2205

clear bug report
easy fix
easy to accept ;-)

Reviewed By: beauby

Differential Revision: D33975281

fbshipit-source-id: 088e1f3078dc79402563be7fac3530d76b197006
2022-02-07 19:36:21 -08:00
avk
36f2998a64 Allow to tune efConstruction HNSW parameter with the ParameterSpace object (#2160)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2160

Reviewed By: beauby

Differential Revision: D33975820

Pulled By: mdouze

fbshipit-source-id: aad8fd566171688213567dbb527cb80ec80d3b65
2022-02-03 09:47:54 -08:00
Check Deng
12d88a5fd8 Fix omp & memory leak (#2168)
Summary:
Fix an OMP bug and a memory leakage bug. The first one would lead to non-deterministic results and even worse.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2168

Test Plan: buck test //faiss/tests/:test_lsq -- test_deterministic

Reviewed By: beauby

Differential Revision: D33975589

Pulled By: mdouze

fbshipit-source-id: c1cf2589b0e718354ccf0221c3474633bcb8c7ee
2022-02-03 09:44:45 -08:00
Ben Mann
30abcd6a86 Add assertion to merge_ondisk.py (#2190)
Summary:
Fixes https://github.com/facebookresearch/faiss/issues/2188

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2190

Reviewed By: beauby

Differential Revision: D33975889

Pulled By: mdouze

fbshipit-source-id: 364eeac8de02f3ae00c9676198ed2ce27cfcd12b
2022-02-03 05:14:22 -08:00
pletessier
9747259e2f SWIG wrapper for InvertedListScanner (#2200)
Summary:
As discussed in https://github.com/facebookresearch/faiss/issues/2072, here is a PR to use InvertedListScanner with Python. It might be slower but it gives access to this features in Python for those who want to avoid C++.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2200

Test Plan: check that it compiles

Reviewed By: beauby

Differential Revision: D33975686

Pulled By: mdouze

fbshipit-source-id: dd731f90ce1609d555a17551fcc8c39eadf3fbd7
2022-02-03 03:46:52 -08:00
Jeff Johnson
04d31fac53 Faiss GPU: fix gpu 0 usage if gpu 0 is not used (GitHub issue 2178) (#2182)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2182

This diff fixes the issue in https://github.com/facebookresearch/faiss/issues/2178

namely that cudaHostAlloc does seem to perform some GPU initialization on the current device that is active.

Reviewed By: beauby

Differential Revision: D33480473

fbshipit-source-id: 4dc76c12b7be2caa96294bbb1aeaf9a44d030ae9
2022-01-10 10:31:03 -08:00
Matthijs Douze
07a874d5b1 Post-training refinement of residual quantizer codebooks (#2166)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2166

RQ training is done progressively from one quantizer to the next, maintaining a current set of codes and quantization centroids.
However, for RQ as for any additive quantizer, there is a closed form solution for the centroids that minimizes the quantization error for fixed codes.
This diff offers the option to estimate that codebook at the end of the optimization. It performs this estimation iteratively, ie. several rounds of code computation - codebook refinement are performed.

A pure python implementation + results is here:
https://github.com/fairinternal/faiss_improvements/blob/dbcc746/decoder/refine_aq_codebook.ipynb

Reviewed By: wickedfoo

Differential Revision: D33309409

fbshipit-source-id: 55c13425292e73a1b05f00e90f4dcfdc8b3549e8
2022-01-05 00:59:16 -08:00
Lucas Hosseini
c08cbff1a4 Prepare for v1.7.2 release. (#2151)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2151

Reviewed By: mdouze

Differential Revision: D33157463

Pulled By: beauby

fbshipit-source-id: 8f8580a7ad953484f41fbbb2d001f3484fab4c3d
v1.7.2
2021-12-16 15:44:23 -08:00
Matthijs Douze
d68ff42195 Fix OPQ dimension parsing (#2147)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2147

There was a bug in the OPQ string parsing. This diff adds a test and fixes the error.

Reviewed By: aijanai

Differential Revision: D33020167

fbshipit-source-id: 32e43653849b258a3b6d0cfdc44a6c637433f2c8
2021-12-11 03:28:29 -08:00
Lucas Hosseini
a0de37bd18 Update CUDA driver on CircleCI. (#2146)
Summary:
A recent CUDA driver is required for building packages for CUDA 11.3.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2146

Reviewed By: wickedfoo

Differential Revision: D33020204

Pulled By: beauby

fbshipit-source-id: 01257b1dcb4987f4866cc058c22d1dd5977d76ce
2021-12-10 10:14:28 -08:00
Lucas Hosseini
7492d23354 Fix packaging (#2121)
Summary:
- Disable problematic tests on OSX.
- Ensure compiler compatibility with CUDA builds.
- Fix path for Python extension libraries.
- Use CentOS for CUDA packaging.
- Update CUDA versions in CI (10.2 and 11.3).

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2121

Reviewed By: mdouze

Differential Revision: D32921117

Pulled By: beauby

fbshipit-source-id: 588c18add8084b8228ff5abc651eaa4567919cc6
2021-12-07 13:12:30 -08:00
Lucas Hosseini
812e97daf4 Fix deadlock in HNSW. (#2143)
Summary:
IndexHNSW has a deadlock in the add() method, which is fixed by
temporarily releasing the lock on the current element while updating
its neighbors' adjacency lists.

This bug concerns multi-threaded insertion only, and seems to manifest
itself only with certain OpenMP configurations.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2143

Reviewed By: mdouze

Differential Revision: D32919041

Pulled By: beauby

fbshipit-source-id: e515541c1b22bfcb79d29c0bde1843e63f5175fb
2021-12-07 09:15:44 -08:00
CodemodService FBSourceClangFormatLinterBot
b60722c4cd Daily arc lint --take CLANGFORMAT
Reviewed By: zertosh

Differential Revision: D32910817

fbshipit-source-id: 60d0cb10412e1a37a0249bb223b75855c5596dbd
2021-12-07 08:10:49 -08:00
Matthijs Douze
a0b50e669f Re-factor factory string parsing (#2134)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2134

The old parsing was very complex and grew out of hand.
this diff just uses regex parsing.

Reviewed By: wickedfoo

Differential Revision: D32759110

fbshipit-source-id: 243029bba8a7fe70c71323f5edc7e2ce4e669757
2021-12-07 04:35:57 -08:00
Matthijs Douze
c0052c1533 IndexFlatCodes: a single parent for all flat codecs (#2132)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2132

This diff adds the class IndexFlatCodes that becomes the parent of all "flat" encodings.
IndexPQ
IndexFlat
IndexAdditiveQuantizer
IndexScalarQuantizer
IndexLSH
Index2Layer

The other changes are:
- for IndexFlat, there is no vector<float> with the data anymore. It is replaced with a `get_xb()` function. This broke quite a few external codes, that this diff also attempts to fix.
- I/O functions needed to be adapted. This is done without changing the I/O format for any index.
- added a small contrib function to get the data from the IndexFlat
- the functionality has been made uniform, for example remove_ids and add are now in the parent class.

Eventually, we may support generic storage for flat indexes, similar to `InvertedLists`, eg to memmap the data, but this will again require a big change.

Reviewed By: wickedfoo

Differential Revision: D32646769

fbshipit-source-id: 04a1659173fd51b130ae45d345176b72183cae40
2021-12-07 01:31:07 -08:00
Sugosh Nagavara Ravindra
253c7a6070 Update train_type_t enum to support all combinations of flags
Summary:
It looks like loading FAISS codecs which have the flag set fails in dev mode since it builds in ASAN and nothing in the code checks for that.
The error is not present in opt mode, however the sandcastle test fails
For best practice, this diff introduces combination of train_type_t flags as enums

Reviewed By: mdouze

Differential Revision: D32746904

fbshipit-source-id: f20820350e0b07b35e04c965dee01b790194e6f3
2021-12-01 23:55:01 -08:00
Matthijs Douze
bef12cf51b Implement LCC's RCQ + ITQ in Faiss (#2123)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2123

One of the encodings used by LCC is based on a RCQ coarse quantizer and a "payload" of ITQ. The codes are compared with Hamming distances.

The index type `IndexIVFSpectralHash` can be re-purposed to perfrorm this type of index.

This diff contains a small demo demo_rcq_itq script in python to show how:
* the RCQ + ITQ are trained
* the RCQ + ITQ index add and search work (with a very inefficient python implementation)
* they can be transferred to an `IndexIVFSpectralHash`
* the python implementation and `IndexIVFSpectralHash` give the same results

The advantage of using to an `IndexIVFSpectralHash` is that in C++ it offers an `InvertedListScanner` object that can be used to compute query to code distances with its `distance_to_code` method. This is generic and will generalize to  other types of encodings and coarse quantizers.

What is missing is an index_factory to make instanciation easier.

Reviewed By: sc268

Differential Revision: D32642900

fbshipit-source-id: 284f3029d239b7946bbca44a748def4e058489bd
2021-11-25 15:59:18 -08:00
Matthijs Douze
c659dd2dc9 Support 2 concatenated codecs (#2117)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2117

This supports 2 concatenated codecs. It is based on IndexRefine, that already does this but did not have a standalone codec interface.
The main use case for now is a residual quantizer + ITQ.
The test below demonstrates how to instantiate that.
The advantage is that the index_factory parser already exists.
The IndexRefine decoder just uses the second index decoder, that is supposed to be more accurate than the first.

Reviewed By: beauby

Differential Revision: D32569997

fbshipit-source-id: 3fe9cd02eaa7d1cfe23b0f1168cc034821f1c362
2021-11-23 09:58:55 -08:00
Check Deng
6c99782f7c Fix unorder bug in NSG (#2086)
Summary:
The results returned by `NSG::search` are already sorted. Calling `maxheap_reorder` will make the results unorder.

Fixed https://github.com/facebookresearch/faiss/issues/2081.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2086

Test Plan: buck test //faiss/tests/:test_index -- test_order

Reviewed By: beauby

Differential Revision: D32593924

Pulled By: mdouze

fbshipit-source-id: 794b94681610657bd2f305f7e3d6cd5d25c6bdba
2021-11-22 11:41:01 -08:00
ptaylor
fbf6b4a439 Compress CUDA device code in libfaiss.so (#2091)
Summary:
Pass `-Xfatbin=-compress-all` to `nvcc` so device code is compressed when embedded in `libfaiss.so`.

In our testing[[1]](0a0d3b48e8/results.txt), compressing device code has negligible (or no) impact on compile, load, or run times, but significantly reduces the library size on disk:

```bash
# cmake -GNinja -B build -S . \
#  -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF \
#  -DFAISS_ENABLE_GPU=ON -DFAISS_ENABLE_PYTHON=OFF \
#  -DCMAKE_CUDA_ARCHITECTURES="60-real;70-real;75-real;80-real;86"

# v1.7.0:
$ du -Shc build/faiss/libfaiss.so
318M	build/faiss/libfaiss.so

# this PR:
$ du -Shc build/faiss/libfaiss.so
160M	build/faiss/libfaiss.so
```

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2091

Reviewed By: mdouze

Differential Revision: D32597803

Pulled By: wickedfoo

fbshipit-source-id: a2adb43aea0fa24a9581abe14a7d90a6e98523ce
2021-11-22 10:51:07 -08:00
Matthijs Douze
b598f5558c Add an epsilon to avoid numerical instability in PCA whiteneing
Summary:
PCA whitening implies to multiply eigenvectors with 1/sqrt(singular values of convariance matrix). The singular values are sometimes 0 (because the vector subspace is not full-rank) or negative (because of numerical issues).
Therefore, this diff adds an epsilon to the denominator above (default 0).

Reviewed By: edpizzi

Differential Revision: D31725075

fbshipit-source-id: dae68bda9f7452220785d76e30ce4b2ac8582413
2021-10-19 01:02:21 -07:00
Chengqi Deng
26abede812 Non-uniform quantization of vector norms (#2037)
Summary:
This diff implemented non-uniform quantization of vector norms in additive quantizers. index_factory and I/O are supported.

index_factory:  `XXX_Ncqint{nbits}` where `nbits` is the number of bits to quantize vector norm.

For 8 bits code, it is almost the same as 8-bit uniform quantization. It will slightly improve the accuracy if the code size is less than 8 bits.
```
RQ4x8_Nqint8:  R@1 0.1116
RQ4x8_Ncqint8: R@1 0.1117

RQ4x8_Nqint4:  R@1 0.0901
RQ4x8_Ncqint4: R@1 0.0989
```

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2037

Test Plan:
buck test //faiss/tests/:test_clustering -- TestClustering1D
buck test //faiss/tests/:test_lsq -- test_index_accuracy_cqint
buck test //faiss/tests/:test_residual_quantizer -- test_norm_cqint
buck test //faiss/tests/:test_residual_quantizer -- test_search_L2

Reviewed By: beauby

Differential Revision: D31083476

Pulled By: mdouze

fbshipit-source-id: f34c3dafc4eb1c6f44a63e68137158911aa4a2f4
2021-10-11 14:13:16 -07:00
Jeff Johnson
312d823494 Faiss GPU large transpose fix (#2075)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2075

This is a fix for https://github.com/facebookresearch/faiss/pull/1996

namely, that large transposition jobs (where one of the dimensions is > 65535) will still work by performing a loop over the gridDim.y

Reviewed By: mdouze

Differential Revision: D31481494

fbshipit-source-id: af35af36cce27ce7d44128d95cc229dd5c4b4b56
2021-10-11 12:36:00 -07:00
Lucas Hosseini
79e74fe307 Generate python docstrings from doxygen comments. (#1969)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1969

Reviewed By: mdouze

Differential Revision: D31084784

Pulled By: beauby

fbshipit-source-id: 32b152f10fde9a0f5299909b8fd5c855fe738996
2021-10-10 22:14:48 -07:00
Alexander Andreev
14ddbc2911 Add faiss_pairwise_L2sqr_with_defaults into C_API (#2067)
Summary:
fixes https://github.com/facebookresearch/faiss/issues/2060

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2067

Reviewed By: beauby

Differential Revision: D31228802

Pulled By: mdouze

fbshipit-source-id: 1cb7df125ad47ccfa5169a10504d588b52eacdf7
2021-10-07 03:43:57 -07:00
Matthijs Douze
b813ba805e Reduce mem usage + improve performance for sequential search imlementation
Summary:
Following up on issue https://github.com/facebookresearch/faiss/issues/2054 it seems that this code crashes Faiss (instead of just leaking memory).

Findings:

- when running in MT mode, each search in an indexflat used as coarse quantizer consumes some memory
- this mem consumption does not appear in single-thread mode or with few threads
- in gdb it appears that even when the nb of queries is 1, each search spawns max_threads threads (80 on the test machine)

This diff:

- adds a C++ test that checks how much mem is used when repeatedly searching a vector
- adjusts the number of search threads to the number of query vectors. This is especially useful for single-vector queries.

Reviewed By: beauby

Differential Revision: D31142383

fbshipit-source-id: 134ddaf141e7c52a854cea398f5dbf89951a7ff8
2021-10-05 15:54:04 -07:00
Kent Gauen
3ca4fe5b6a Error Checking Typo (#2055)
Summary:
I am correcting a minor typo in the error checking.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2055

Reviewed By: beauby, wickedfoo

Differential Revision: D31052509

Pulled By: mdouze

fbshipit-source-id: 36063107503afa5c37a98a0ae0d62df8bc8832e8
2021-09-20 09:29:35 -07:00