summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2023-10-25 11:10:51 +0200
committerRicardo Wurmus <rekado@elephly.net>2023-10-25 11:10:51 +0200
commit94d5b82ce8cf684a6eb72562243b7fc96dd9892c (patch)
tree7f22ed2e1293928b0bfb2eda1e7096c23cc61f4c
parent6e451ee211558a03499b97c81c3bb51e7d8336df (diff)
python: Add python-tensorflow.
* guix-science/packages/python.scm (python-tensorflow): New variable.
-rw-r--r--guix-science/packages/python.scm84
1 files changed, 84 insertions, 0 deletions
diff --git a/guix-science/packages/python.scm b/guix-science/packages/python.scm
index c93f475..c9ec380 100644
--- a/guix-science/packages/python.scm
+++ b/guix-science/packages/python.scm
@@ -26,11 +26,13 @@
26 #:use-module (gnu packages check) 26 #:use-module (gnu packages check)
27 #:use-module (gnu packages compression) 27 #:use-module (gnu packages compression)
28 #:use-module (gnu packages curl) 28 #:use-module (gnu packages curl)
29 #:use-module (gnu packages elf)
29 #:use-module (gnu packages graph) 30 #:use-module (gnu packages graph)
30 #:use-module (gnu packages icu4c) 31 #:use-module (gnu packages icu4c)
31 #:use-module (gnu packages image) 32 #:use-module (gnu packages image)
32 #:use-module (gnu packages java) 33 #:use-module (gnu packages java)
33 #:use-module (gnu packages linux) 34 #:use-module (gnu packages linux)
35 #:use-module (gnu packages llvm)
34 #:use-module (gnu packages maths) 36 #:use-module (gnu packages maths)
35 #:use-module (gnu packages mpi) 37 #:use-module (gnu packages mpi)
36 #:use-module (gnu packages pdf) 38 #:use-module (gnu packages pdf)
@@ -1695,3 +1697,85 @@ including both a sequential API for beginners that allows users to
1695build models quickly by plugging together building blocks and a 1697build models quickly by plugging together building blocks and a
1696subclassing API with an imperative style for advanced research.") 1698subclassing API with an imperative style for advanced research.")
1697 (license license:asl2.0))) 1699 (license license:asl2.0)))
1700
1701(define-public python-tensorflow
1702 (package
1703 (inherit tensorflow)
1704 (name "python-tensorflow")
1705 (source #f)
1706 (build-system pyproject-build-system)
1707 (arguments
1708 (list
1709 #:tests? #false
1710 #:phases
1711 #~(modify-phases %standard-phases
1712 (replace 'unpack
1713 (lambda _
1714 (mkdir-p "source")
1715 (copy-recursively #$tensorflow:python "source")
1716 (chdir "source")
1717 ;; XXX: the "python" output of the tensorflow package
1718 ;; contains broken symlinks.
1719 (delete-file-recursively "third_party/eigen3")
1720 (mkdir-p "third_party/eigen3")
1721 (copy-recursively #$eigen-for-python-ml-dtypes
1722 "third_party/eigen3")
1723 (with-output-to-file "third_party/eigen3/LICENSE"
1724 (lambda () (display "")))))
1725 (add-after 'unpack 'relax-dependencies
1726 (lambda _
1727 (substitute* "setup.py"
1728 ;; We don't have tensorflow-io yet
1729 (("'tensorflow-io-gcs-filesystem.*") "None,")
1730 (("'platform_system.*") "")
1731 ;; Versions above 0.4 break tests, but that's okay
1732 ;; because we aren't running them.
1733 (("gast >= 0.2.1, <= 0.4.0") "gast >= 0.2.1")
1734 ;; Drop all of tensorboard, keras, and tensorflow_estimator
1735 (("'(keras|tensorboard|tensorflow_estimator) >.*',") " None,")
1736 ;; Our clang bindings have a different name.
1737 (("libclang") "clang")
1738 ;; No tensorboard, sorry.
1739 (("standard_or_nightly\\('tensorboard = tensorboard.main:run_main', None\\),") "")
1740 (("'import_pb_to_tensorboard = tensorflow.python.tools.import_pb_to_tensorboard:main',") "")
1741 ;; We don't have tensorflow-estimator yet.
1742 (("'estimator_ckpt_converter = '") "")
1743 (("'tensorflow_estimator.python.estimator.tools.checkpoint_converter:main',") ""))))
1744 ;; XXX: this is really ugly, but many shared objects cannot
1745 ;; find libtensorflow_framework.so.2 and libbfloat16.so.so
1746 (add-after 'unpack 'find-tensorflow-libraries
1747 (lambda _
1748 ;; XXX: not all .so files need this.
1749 (let ((libraries (find-files "." ".*\\.so$")))
1750 (for-each (lambda (lib)
1751 (make-file-writable lib)
1752 (system (format #false
1753 "patchelf --set-rpath ~a:~a:$(patchelf --print-rpath ~a) ~a"
1754 ;; for libtensorflow_framework.so.2
1755 (string-append
1756 #$(this-package-input "tensorflow")
1757 "/lib")
1758 ;; for libbfloat16.so.so
1759 (string-append
1760 #$output
1761 "/lib/python3.10/site-packages/tensorflow/tsl/python/lib/core/")
1762 lib lib)))
1763 libraries))))
1764 (add-after 'install 'install-missing-libraries
1765 (lambda _
1766 ;; libtensorflow_cc.so.2 is not installed. See
1767 ;; https://github.com/tensorflow/tensorflow/issues/60326.
1768 (let ((dir (string-append #$output "/lib/python3.10/site-packages/tensorflow/"))
1769 (lib (string-append "libtensorflow_cc.so." #$(package-version this-package))))
1770 (install-file (string-append "tensorflow/" lib) dir)
1771 (with-directory-excursion dir
1772 (symlink lib "libtensorflow_cc.so.2"))))))))
1773 (outputs '("out"))
1774 (propagated-inputs
1775 (modify-inputs (package-propagated-inputs tensorflow)
1776 (append python-clang-13)))
1777 (inputs (list tensorflow))
1778 (native-inputs
1779 (list eigen-for-python-ml-dtypes
1780 patchelf
1781 `(,tensorflow "python")))))