Commit Graph
755 Commits
Author SHA1 Message Date
Iurii Makarov 8ccd800986 Implemented Jaccard distance (#2684)
Summary:
**Summary**
Implemented Jaccard distance requested in this issue: https://github.com/facebookresearch/faiss/issues/1299
**Test plan**
Run: make -C build test
Output: 100% tests passed, 0 tests failed out of 174

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

Reviewed By: mdouze

Differential Revision: D43398833

Pulled By: lvoursl

fbshipit-source-id: b38cf27a7858842efe967bcb1033977863716a76
2023-02-27 07:49:42 -08:00
Alexandr Guzhva 521e271cb8 modify FAISS_PRAGMA_IMPRECISE_FUNCTION_* flags to make old clang versions to generate FMAs on x64 (#2726)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2726

Old versions of clang (prior to 14) do not generate FMAs on x86 unless this option is used. On the other hand, ARM does not support the needed pragma flag.

Reviewed By: DenisYaroshevskiy

Differential Revision: D43503265

fbshipit-source-id: a024dd221288e44d4e2ade2f5db2c4402e26ff3d
2023-02-22 12:19:32 -08:00
Alexandr Guzhva 8ef0985c11 auto-vectorization for fvec_L2sqr() (#2716)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2716

enable fast-math computations for fvec_L2sqr() and let compiler autovectorize it

Reviewed By: algoriddle

Differential Revision: D43369467

fbshipit-source-id: e84985bfbe0385436bcbc829427f479003093ba7
2023-02-22 06:55:01 -08:00
Alexandr Guzhva f12fe8f300 remove unused fvec_inner_product_ref() and fvec_norm_L2sqr_ref() (#2725)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2725

fvec_inner_product_ref() is no longer needed, using fvec_inner_product() instead in all the cases

fvec_norm_L2sqr_ref() is no longer needed, using fvec_norm_L2sqr() instead in all the cases

Reviewed By: algoriddle

Differential Revision: D43472582

fbshipit-source-id: 2d99a022d420092aed2adfd57e12be5b3e652944
2023-02-22 06:55:01 -08:00
Alexandr Guzhva 67d2a779ea Replace distance_to_code() in IVFPQScanner and PQDistanceComputer (#2717)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2717

Use avx2-optimized distance_to_code(), if appropriate

Reviewed By: mlomeli1

Differential Revision: D43369478

fbshipit-source-id: 0a68c07057710644342e0993a47f26e77a397636
2023-02-21 14:19:13 -08:00
Alexandr Guzhva 55b2d54ee1 move files from impl/ivfpq to impl/code_distance (#2715)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2715

Reviewed By: mlomeli1

Differential Revision: D43369479

fbshipit-source-id: 3de25f4313a20eb4d249316133822b3a31a55893
2023-02-21 14:19:13 -08:00
Denis Yaroshevskiy cf40d3a73d Fixing FAISS_PRAGMA_IMPRECISE_* for clang arm and gcc (#2721)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2721

FAISS_PRAGMA_IMPRECISE_* macros were modified:

* Disabled ones on clang on arm, because it does not support `_Pragma("float_control(precise, off)")`

* Added missing pragma for the GCC compiler.

Reviewed By: alexanderguzhva

Differential Revision: D43437450

fbshipit-source-id: cec8042c3c8c7147ae7e2ffa1ac9e2232c8f1a92
2023-02-21 07:26:40 -08:00
Rujin Cao 6edd23d1b4 Fix typo 'ownerhsip'
Summary: ownerhsip -> ownership

Reviewed By: stanley-shi, sonamghosh, xuwenzhi

Differential Revision: D43398548

fbshipit-source-id: 60bd51a0d10995686ad5d6f9cc6da4101444bce9
2023-02-17 16:27:15 -08:00
Denis Yaroshevskiy 37f1f67870 Fix msvc pragmas issue (#2718)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2718

Missed msvc failure.

Also updated a failing test somewhere.

Reviewed By: alexanderguzhva

Differential Revision: D43401794

fbshipit-source-id: 029102b969cbe6ab6c2420da21454f61fd28e094
2023-02-17 15:45:06 -08:00
Denis Yaroshevskiy a5203ff017 Follow up fixes to faiss vectorization change
Summary:
Pragmas:
turns out GCC does not support pragma float_control
I have no way to test it locally but I tried on godbolt: https://godbolt.org/z/zTzf7jd7c

I will put these pragmas in folly later but for now - let's just solve the problem.

Test:
The diff: D43353199 that produced slightly different floating point results broke this test.

After looking into it I don't believe that the original test data had any meaning and was just a dump of the output.

Accoding to mdouze the previous test data was questionable and using random numbers would be preferrable, so I did.

Reviewed By: alexanderguzhva

Differential Revision: D43393684

fbshipit-source-id: 691397302b58a98e1ccbe32feffa7aaeee96accd
2023-02-17 08:53:50 -08:00
Denis Yaroshevskiy 45b16d23a1 faiss: use autovectorization for inner product (#2712)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2712

Using autovectorization to get the proper urnolling.

Previous version timings are:

Before
```
faiss_ip_10000                        2.10us   475.62K
faiss_n2_10000                        4.23us   236.30K
```

After
```
faiss_ip_10000                         1.21us   827.16K
faiss_n2_10000                       640.68ns     1.56M
```

Reviewed By: alexanderguzhva

Differential Revision: D43353199

fbshipit-source-id: 8f73a34acd4b0368be6cdb05ba7a99a566c9ed83
2023-02-16 10:24:25 -08:00
generatedunixname89002005325676 fb88ea3976 Daily arc lint --take CLANGFORMAT
Reviewed By: 0x1eaf

Differential Revision: D43344501

fbshipit-source-id: 0adb4b573057a751057821af645b7802e29c06cd
2023-02-16 03:06:35 -08:00
Alexandr Guzhva 0519c048c2 implemented fvec_L2sqr_ny_y_transposed() plus an AVX2 code for it (#2696)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2696

Add fvec_L2sqr_ny_y_transposed() call which is used by ProductQuantizer in case of pq.sync_transposed_centroids() is enabled.

Reviewed By: mdouze

Differential Revision: D43057940

fbshipit-source-id: b82a0153fb10f1558c7db04e32d690b2ee7b9144
2023-02-15 13:00:05 -08:00
Alexandr Guzhva f937cef502 Improve fvec_op_ny_D4 for x64 (#2693)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2693

A new kernel for fvec_op_ny_D4 for x64 that reorganizes read ops.

This diff also introduces transpose microkernels for D2 and D8 for AVX2 for future needs.

Reviewed By: mdouze

Differential Revision: D43057318

fbshipit-source-id: 37b2e18139905fcdac69e4603038a15725a730dd
2023-02-15 13:00:05 -08:00
Alexandr Guzhva 875a5d4ac8 Improve IndexIVFPQ::scan_list_with_table and IndexIVFPQ::scan_list_polysemous_hc for x64 (#2694)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2694

Improves the performance of IVFPQ::scan_list_with_table() and IVFPQ::scan_list_polysemous_hc() by manually unrolling loops.

Reviewed By: mdouze

Differential Revision: D43056462

fbshipit-source-id: 326a394b7d9de4f576d165e0245852acc1fec310
2023-02-15 13:00:05 -08:00
Matthijs Douze a80c96c0de Evaluation script for hybrid CPU / GPU search
Summary:
Implementation of various combinations of coarse quantization / scaning code on CPU and GPU.

Used to generate the results of

https://github.com/facebookresearch/faiss/wiki/Hybrid-CPU-GPU-search-and-multiple-GPUs

Reviewed By: alexanderguzhva

Differential Revision: D43041802

fbshipit-source-id: 12608812ab351d60d4a6dc45be1ca493f76d4375
2023-02-15 12:55:06 -08:00
Matthijs Douze 1dc992bf26 IndexShards with common quantizer (#2682)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2682

IndexShards normally sees the indexes as opaque, so there is no way to factrorize the coarse quantizer.
This diff introduces IndexIVFShards that handles IVF indexes with a common quantizer so that the quantization is computed only once.

Reviewed By: alexanderguzhva

Differential Revision: D42781513

fbshipit-source-id: 441316eff4c1ba0468501c456af9194ea5f042d6
2023-02-15 06:48:47 -08:00
Alexandr Guzhva 868e17f294 OSS legal requirements (#2698)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2698

Add headers about copyright.

Reviewed By: algoriddle

Differential Revision: D43085637

fbshipit-source-id: 5a57876b7047097ffe01cd79322674625d9bca34
2023-02-07 14:32:56 -08:00
Alexandr Guzhva e7d5577dd0 Fix CircleCI format warnings (#2699)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2699

Remove a couple of blank lines

Reviewed By: algoriddle

Differential Revision: D43092258

fbshipit-source-id: 97a0e0a359562e93052d121ce4b5128b4f73524a
2023-02-07 12:17:42 -08:00
Matthijs Douze ab058456df Crop a ResidualCoarseQuantizer (#2683)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2683

Adds a small function and a test to demonstrate how to crop a RCQ to its first quantizers.
Also adds a SearchParameters to set the beam_factor of a RCQ.

Reviewed By: alexanderguzhva

Differential Revision: D42842378

fbshipit-source-id: b522269ce983cddc50c3d0e18b541954c5d7001d
2023-02-06 12:52:28 -08:00
Jeff Johnson 9f372ce7f8 Complete Faiss OSS legal requirements
Summary: Added the required terms of use, privacy policy and copyright statement for Meta OSS projects.

Reviewed By: algoriddle

Differential Revision: D43056233

fbshipit-source-id: 8541edd587107bf3129ff7f8b29ec26c016f779f
2023-02-06 12:39:57 -08:00
Jeff Johnson 43d3dcf061 Faiss GPU: Use 64-bit indexing arithmetic everywhere (#2685)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2685

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

This diff is an attempt at dealing with limitations when I originally wrote the Faiss GPU code back in 2016. Namely, 64 bit integer arithmetic was really slow on the GPU (this was also the impetus for me adding the 32 vs 64 bit indexing logic to PyTorch GPU), and GPUs at the time were very memory limited.

However, there have been enough cases where people are attempting to use Faiss GPU to handle larger datasets, especially including > 2 GB flat indexes, which sometimes worked (total number of elements in a tensor being < 2^31 - 1 but the byte size could be larger) or sometimes didn't work (when considering byte offsets not word sizes). This needed fixing.

This diff changes the `Tensor`, `HostTensor` and `DeviceTensor` classes to default to using `faiss::idx_t` as the index type (64 bit), and also changes many other places in the GPU code to follow the same data type. Much of the code being changed follows from the type propagation coming from the `Tensor` class and sub-classes.

`GpuIndexIVF.setNumProbes` and `GpuIndexIVF.getNumProbes` functions have been removed, just set/get `nprobe` on the object as need (like the CPU side).

The net result is that flat indexes can contain > 2 GB of data, and individual IVF lists can similarity contain > 2 GB of data, as well as any tensor dimension can be over 2G (excepting vector dimension; see limitations below).

Notes:

- performance for large `k` (>= 512) or large `nprobe` (>= 512) deteriorates due to low occupancy in the k-selection kernels due to increased register pressure (we now maintain all indices as int64 rather than int32, thus requiring double the registers). However, based on tests this doesn't hurt more than 10-20% or so at these large sizes. Small `k`/`nprobe` has no significant effect, and in some cases is even faster (depending upon if we needed to produce int64 indices but computations were done internally using int32).
- `k`, like with CPU Faiss, is an int parameter everywhere still.
- `d`, like with CPU Faiss, is an int parameter everywhere except for places where dimensionality is inferred from a tensor dimension (in which case it is naturally `idx_`).
- `nprobe`, like `IndexIVF`, is `size_t` at the top level (`GpuIndexIVF` class member) but internally to the code it is either `int` or `idx_t` depending upon the context (e.g., if `nprobe` is extracted from a tensor dimension, it is already `idx_t`).

In the Faiss GPU code however, `k` and `nprobe` are still limited to 2048 maximum at present.

Reviewed By: alexanderguzhva

Differential Revision: D40494090

fbshipit-source-id: 8581aff86ff25091b47e59f749adebebf2d3b160
2023-02-03 12:11:22 -08:00
Jeff Johnson 13ccc683d1 Faiss GPU: change DeviceVector reallocation heuristic (#2691)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2691

`faiss::gpu::DeviceVector<T>` (the GPU analogue of `std::vector`) is used in Faiss GPU to store IVF list data, among other things. `thrust::device_vector` could not be used at the time of the library's authorship due to lack of certain features (stream usage from what I recall).

Like `std::vector`, it involves a heuristic used to determine what the new vector capacity should be in order to allow for a particular number of elements. It previously has always rounded up allocation sizes to the next highest power of 2, thus incremental appending to a DeviceVector amortizes the cost of memory (re-)allocation and only infrequently results in full re-allocation.

However, this doubling behavior was not limited. While at small sizes of individual IVF lists, this doubling is not that much of an issue (and there is a reclaim memory function on indices to reclaim unused memory resulting from this amortization). However, when operating with data sets close to GPU memory limits, this doubling is dangerous, as attempting to allocate, say, a GpuIndexFlat with 4.x GB of vectors on a 8 GB GPU could run out of memory.

Now we introduce a new heuristic:

- below 4 M list sizes, we always double (as before);
- otherwise, below 128 M list sizes, we only increase by 1.25x;
- otherwise, the allocation made by DeviceVector is exactly sized to the size requested by the user.

Reviewed By: mdouze

Differential Revision: D42951571

fbshipit-source-id: 462d8af582725869ab5642b81e27db0e71774c6e
2023-02-02 11:21:05 -08:00
Gergely Szilvasy 72f52af6e4 iterable invlists support range search (#2681)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2681

1. added support for range search
2. refactored iterator to eliminate copying of codes

Reviewed By: mdouze

Differential Revision: D42841542

fbshipit-source-id: 188f950b2ca83b43009e7d7066cacf4221f773b3
2023-01-31 03:40:20 -08:00
Yinze 38593cdbfc fix typo (#2481)
Summary:
`ptointer` to `pointer`

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

Reviewed By: algoriddle

Differential Revision: D42806088

Pulled By: mlomeli1

fbshipit-source-id: 87ef2bbdf4e19d81f6984607ddbfc62012938658
2023-01-30 01:57:56 -08:00
Ikko Eltociear Ashimine 93cc1d7925 Fix typo in Dockerfile (#2648)
Summary:
necesary -> necessary

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

Reviewed By: alexanderguzhva

Differential Revision: D42805978

Pulled By: mlomeli1

fbshipit-source-id: 1d640918dfe85e79856b18ce718fb26bbb0c6a92
2023-01-27 08:56:37 -08:00
Gergely Szilvasy bff0b156be iterable inverted lists
Summary: Adding support for iterable inverted lists, eg.  key value stores.

Reviewed By: mdouze

Differential Revision: D42778489

fbshipit-source-id: 2236fb37a2c3ae4bc5b384c2e2325f405b673ac9
2023-01-27 07:42:34 -08:00
Matthijs Douze cf15b89786 indicate default values in class declaration (#2676)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2676

This is a cosmetic diff where default values for scalar fields are moved to the .h file where the object is declared rather than in the object constructor. The advantage is that it is easier to read the default value of a parameter from just the class.

Reviewed By: alexanderguzhva

Differential Revision: D42722205

fbshipit-source-id: 9d9bc4641068f6d6233f60f0a3a16ab793c94bb8
2023-01-26 09:39:47 -08:00
Matthijs Douze c74cf4f52f Support CPU quantizer parameters in GPU autotune
Summary:
IVF GPU indexes now support CPU quantizers.
In order for the the auto-tuning to support accessing the parameters of the quantizers, GpuAutoTune needs to be adapted.

Reviewed By: algoriddle

Differential Revision: D42633348

fbshipit-source-id: ef472855aa882ccde9d878ae09782204045e38c5
2023-01-24 11:24:47 -08:00
generatedunixname89002005325676 2ae369c276 Daily arc lint --take CLANGFORMAT
Differential Revision: D42496191

fbshipit-source-id: 6adcae2114498ecb0cc80984863e00b8ea36c2f6
2023-01-13 06:46:58 -08:00
Matthijs Douze 8fc3775472 building blocks for hybrid CPU / GPU search (#2638)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2638

This diff is a more streamlined way of searching IVF indexes with precomputed clusters.
This will be used for experiments with hybrid CPU / GPU search.

Reviewed By: algoriddle

Differential Revision: D41301032

fbshipit-source-id: a1d645fd0f2bf806454dfd04971edc0a6200d20d
2023-01-12 13:34:44 -08:00
Rico 1eb4f42639 fix c_api link error: undefined reference (#2660)
Summary:
detail error: undefined reference to `faiss_index_cpu_to_gpu_multiple_with_options'

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

Reviewed By: algoriddle

Differential Revision: D42471891

Pulled By: mdouze

fbshipit-source-id: 3316311ee7a3d856a764f1590372393bf51f11c6
2023-01-12 00:19:18 -08:00
Ji Bin 9c7ad74814 Adaptation for compile c_api with CUDA 12 (#2656)
Summary:
Closes https://github.com/facebookresearch/faiss/issues/2655

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

Reviewed By: algoriddle

Differential Revision: D42471852

Pulled By: mdouze

fbshipit-source-id: 72162acc1590e565cdfcbd78510ae757c396e970
2023-01-12 00:15:36 -08:00
chasingegg 62c7342db1 Enable precomputed table only if L2 quantizer and by_residual is true (#2659)
Summary:
Related issue https://github.com/facebookresearch/faiss/issues/2658

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

Reviewed By: algoriddle

Differential Revision: D42431369

Pulled By: mdouze

fbshipit-source-id: 4beeedd86e8090b499a3cd2931f3d9511bc49c51
2023-01-10 07:29:01 -08:00
pboueri 38bf321885 Missed import module throws unintended error (#2652)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2652

Reviewed By: algoriddle

Differential Revision: D42409264

Pulled By: mdouze

fbshipit-source-id: caf10d97a26a23aca240e67e38d449ca33c298c1
2023-01-09 03:40:36 -08:00
Matthijs Douze 75bd1fcacc Scan exactly max_codes elements (#2647)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2647

The `max_codes` search parameter for IVF indexes limits the number of distance computations that are performed.
Previously, the number of distance computations could exceed max_codes because inverted lists were scanned completely.
This diff changed this to scan the beginning of the last inverted list to reach `max_codes` exactly.

Reviewed By: alexanderguzhva

Differential Revision: D42367593

fbshipit-source-id: 67c88b93a407ab271397e913c5fa17104f4274c3
2023-01-09 00:11:07 -08:00
Alexandr Guzhva 135d3fdf43 about a magnitude faster LSQ/PLSQ training and encoding (#2650)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2650

LocalSearchQuantizer::icm_encode_step was optimized:
* The loop orders were changes
* Memory allocations were optimized
* Different order for accessing 'binaries' tensor, because it is symmetric
* SIMD for the lookup of the best code.

Results are unchanged.

Also, fixes incorrect test in test_local_search_quantizer.py

Reviewed By: mdouze

Differential Revision: D42352124

fbshipit-source-id: bf7e349f2123e6ee99e0776cf15ad5fc1cf2439a
2023-01-06 09:06:34 -08:00
Alexandr Guzhva bbab020925 Modify approximate heap facility to maintain the correct order as if the input elements were pushed into the heap sequentially (#2651)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2651

Modify approximate heap facility to maintain the correct order as if the input elements were pushed into the heap sequentially

Reviewed By: mdouze

Differential Revision: D42373532

fbshipit-source-id: 477dc8acd2567157e2b99076a566326821021c8c
2023-01-06 09:06:34 -08:00
chasingegg adc9d1a0cd Refactor prepare cache code in cmp_with_scann benchmark (#2573)
Summary:
In ```cmp_with_scann.py```, we will save npy file for base and query vector file and gt file. However, we will only do this while the lib is faiss, if we directly run this script with scann lib it will complain that file does not exsit.
Therefore, the code should be refactored to save npy file from the beginning so that nothing will go wrong.

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

Reviewed By: mdouze

Differential Revision: D42338435

Pulled By: algoriddle

fbshipit-source-id: 9227f95e1ff79f5329f6206a0cb7ca169185fdb3
2023-01-04 02:35:18 -08:00
chasingegg af833cd770 Fix some typos (#2645)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2645

Reviewed By: mdouze

Differential Revision: D42338453

Pulled By: algoriddle

fbshipit-source-id: 1ea5c33960a42c9e8624b10eba067e722d712e34
2023-01-04 02:18:09 -08:00
zh Wang f3577ab8c0 Fix inconsistency of parameter naming (#2542)
Summary:
There are two different names for the same thing and name inconsistency between the function declaration and definition which uses `M2` in the function declaration and uses `nsq` in the function definition. It may cause confusion, so it's better to unify them.

Signed-off-by: zh Wang <[email protected]>

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

Reviewed By: mdouze

Differential Revision: D42338110

Pulled By: algoriddle

fbshipit-source-id: d386e00fb8d8904051dd676bae1e7f4702a172d9
2023-01-04 02:07:35 -08:00
zh Wang 60c850e296 Fix hnsw benchmark (#2591)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2591

Reviewed By: mdouze

Differential Revision: D42337854

Pulled By: algoriddle

fbshipit-source-id: 222885fe0e1562deddd0f37c0dbedd1963c885e5
2023-01-04 01:49:09 -08:00
Alexandr Guzhva b9bf2490a3 Add facilities for approximate evaluation of min-k distances via heap. Affects RQ / PRQ / RQ_LUT / PRQ_LUT (#2633)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2633

The core idea.
Instead of putting every element of the dataset into MaxHeap, split the dataset into buckets and let every bucket track elements min-1, min-2 or min-3 distances.

Applied to ResidualQuantizer class for vector codec purposes.

An example
```
rq.approx_topk_mode = faiss.APPROX_TOPK_BUCKETS_B16_D2
```

Reviewed By: mdouze

Differential Revision: D42044398

fbshipit-source-id: 43169026476650442806a31d1c1aa2d5d5028e65
2023-01-03 14:39:11 -08:00
Gergely Szilvasy 05a9d52833 increase circleci no_output_timeout (#2644)
Summary:
Linux builds are regularly failing with “Too long with no output (exceeded 10m0s): context deadline exceeded”

https://app.circleci.com/pipelines/github/facebookresearch/faiss/3343/workflows/a6357953-bbaa-438c-acfa-2507ceb008e8/jobs/16680?invite=true#step-103-467

Applying the fix suggested in https://support.circleci.com/hc/en-us/articles/360045268074-Build-Fails-with-Too-long-with-no-output-exceeded-10m0s-context-deadline-exceeded-

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

Reviewed By: alexanderguzhva

Differential Revision: D42313426

Pulled By: algoriddle

fbshipit-source-id: 8e56c23f5f600974820c198d50562e043c909ce1
2023-01-03 13:22:30 -08:00
chasingegg 954fb0f802 Remove unused code (#2603)
Summary:
Fix https://github.com/facebookresearch/faiss/issues/2602

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

Reviewed By: mlomeli1

Differential Revision: D42315147

Pulled By: algoriddle

fbshipit-source-id: b92cfb2595b767ec317369546d34361a8ff5ea99
2023-01-03 12:40:38 -08:00
Matthijs Douze 74ee67aefc CodePacker for non-contiguous code layouts (#2625)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2625

This diff introduces a new abstraction for the code layouts that are not simply flat one after another.

The packed codes are assumed to be packed together in fixed-size blocks. Hence, code `#i` is stored at offset `i % nvec` of block `floor(i / nvec)`. Each block has size `block_size`.

The `CodePacker` object takes care of the translation between packed and flat codes. The packing / unpacking functions are virtual functions now, but they could as well be inlined for performance.

The `CodePacker` object makes it possible to do manipulations onarrays of codes (including inverted lists) in a uniform way, for example merging / adding / updating / removing / converting to&from CPU.

In this diff, the only non-trivial CodePacker implemnted is for the FastScan code. The new functionality supported is merging IVFFastScan indexes.

Reviewed By: alexanderguzhva

Differential Revision: D42072972

fbshipit-source-id: d1f8bdbcf7ab0f454b5d9c37ba2720fd191833d0
2022-12-21 11:06:53 -08:00
Alexandr Guzhva eaa67d8acf Speedup ResidualQuantizer sa_encode(), LUT=1 by avoiding r/w to a temporary buffer (#2599)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2599

Reviewed By: mdouze

Differential Revision: D41563612

fbshipit-source-id: 111f30e4aa8962709d1ef83cb78994e6e9639167
2022-12-19 11:41:01 -08:00
Alexandr Guzhva f163e39726 Further improve exhaustive_L2sqr_blas (#2626)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2626

Improves the performance of fused kernels used in exhaustive_L2sqr_blas() call. The code parameters are tweaked to utilize concurrently working ALU and LOAD/STORE units in a single CPU core.

The parameters values were tweaked for AVX2 and AVX512 kernels, but ARM ones remained unchanged because there was no way for me to benchmark the changes. Please feel free to alter ones if you have access to an ARM machine.

Reviewed By: mdouze

Differential Revision: D42079875

fbshipit-source-id: f1f7dc1759dbad57827d1c1b1b2b399322b33df0
2022-12-19 08:38:19 -08:00
Jeff Johnson 590f6fb47d Faiss pytorch bridge: revert to TypedStorage (#2631)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2631

The pytorch in fbcode complains about `storage()` saying it is deprecated and we need to move to UntypedStorage `_storage()`, while github CI is using an older version of pytorch where `_storage()` doesn't exist.

As it is only a warning not an error in fbcode, revert to the old form, but we'll likely have to change to `_storage()` eventually.

Reviewed By: alexanderguzhva

Differential Revision: D42107029

fbshipit-source-id: 699c15932e6ae48cd1c60ebb7212dcd9b47626f6
2022-12-16 15:38:08 -08:00
Jeff Johnson 4bb7aa4b77 Faiss + Torch fixes, re-enable k = 2048
Summary:
This diff fixes four separate issues:

- Using the pytorch bridge produces the following deprecation warning. We switch to `_storage()` instead.
```
torch_utils.py:51: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor._storage() instead of tensor.storage()
  x.storage().data_ptr() + x.storage_offset() * 4)
```
- The `storage_offset` for certain types was wrong, but this would only affect torch tensors that were a view into a storage that didn't begin at the beginning.
- The `reconstruct_n` numpy pytorch bridge function allowed passing `-1` for `ni` which indicated that all vectors should be reconstructed. The torch bridge didn't follow this and throw an error:
```
TypeError: torch_replacement_reconstruct_n() missing 2 required positional arguments: 'n0' and 'ni'
```
- Choosing values in the range (1024, 2048] for `k` or `nprobe` were broken in D37777979; this is now fixed again.

Reviewed By: alexanderguzhva

Differential Revision: D42041239

fbshipit-source-id: c7d9b4aba63db8ac73e271c8ef34e231002963d9
2022-12-14 16:21:22 -08:00