Merge pull request #168197 from SomeoneSerge/faiss

faiss: init at 1.7.2

authored by Jonas Heinrich and committed by GitHub 370e7d9b cb86b14f

+165
+123
pkgs/development/libraries/science/math/faiss/default.nix
···
··· 1 + { lib 2 + , config 3 + , fetchFromGitHub 4 + , stdenv 5 + , cmake 6 + , cudaPackages 7 + , cudaSupport ? config.cudaSupport or false 8 + , cudaCapabilities ? [ "60" "70" "80" "86" ] 9 + , pythonSupport ? true 10 + , pythonPackages 11 + , blas 12 + , swig 13 + , addOpenGLRunpath 14 + , optLevel ? let 15 + optLevels = 16 + lib.optional stdenv.hostPlatform.avx2Support "avx2" 17 + ++ lib.optional stdenv.hostPlatform.sse4_1Support "sse4" 18 + ++ [ "generic" ]; 19 + in 20 + # Choose the maximum available optimization level 21 + builtins.head optLevels 22 + , faiss # To run demos in the tests 23 + , runCommand 24 + }: 25 + 26 + let 27 + pname = "faiss"; 28 + version = "1.7.2"; 29 + inherit (cudaPackages) cudatoolkit; 30 + in 31 + stdenv.mkDerivation { 32 + inherit pname version; 33 + 34 + outputs = [ "out" "demos" ]; 35 + 36 + src = fetchFromGitHub { 37 + owner = "facebookresearch"; 38 + repo = pname; 39 + rev = "v${version}"; 40 + hash = "sha256-Tklf5AaqJbOs9qtBZVcxXPLAp+K54EViZLSOvEhmswg="; 41 + }; 42 + 43 + buildInputs = [ 44 + blas 45 + swig 46 + ] ++ lib.optionals pythonSupport [ 47 + pythonPackages.setuptools 48 + pythonPackages.pip 49 + pythonPackages.wheel 50 + ]; 51 + 52 + propagatedBuildInputs = lib.optionals pythonSupport [ 53 + pythonPackages.numpy 54 + ]; 55 + 56 + nativeBuildInputs = [ cmake ] ++ lib.optionals cudaSupport [ 57 + cudatoolkit 58 + addOpenGLRunpath 59 + ] ++ lib.optional pythonSupport [ 60 + pythonPackages.python 61 + ]; 62 + 63 + passthru.extra-requires.all = [ 64 + pythonPackages.numpy 65 + ]; 66 + 67 + cmakeFlags = [ 68 + "-DFAISS_ENABLE_GPU=${if cudaSupport then "ON" else "OFF"}" 69 + "-DFAISS_ENABLE_PYTHON=${if pythonSupport then "ON" else "OFF"}" 70 + "-DFAISS_OPT_LEVEL=${optLevel}" 71 + ] ++ lib.optionals cudaSupport [ 72 + "-DCMAKE_CUDA_ARCHITECTURES=${lib.concatStringsSep ";" cudaCapabilities}" 73 + ]; 74 + 75 + 76 + # pip wheel->pip install commands copied over from opencv4 77 + 78 + buildPhase = '' 79 + make -j faiss 80 + make demo_ivfpq_indexing 81 + '' + lib.optionalString pythonSupport '' 82 + make -j swigfaiss 83 + (cd faiss/python && 84 + python -m pip wheel --verbose --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist .) 85 + ''; 86 + 87 + installPhase = '' 88 + make install 89 + mkdir -p $demos/bin 90 + cp ./demos/demo_ivfpq_indexing $demos/bin/ 91 + '' + lib.optionalString pythonSupport '' 92 + mkdir -p $out/${pythonPackages.python.sitePackages} 93 + (cd faiss/python && python -m pip install dist/*.whl --no-index --no-warn-script-location --prefix="$out" --no-cache) 94 + ''; 95 + 96 + fixupPhase = lib.optionalString (pythonSupport && cudaSupport) '' 97 + addOpenGLRunpath $out/${pythonPackages.python.sitePackages}/faiss/*.so 98 + addOpenGLRunpath $demos/bin/* 99 + ''; 100 + 101 + passthru = { 102 + inherit cudaSupport cudaPackages pythonSupport; 103 + 104 + tests = { 105 + runDemos = runCommand "${pname}-run-demos" 106 + { buildInputs = [ faiss.demos ]; } 107 + # There are more demos, we run just the one that documentation mentions 108 + '' 109 + demo_ivfpq_indexing && touch $out 110 + ''; 111 + } // lib.optionalAttrs pythonSupport { 112 + pytest = pythonPackages.callPackage ./tests.nix { }; 113 + }; 114 + }; 115 + 116 + meta = with lib; { 117 + description = "A library for efficient similarity search and clustering of dense vectors by Facebook Research"; 118 + homepage = "https://github.com/facebookresearch/faiss"; 119 + license = licenses.mit; 120 + platforms = platforms.unix; 121 + maintainers = with maintainers; [ SomeoneSerge ]; 122 + }; 123 + }
+30
pkgs/development/libraries/science/math/faiss/tests.nix
···
··· 1 + { lib 2 + , buildPythonPackage 3 + , faiss 4 + , scipy 5 + , pytestCheckHook 6 + }: 7 + 8 + assert faiss.pythonSupport; 9 + 10 + buildPythonPackage { 11 + pname = "faiss-pytest-suite"; 12 + inherit (faiss) version; 13 + 14 + src = "${faiss.src}/tests"; 15 + 16 + dontBuild = true; 17 + dontInstall = true; 18 + 19 + # Tests that need GPUs and would fail in the sandbox 20 + disabledTestPaths = lib.optionals faiss.cudaSupport [ 21 + "test_contrib.py" 22 + ]; 23 + 24 + checkInputs = [ 25 + faiss 26 + pytestCheckHook 27 + scipy 28 + ] ++ 29 + faiss.extra-requires.all; 30 + }
+7
pkgs/top-level/all-packages.nix
··· 34575 jre = openjdk11; 34576 }; 34577 34578 fityk = callPackage ../applications/science/misc/fityk { }; 34579 34580 galario = callPackage ../development/libraries/galario { };
··· 34575 jre = openjdk11; 34576 }; 34577 34578 + faiss = callPackage ../development/libraries/science/math/faiss { 34579 + pythonPackages = python3Packages; 34580 + # faiss wants the "-doxygen" option 34581 + # available only since swig4 34582 + swig = swig4; 34583 + }; 34584 + 34585 fityk = callPackage ../applications/science/misc/fityk { }; 34586 34587 galario = callPackage ../development/libraries/galario { };
+5
pkgs/top-level/python-packages.nix
··· 3022 3023 factory_boy = callPackage ../development/python-modules/factory_boy { }; 3024 3025 fake-useragent = callPackage ../development/python-modules/fake-useragent { }; 3026 3027 faker = callPackage ../development/python-modules/faker { };
··· 3022 3023 factory_boy = callPackage ../development/python-modules/factory_boy { }; 3024 3025 + faiss = toPythonModule (pkgs.faiss.override { 3026 + pythonSupport = true; 3027 + pythonPackages = self; 3028 + }); 3029 + 3030 fake-useragent = callPackage ../development/python-modules/fake-useragent { }; 3031 3032 faker = callPackage ../development/python-modules/faker { };