diff options
Diffstat (limited to 'gnu/packages/machine-learning.scm')
-rw-r--r-- | gnu/packages/machine-learning.scm | 292 |
1 files changed, 175 insertions, 117 deletions
diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm index c32180615b..fd0be8d500 100644 --- a/gnu/packages/machine-learning.scm +++ b/gnu/packages/machine-learning.scm @@ -55,12 +55,14 @@ #:use-module (gnu packages) #:use-module (gnu packages adns) #:use-module (gnu packages algebra) + #:use-module (gnu packages assembly) #:use-module (gnu packages audio) #:use-module (gnu packages autotools) #:use-module (gnu packages base) #:use-module (gnu packages bash) #:use-module (gnu packages boost) #:use-module (gnu packages bdw-gc) + #:use-module (gnu packages c) #:use-module (gnu packages check) #:use-module (gnu packages compression) #:use-module (gnu packages cmake) @@ -89,6 +91,7 @@ #:use-module (gnu packages ninja) #:use-module (gnu packages ocaml) #:use-module (gnu packages onc-rpc) + #:use-module (gnu packages opencl) #:use-module (gnu packages parallel) #:use-module (gnu packages perl) #:use-module (gnu packages pkg-config) @@ -100,6 +103,7 @@ #:use-module (gnu packages python-science) #:use-module (gnu packages python-web) #:use-module (gnu packages python-xyz) + #:use-module (gnu packages regex) #:use-module (gnu packages rpc) #:use-module (gnu packages serialization) #:use-module (gnu packages sphinx) @@ -108,6 +112,7 @@ #:use-module (gnu packages swig) #:use-module (gnu packages time) #:use-module (gnu packages tls) + #:use-module (gnu packages vulkan) #:use-module (gnu packages video) #:use-module (gnu packages web) #:use-module (gnu packages xml) @@ -115,6 +120,37 @@ #:use-module (gnu packages xorg) #:use-module (ice-9 match)) +(define-public fasttext + (package + (name "fasttext") + (version "0.9.2") + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/facebookresearch/fastText") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 + (base32 "07cz2ghfq6amcljaxpdr5chbd64ph513y8zqmibfx2xwfp74xkhn")))) + (build-system cmake-build-system) + ;; Tests require downloading of test data. + (arguments (list #:tests? #false)) + (home-page "https://github.com/facebookresearch/fastText") + (synopsis "Library for fast text representation and classification") + (description "fastText is a library for efficient learning of word +representations and sentence classification.") + (license license:expat))) + +(define-public python-fasttext + (package + (inherit fasttext) + (name "python-fasttext") + (build-system pyproject-build-system) + (propagated-inputs (list python-numpy python-scipy)) + (inputs (list fasttext)) + (native-inputs (list pybind11)))) + (define-public fann ;; The last release is >100 commits behind, so we package from git. (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7")) @@ -1194,7 +1230,7 @@ I/O.") (define-public gemmlowp - (let ((commit "f9959600daa42992baace8a49544a00a743ce1b6") + (let ((commit "08e4bb339e34017a0835269d4a37c4ea04d15a69") (version "0.1") (revision "1")) (package @@ -1207,13 +1243,14 @@ I/O.") (file-name (git-file-name name version)) (sha256 (base32 - "1hzfhlhzcb827aza6a7drydc67dw5fm3qfqilb9ibskan8dsf0c6")))) + "1q8f3w5slxd8fbn31hpm00y6wyp7gm71rzr27cmcff4b3px4ca6k")))) (arguments `(#:configure-flags (list ,@(match (%current-system) ((or "x86_64-linux" "i686-linux") '("-DCMAKE_CXX_FLAGS=-msse2")) - (_ '()))) + (_ '())) + "-DBUILD_SHARED_LIBS=ON") #:phases (modify-phases %standard-phases ;; This directory contains the CMakeLists.txt. @@ -1993,13 +2030,13 @@ discrete, and conditional dimensions.") (define-public python-deepxde (package (name "python-deepxde") - (version "1.9.2") + (version "1.9.3") (source (origin (method url-fetch) (uri (pypi-uri "DeepXDE" version)) (sha256 (base32 - "07bz3d7d698l0fhznw5l8p16b22d4ly7xq99vrgv48c722qr2r5b")))) + "1zw2gqssc0s3maf4gdjckxmzx1d3036hbp1iir26kd08hxj93vzs")))) (build-system pyproject-build-system) (arguments (list #:tests? #f ; there are no tests @@ -2935,7 +2972,7 @@ advanced research.") (define-public tensorflow-lite (package (name "tensorflow-lite") - (version "2.5.0") + (version "2.12.1") (source (origin (method git-fetch) @@ -2945,97 +2982,141 @@ advanced research.") (file-name (git-file-name name version)) (sha256 (base32 - "1jdw2i1rq06zqd6aabh7bbm0avsg4pygnfmd7gviv0blhih9054l")))) + "0jkgljdagdqllnxygl35r5bh3f9qmbczymfj357gm9krh59g2kmd")))) (build-system cmake-build-system) (arguments - `(#:tests? #false ; no "check" target - #:build-type "Release" - #:configure-flags - (list - "-DTFLITE_ENABLE_GPU=OFF" - "-DTFLITE_ENABLE_RUY=OFF" - - ;; TODO: The build system attempts to build xnnpack from source. We - ;; would like to use our xnnpack package here, but this requires more - ;; work. - "-DTFLITE_ENABLE_XNNPACK=OFF" - - ;; Pretend we've already fetched abseil. We won't actually build it - ;; but use the existing package. - "-Dabseil-cpp_POPULATED=TRUE" - - ;; Don't fetch the sources. We have already built flatbuffers. - "-Dflatbuffers_POPULATED=TRUE" - - "-DFFT2D_SOURCE_DIR=/tmp/fft2d" - "-Dneon2sse_SOURCE_DIR=/tmp/neon2sse" - "-Dneon2sse_BINARY_DIR=/tmp/neon2sse-bin" - "-DFARMHASH_SOURCE_DIR=/tmp/farmhash" - "-Dgemmlowp_SOURCE_DIR=/tmp/gemmlowp" - (string-append "-DRUY_SOURCE_DIR=" - (assoc-ref %build-inputs "ruy-src"))) - #:phases - (modify-phases %standard-phases - (add-after 'unpack 'chdir - (lambda _ (chdir "tensorflow/lite"))) - (add-after 'chdir 'copy-sources - (lambda* (#:key inputs #:allow-other-keys) - ;; Use external cmake finders instead of these stubs that won't - ;; find anything but the bundled sources. - (delete-file "tools/cmake/modules/Findabsl.cmake") - (delete-file "tools/cmake/modules/Findeigen.cmake") - - (substitute* "CMakeLists.txt" - (("find_package\\(eigen REQUIRED") - "find_package(eigen REQUIRED NAMES Eigen3")) - (substitute* "tools/cmake/modules/Findflatbuffers.cmake" - (("get_target_property.*") - (format #false "set(FLATBUFFERS_INCLUDE_DIRS ~a/include)\n" - (assoc-ref inputs "flatbuffers")))) - - ;; Don't fetch source code; we already have everything we need. - (substitute* '("tools/cmake/modules/fft2d.cmake" - "tools/cmake/modules/ruy.cmake" - "tools/cmake/modules/farmhash.cmake" - "tools/cmake/modules/neon2sse.cmake" - "tools/cmake/modules/gemmlowp.cmake") - (("OverridableFetchContent_Populate.*") "")) - - (mkdir-p "/tmp/farmhash") - (with-directory-excursion "/tmp/farmhash" - (invoke "tar" "--strip-components=1" - "-xf" (assoc-ref inputs "farmhash-src"))) - - (mkdir-p "/tmp/fft2d") - (with-directory-excursion "/tmp/fft2d" - (invoke "tar" "--strip-components=1" - "-xf" (assoc-ref inputs "fft2d-src"))) - - (copy-recursively (assoc-ref inputs "neon2sse-src") - "/tmp/neon2sse/") - (copy-recursively (assoc-ref inputs "gemmlowp-src") - "/tmp/gemmlowp/"))) - (add-after 'copy-sources 'prepare-shared-library-build - (lambda _ (chdir "c"))) - (replace 'install - (lambda* (#:key outputs #:allow-other-keys) - (let* ((out (assoc-ref outputs "out")) - (lib (string-append out "/lib")) - (headers (string-append out "/include/tensorflow/lite"))) - (install-file "../build/libtensorflowlite_c.so" lib) - (with-directory-excursion ".." - (for-each - (lambda (file) - (let ((target-dir (string-append headers "/" (dirname file)))) - (install-file file target-dir))) - (find-files "." "\\.h$"))))))))) + (list + #:tests? #false ;tests are not building now + #:build-type "Release" + #:modules '((ice-9 match) + (guix build utils) + (guix build cmake-build-system)) + #:configure-flags + #~(list + ;; "-DTFLITE_KERNEL_TEST=ON" ; TODO: build tests + ;; so cmake can be used to find this from other packages + "-DTFLITE_ENABLE_INSTALL=ON" + + ;; Use Guix's own packages as dependencies. + "-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON" + + "-DTFLITE_ENABLE_GPU=ON" + "-DTFLITE_ENABLE_RUY=ON" + + ;; TODO: turn on Farmhash + ;;"-DSYSTEM_FARMHASH=ON" + (string-append "-Dabsl_DIR=" #$(this-package-input "abseil-cpp") + "/lib/cmake/absl") + (string-append "-DEigen3_DIR=" #$(this-package-input "eigen") + "/share/eigen3/cmake") + (string-append "-DFlatBuffers_DIR=" + #$(this-package-input "flatbuffers-shared") + "/lib/cmake/flatbuffers") + (string-append "-DNEON_2_SSE_DIR=" #$(this-package-input "neon2sse") + "/lib/cmake/NEON_2_SSE") + (string-append "-Dcpuinfo_DIR=" #$(this-package-input "cpuinfo") + "/share/cpuinfo") + (string-append "-Druy_DIR=" #$(this-package-input "ruy") + "/lib/cmake/ruy") + + ;; TODO: The build system attempts to build xnnpack from source. We + ;; would like to use our xnnpack package here, but this requires more + ;; work. + "-DTFLITE_ENABLE_XNNPACK=OFF" + + ;; Don't fetch the sources. We have these already + "-Degl_headers_POPULATED=TRUE" + "-Dfp16_headers_POPULATED=TRUE" + "-Dopencl_headers_POPULATED=TRUE" + "-Dopengl_headers_POPULATED=TRUE" + "-Dvulkan_headers_POPULATED=TRUE" + "-Dgoogletest_POPULATED=TRUE" + "-Dgoogle_benchmark_POPULATED=TRUE" + "-Dnsync_POPULATED=TRUE" + "-Dre2_POPULATED=TRUE" + + "-DFFT2D_SOURCE_DIR=/tmp/fft2d" + "-DFARMHASH_SOURCE_DIR=/tmp/farmhash" + "-Dgemmlowp_SOURCE_DIR=/tmp/gemmlowp") + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'chdir + (lambda _ (chdir "tensorflow/lite"))) + (add-after 'chdir 'copy-sources + (lambda* (#:key inputs #:allow-other-keys) + ;; TODO: properly use Guix's pthreaqdpool. We are not using + ;; pthreadpool because we are not enabling xnnpack + (substitute* "CMakeLists.txt" + (("if\\(NOT DEFINED PTHREADPOOL_SOURCE_DIR\\)") + "if(false)")) + (substitute* "CMakeLists.txt" + (("if\\(NOT TARGET pthreadpool\\)") + "if(false)")) + + ;; Don't fetch source code; we already have everything we need. + (substitute* '("tools/cmake/modules/fft2d.cmake" + "tools/cmake/modules/farmhash.cmake" + "tools/cmake/modules/gemmlowp.cmake") + (("OverridableFetchContent_Populate.*") "")) + + (mkdir-p "/tmp/farmhash") + (with-directory-excursion "/tmp/farmhash" + (invoke "tar" "--strip-components=1" + "-xf" (assoc-ref inputs "farmhash-src"))) + + (mkdir-p "/tmp/fft2d") + (with-directory-excursion "/tmp/fft2d" + (invoke "tar" "--strip-components=1" + "-xf" (assoc-ref inputs "fft2d-src"))) + + (copy-recursively (assoc-ref inputs "gemmlowp-src") + "/tmp/gemmlowp/"))) + + (add-after 'build 'build-shared-library + (lambda* (#:key configure-flags #:allow-other-keys) + (mkdir-p "c") + (with-directory-excursion "c" + (apply invoke "cmake" (append configure-flags (list "../../lite/c"))) + (invoke "cmake" "--build" "." "-j" (number->string + (parallel-job-count)))))) + (add-after 'build-shared-library 'build-benchmark-model + (lambda _ + (invoke "cmake" "--build" "." "--target" "benchmark_model" + "-j" (number->string (parallel-job-count))))) + + (add-after 'install 'install-extra + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (lib (string-append out "/lib")) + (bin (string-append out "/bin"))) + (install-file "../build/c/libtensorflowlite_c.so" lib) + (install-file "../build/tools/benchmark/benchmark_model" bin)))) + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + (invoke "ctest" "-L" "plain"))))))) (inputs `(("abseil-cpp" ,abseil-cpp-20200923.3) - ("eigen" ,eigen-for-tensorflow-lite) - ("flatbuffers" ,flatbuffers) - ("python" ,python))) + ("cpuinfo" ,cpuinfo) + ("eigen" ,eigen) + ("fp16" ,fp16) + ("flatbuffers-shared" ,flatbuffers-next-shared) + ;;("gemmlowp" ,gemmlowp) ; TODO + ("mesa-headers" ,mesa-headers) + ("neon2sse" ,neon2sse) + ("nsync" ,nsync) + ("opencl-clhpp" ,opencl-clhpp) + ("opencl-headers" ,opencl-headers) + ("opencl-icd-loader" ,opencl-icd-loader) + ("pthreadpool" ,pthreadpool) + ("python" ,python) + ("ruy" ,ruy) + ("re2" ,re2) + ;;("xnnpack" ,xnnpack) ; TODO: use Guix's copy of xnnpack + ("vulkan-headers" ,vulkan-headers))) (native-inputs `(("pkg-config" ,pkg-config) + ("googletest" ,googletest) ("gemmlowp-src" ;; The commit hash is taken from ;; "tensorflow/lite/tools/cmake/modules/gemmlowp.cmake". @@ -3049,17 +3130,6 @@ advanced research.") (sha256 (base32 "1sbp8kmr2azwlvfbzryy1frxi99jhsh1nc93bdbxdf8zdgpv0kxl"))))) - ("neon2sse-src" - ,(let ((commit "a1652fd5253afbf3e39357b012974f93511f6108")) - (origin - (method git-fetch) - (uri (git-reference - (url "https://github.com/intel/ARM_NEON_2_x86_SSE") - (commit commit))) - (file-name (git-file-name "neon2sse" (string-take commit 8))) - (sha256 - (base32 - "1q8gkxag9wlnwdwad2pclsrkwzrdjy94hyrkayrsvxyj7szb5y8i"))))) ("farmhash-src" ,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45")) (origin @@ -3075,24 +3145,12 @@ advanced research.") ,(origin (method url-fetch) (uri (string-append "https://storage.googleapis.com/" - "mirror.tensorflow.org/" - "www.kurims.kyoto-u.ac.jp/~ooura/fft2d.tgz")) + "mirror.tensorflow.org/github.com/petewarden/" + "OouraFFT/archive/v1.0.tar.gz")) (file-name "fft2d.tar.gz") (sha256 (base32 - "1jfflzi74fag9z4qmgwvp90aif4dpbr1657izmxlgvf4hy8fk9xd")))) - ("ruy-src" - ,(let ((commit "9c56af3fce210a8a103eda19bd6f47c08a9e3d90")) - (origin - (method git-fetch) - (uri (git-reference - (url "https://github.com/google/ruy") - (commit commit) - (recursive? #true))) - (file-name (git-file-name "ruy" (string-take commit 8))) - (sha256 - (base32 - "1cfd5gk6kaj8kbl3h98gx1ap8czd59y6p8qq8nr28fklpyzf5cis"))))))) + "1jfflzi74fag9z4qmgwvp90aif4dpbr1657izmxlgvf4hy8fk9xd")))))) (home-page "https://tensorflow.org") (synopsis "Machine learning framework") (description |