Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

add feedstock for facebookresearch/faiss #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) Copyright IBM Corp. 2018, 2019. All Rights Reserved.
# (C) Copyright IBM Corp. 2018, 2020. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,11 +29,27 @@ branches:

matrix:
include:
- env: CONFIG=linux_noarch UPLOAD_PACKAGES=True DOCKER_IMAGE=ibmcom/powerai:1.6.2-pytorch-ubuntu18.04-py36-x86_64
- env: CONFIG=linux_ppc64le_python3.6 UPLOAD_PACKAGES=True DOCKER_IMAGE=ibmcom/powerai:1.7.0-dev-ubuntu18.04-py36-ppc64le
language: generic
os: linux
arch: ppc64le
language: generic

- env: CONFIG=linux_ppc64le_python3.7 UPLOAD_PACKAGES=True DOCKER_IMAGE=ibmcom/powerai:1.7.0-dev-ubuntu18.04-py37-ppc64le
language: generic
os: linux
arch: amd64
arch: ppc64le

- env: CONFIG=linux_python3.6 UPLOAD_PACKAGES=True DOCKER_IMAGE=ibmcom/powerai:1.7.0-dev-ubuntu18.04-py36-x86_64
language: generic
os: linux
arch: x86_64

- env: CONFIG=linux_python3.7 UPLOAD_PACKAGES=True DOCKER_IMAGE=ibmcom/powerai:1.7.0-dev-ubuntu18.04-py37-x86_64
language: generic
os: linux
arch: x86_64

script:
- "travis_wait 60 sleep 3600 &"
- ./conda-recipes/build_scripts/run_docker_build.sh pycox-feedstock
- "travis_wait 180 sleep 10800 &"
- ./conda-recipes/build_scripts/run_docker_build.sh faiss-gpu-feedstock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
c_compiler:
- gcc
c_compiler_version:
- '8'
channel_sources:
- defaults
channel_targets:
- powerai main
docker_image:
- ibmcom/powerai:1.7.0-dev-ubuntu18.04-py36-ppc64le
pin_run_as_build:
python:
min_pin: x.x
max_pin: x.x
python:
- '3.6'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
c_compiler:
- gcc
c_compiler_version:
- '8'
channel_sources:
- defaults
channel_targets:
- powerai main
docker_image:
- ibmcom/powerai:1.7.0-dev-ubuntu18.04-py37-ppc64le
pin_run_as_build:
python:
min_pin: x.x
max_pin: x.x
python:
- '3.7'
16 changes: 16 additions & 0 deletions conda-recipes/faiss-gpu-feedstock/.ci_support/linux_python3.6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
c_compiler:
- gcc
c_compiler_version:
- '8'
channel_sources:
- defaults
channel_targets:
- powerai main
docker_image:
- ibmcom/powerai:1.7.0-dev-ubuntu18.04-py36-x86_64
pin_run_as_build:
python:
min_pin: x.x
max_pin: x.x
python:
- '3.6'
16 changes: 16 additions & 0 deletions conda-recipes/faiss-gpu-feedstock/.ci_support/linux_python3.7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
c_compiler:
- gcc
c_compiler_version:
- '8'
channel_sources:
- defaults
channel_targets:
- powerai main
docker_image:
- ibmcom/powerai:1.7.0-dev-ubuntu18.04-py37-x86_64
pin_run_as_build:
python:
min_pin: x.x
max_pin: x.x
python:
- '3.7'
21 changes: 21 additions & 0 deletions conda-recipes/faiss-gpu-feedstock/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Facebook, Inc. and its affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions conda-recipes/faiss-gpu-feedstock/README-recipe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conda recipe adapted from the recipe in the upstream faiss repo:

https://github.com/facebookresearch/faiss/tree/master/conda/faiss-gpu
91 changes: 91 additions & 0 deletions conda-recipes/faiss-gpu-feedstock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Faiss

Faiss is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also contains supporting code for evaluation and parameter tuning. Faiss is written in C++ with complete wrappers for Python/numpy. Some of the most useful algorithms are implemented on the GPU. It is developed by [Facebook AI Research](https://research.fb.com/category/facebook-ai-research-fair/).

## NEWS

*NEW: version 1.6.1 (2019-11-29) bugfix.*

*NEW: version 1.6.0 (2019-10-15) code structure reorg, support for codec interface.*

*NEW: version 1.5.3 (2019-06-24) fix performance regression in IndexIVF.*

*NEW: version 1.5.2 (2019-05-27) the license was relaxed to MIT from BSD+Patents. Read LICENSE for details.*

*NEW: version 1.5.0 (2018-12-19) GPU binary flat index and binary HNSW index*

*NEW: version 1.4.0 (2018-08-30) no more crashes in pure Python code*

*NEW: version 1.3.0 (2018-07-12) support for binary indexes*

*NEW: latest commit (2018-02-22) supports on-disk storage of inverted indexes, see demos/demo_ondisk_ivf.py*

*NEW: latest commit (2018-01-09) includes an implementation of the HNSW indexing method, see benchs/bench_hnsw.py*

*NEW: there is now a Facebook public discussion group for Faiss users at https://www.facebook.com/groups/faissusers/*

*NEW: on 2017-07-30, the license on Faiss was relaxed to BSD from CC-BY-NC. Read LICENSE for details.*

## Introduction

Faiss contains several methods for similarity search. It assumes that the instances are represented as vectors and are identified by an integer, and that the vectors can be compared with L2 (Euclidean) distances or dot products. Vectors that are similar to a query vector are those that have the lowest L2 distance or the highest dot product with the query vector. It also supports cosine similarity, since this is a dot product on normalized vectors.

Most of the methods, like those based on binary vectors and compact quantization codes, solely use a compressed representation of the vectors and do not require to keep the original vectors. This generally comes at the cost of a less precise search but these methods can scale to billions of vectors in main memory on a single server.

The GPU implementation can accept input from either CPU or GPU memory. On a server with GPUs, the GPU indexes can be used a drop-in replacement for the CPU indexes (e.g., replace `IndexFlatL2` with `GpuIndexFlatL2`) and copies to/from GPU memory are handled automatically. Results will be faster however if both input and output remain resident on the GPU. Both single and multi-GPU usage is supported.

## Building

The library is mostly implemented in C++, with optional GPU support provided via CUDA, and an optional Python interface. The CPU version requires a BLAS library. It compiles with a Makefile and can be packaged in a docker image. See [INSTALL.md](INSTALL.md) for details.

## How Faiss works

Faiss is built around an index type that stores a set of vectors, and provides a function to search in them with L2 and/or dot product vector comparison. Some index types are simple baselines, such as exact search. Most of the available indexing structures correspond to various trade-offs with respect to

- search time
- search quality
- memory used per index vector
- training time
- need for external data for unsupervised training

The optional GPU implementation provides what is likely (as of March 2017) the fastest exact and approximate (compressed-domain) nearest neighbor search implementation for high-dimensional vectors, fastest Lloyd's k-means, and fastest small k-selection algorithm known. [The implementation is detailed here](https://arxiv.org/abs/1702.08734).

## Full documentation of Faiss

The following are entry points for documentation:

- the full documentation, including a [tutorial](https://github.com/facebookresearch/faiss/wiki/Getting-started), a [FAQ](https://github.com/facebookresearch/faiss/wiki/FAQ) and a [troubleshooting section](https://github.com/facebookresearch/faiss/wiki/Troubleshooting) can be found on the [wiki page](http://github.com/facebookresearch/faiss/wiki)
- the [doxygen documentation](http://rawgithub.com/facebookresearch/faiss/master/docs/html/annotated.html) gives per-class information
- to reproduce results from our research papers, [Polysemous codes](https://arxiv.org/abs/1609.01882) and [Billion-scale similarity search with GPUs](https://arxiv.org/abs/1702.08734), refer to the [benchmarks README](benchs/README.md). For [
Link and code: Fast indexing with graphs and compact regression codes](https://arxiv.org/abs/1804.09996), see the [link_and_code README](benchs/link_and_code)

## Authors

The main authors of Faiss are:
- [Hervé Jégou](https://github.com/jegou) initiated the Faiss project and wrote its first implementation
- [Matthijs Douze](https://github.com/mdouze) implemented most of the CPU Faiss
- [Jeff Johnson](https://github.com/wickedfoo) implemented all of the GPU Faiss
- [Lucas Hosseini](https://github.com/beauby) implemented the binary indexes

## Reference

Reference to cite when you use Faiss in a research paper:

```
@article{JDH17,
title={Billion-scale similarity search with GPUs},
author={Johnson, Jeff and Douze, Matthijs and J{\'e}gou, Herv{\'e}},
journal={arXiv preprint arXiv:1702.08734},
year={2017}
}
```

## Join the Faiss community

For public discussion of Faiss or for questions, there is a Facebook public discussion group at https://www.facebook.com/groups/faissusers/

We monitor the [issues page](http://github.com/facebookresearch/faiss/issues) of the repository. You can report bugs, ask questions, etc.

## License

Faiss is MIT-licensed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 65775f8725760e4bc7eb9b6b8ab8f9bdd6a26ed2 Mon Sep 17 00:00:00 2001
From: "Brian W. Hart" <[email protected]>
Date: Mon, 16 Mar 2020 20:21:31 +0000
Subject: [PATCH] add tolerance for ppc64le

numpy's CPU info dictionary does not have a 'flags' field on
ppc64le. Tolerate a lookup failure when checking for instruction
set to allow faiss to run on ppc64le.
---
python/faiss.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/python/faiss.py b/python/faiss.py
index 8973731..163e2cb 100644
--- a/python/faiss.py
+++ b/python/faiss.py
@@ -28,7 +28,7 @@ def instruction_set():
return "default"
elif platform.system() == "Linux":
import numpy.distutils.cpuinfo
- if "avx2" in numpy.distutils.cpuinfo.cpu.info[0]['flags']:
+ if "avx2" in numpy.distutils.cpuinfo.cpu.info[0].get('flags', ""):
return "AVX2"
else:
return "default"
--
1.8.3.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From f58b6330a636433ca8d80e9395dcdb29cbef09ba Mon Sep 17 00:00:00 2001
From: "Brian W. Hart" <[email protected]>
Date: Tue, 17 Mar 2020 19:10:52 +0000
Subject: [PATCH] faiss: update CUDA include path for WML CE cudatoolkit
packages

For building against WML CE cudatoolkit packages, we can always
expect to find the CUDA headers in the top-level include/
directory of the build environment.
---
makefile.inc.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/makefile.inc.in b/makefile.inc.in
index 19d8511..fde9eb7 100644
--- a/makefile.inc.in
+++ b/makefile.inc.in
@@ -16,7 +16,7 @@ SWIGFLAGS = -DSWIGWORDSIZE64
NVCC = @NVCC@
CUDA_ROOT = @CUDA_PREFIX@
CUDA_ARCH = @CUDA_ARCH@
-NVCCFLAGS = -I $(CUDA_ROOT)/targets/x86_64-linux/include/ \
+NVCCFLAGS = -I $(CUDA_ROOT)/include/ \
-Xcompiler -fPIC \
-Xcudafe --diag_suppress=unrecognized_attribute \
$(CUDA_ARCH) \
--
1.8.3.1

23 changes: 23 additions & 0 deletions conda-recipes/faiss-gpu-feedstock/recipe/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -ex

ARCH=`uname -p`
if [[ "${ARCH}" == 'x86_64' ]]; then
# Build avx2 version
CXXFLAGS="-mavx2 -mf16c" ./configure --with-cuda=$PREFIX
make -j $CPU_COUNT
make -C python _swigfaiss_avx2.so
make clean
fi

# Build vanilla version (no avx)
./configure --with-cuda=$PREFIX
make -j $CPU_COUNT
make -C python _swigfaiss.so

make -C python build

cd python

$PYTHON setup.py install --single-version-externally-managed --record=record.txt
45 changes: 45 additions & 0 deletions conda-recipes/faiss-gpu-feedstock/recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% set version = "1.6.2" %}

package:
name: faiss-gpu
version: {{ version }}

source:
url: https://github.com/facebookresearch/faiss/archive/v{{ version }}.tar.gz
sha256: 8be8fcb943e94a93fb0796cad02a991432c0d912d8ae946f4beb5a8a9c5d4932
patches:
- 0001-add-tolerance-for-ppc64le.patch
- 0001-faiss-update-CUDA-include-path-for-WML-CE-cudatoolki.patch

requirements:
build:
- {{ compiler('cxx') }}
- make
- setuptools
- swig
- patch

host:
- python {{ python }}
- numpy 1.17.*
- libopenblas # [ppc64le]
- mkl >=2018 # [x86_64]
- cudatoolkit ==10.2.*
- cudatoolkit-dev ==10.2.*
run:
- python {{ python }}
- numpy 1.17.*
- libopenblas # [ppc64le]
- mkl >=2018 # [x86_64]
- blas=*=mkl # [x64_64]
- {{ pin_compatible('cudatoolkit', max_pin='x.x') }}

build:
number: 0

about:
home: https://github.com/facebookresearch/faiss
license: MIT
license_family: MIT
license_file: LICENSE
summary: A library for efficient similarity search and clustering of dense vectors.