14 Commits

Author SHA1 Message Date
Lucas Hosseini
7212261a86 Fix docker build for GPU nightlies.
Reviewed By: wickedfoo

Differential Revision: D24670301

fbshipit-source-id: 5b19a9a88a880c20e51f6db1ce663224cf8d212c
2020-11-02 07:49:33 -08:00
Lucas Hosseini
04fde4032a Fix nightly build for GPU.
Reviewed By: wickedfoo

Differential Revision: D24559296

fbshipit-source-id: a9fbf51c5153b8b2dff4b2dd684cd84f5aaabc49
2020-10-26 22:33:52 -07:00
Jeff Johnson
8d776e6453 PyTorch tensor / Faiss index interoperability (#1484)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1484

This diff allows for native usage of PyTorch tensors for Faiss indexes on both CPU and GPU. It is currently only implemented in this diff for things that inherit from `faiss.Index`, which covers the non-binary indices, and it patches the same functions on `faiss.Index` that were also covered by `__init__.py` for numpy interoperability.

There must be uniformity among the inputs: if any array input is a Torch tensor, then all array inputs must be Torch tensors. Similarly, if any array input is a numpy ndarray, then all array inputs must be numpy ndarrays.

If `faiss.contrib.torch_utils` is imported, it ensures that `import faiss` has already been performed to patch all of the functions using the base `__init__.py` numpy wrappers, and then patches the following functions again:

```
add
add_with_ids
assign
train
search
remove_ids
reconstruct
reconstruct_n
range_search
update_vectors
search_and_reconstruct
sa_encode
sa_decode
```

to allow usage of PyTorch CPU tensors, and additionally PyTorch GPU tensors if the index being used is on the GPU.

numpy functionality is still available when `faiss.contrib.torch_utils` is imported; we pass through to the original patched numpy function when we detect numpy inputs.

In addition, to allow for better (asynchronous) GPU usage without requiring the CPU to be involved, all of these functions which construct tensors/arrays for output now take optional arguments for storage (numpy or torch.Tensor) to be provided that will contain the output data. `range_search` is the only exception to this, as the size of the output data is indeterminate. The eventual GPU implementation will likely require the user to provide a maximum cap on the output size, and allow that to be passed instead. If the optional pre-allocated output values are presented by the user, they are used; otherwise, new return ndarray / Tensors are constructed as before and used for the return. If this feature were not provided on the GPU, then every execution would be completely serial as we would depend upon the CPU to allocate GPU memory before every operation. Instead, now this can function much like NN graph execution on the GPU, assuming that all of the data requirements are pre-allocated, so the execution will run at the full speed of the GPU and not be stalled sequentially launching kernels.

This diff also exposes the `GpuResources` shared_ptr object owned by a GPU index. This is required for pytorch GPU so that we can perform proper stream ordering in Faiss with respect to the current pytorch stream. So, Faiss indices now perform more or less as any NN operation in Torch does.

Note, however, that a Faiss index has its own setting on current device, and if the pytorch GPU tensor inputs are resident on a different device than what the Faiss index expects, a cross-device copy will be initiated. I may choose to make this an error in the future and require matching device to device.

This diff also found a bug when passing GPU data directly to `train()` for `GpuIndexIVFFlat` and `GpuIndexIVFScalarQuantizer`, as I guess we never tested passing GPU data directly to these functions before. `GpuIndexIVFPQ` was doing the right thing however.

The assign function is now also implemented on the GPU as well, and is now marked `const` to be in line with the `search` function.

Also added better checking of non-contiguous inputs for both Torch tensors and numpy ndarrays.

Updated the `knn_gpu` function with a base implementation always present that allows for usage of numpy arrays, which is overridden when `torch_utils` is imported to allow torch usage. This supports row/column major layout, float32/float16 data and int64/int32 indices for both numpy and torch.

Reviewed By: mdouze

Differential Revision: D24299400

fbshipit-source-id: b4f117b9c120bd1ad83e7702087051ab7b303b29
2020-10-23 22:24:22 -07:00
Lucas Hosseini
bab6db84e0 Make pytorch available in CircleCI. (#1486)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1486

Reviewed By: wickedfoo

Differential Revision: D24493486

Pulled By: beauby

fbshipit-source-id: 00156213061503ff593b2e9ede062850b23527a9
2020-10-22 21:10:32 -07:00
Lucas Hosseini
7891094da6 Add nightly packages for GPU. (#1485)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1485

Test Plan: Imported from OSS

Reviewed By: wickedfoo

Differential Revision: D24492171

Pulled By: beauby

fbshipit-source-id: 20fbcbdd50ab30e110e41b34e0c07d88432b1422
2020-10-22 19:47:13 -07:00
Lucas Hosseini
64c13cdda3 Run python gpu tests. (#1479)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1479

Reviewed By: mdouze

Differential Revision: D24413984

Pulled By: beauby

fbshipit-source-id: 006343c996a278df1d9fc70e11283d31d63a0330
2020-10-22 09:56:30 -07:00
Lucas Hosseini
d1f72c5922 Remove guard for OSX packages.
Reviewed By: wickedfoo

Differential Revision: D24295557

fbshipit-source-id: 87608edba1c67f10ea11a4ceb73234ada7663bab
2020-10-13 19:44:26 -07:00
Lucas Hosseini
4a63f77fde Remove redundant jobs for releases.
Reviewed By: mdouze

Differential Revision: D24286656

fbshipit-source-id: 93c176e5c063f845114f76e2ac01dbad69b70fb5
2020-10-13 14:03:04 -07:00
Lucas Hosseini
882d4f1051 Fix conda build cmd for nightly packages.
Reviewed By: mdouze

Differential Revision: D24269549

fbshipit-source-id: 8e6800781ae54a67c1d2424611a761f838d12026
2020-10-12 22:17:11 -07:00
Lucas Hosseini
52c6465a5e Test reporting in CircleCI (#1452)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1452

Reviewed By: mdouze

Differential Revision: D24269693

Pulled By: beauby

fbshipit-source-id: a1a98d263ef4b20107c845421615b1f35b52c6e2
2020-10-12 22:13:31 -07:00
Lucas Hosseini
8e44bff055 Nightly builds (#1451)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1451

Reviewed By: mdouze

Differential Revision: D24245777

Pulled By: beauby

fbshipit-source-id: f2ce92b28e3d7ffdc2e85bcd78d321da15fec87e
2020-10-12 14:40:52 -07:00
Lucas Hosseini
9873376d8c Add GPU CI. (#1378)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1378

Reviewed By: mdouze

Differential Revision: D23370605

Pulled By: beauby

fbshipit-source-id: 6a9de47b6167ba8be12cce2735b1132991a190ab
2020-09-01 06:51:56 -07:00
Lucas Hosseini
3a9eb87af2 Windows CI + conda packaging. (#1377)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1377

Test Plan: Imported from OSS

Reviewed By: mdouze

Differential Revision: D23314728

Pulled By: beauby

fbshipit-source-id: fb74b1e832233aeeea47f3acdd606c6be65c143f
2020-08-25 16:58:25 -07:00
Lucas Hosseini
b7b261cad1 Move from TravisCI to CircleCI (#1315)
Summary:
Depends on https://github.com/facebookresearch/faiss/issues/1313.

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

Reviewed By: mdouze

Differential Revision: D23148557

Pulled By: beauby

fbshipit-source-id: 0a35f17d22aa04db6bd1c16cfc5ff8eee28f1f74
2020-08-15 04:00:51 -07:00