summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-science/packages/python.scm295
1 files changed, 295 insertions, 0 deletions
diff --git a/guix-science/packages/python.scm b/guix-science/packages/python.scm
index 879652b..9887b7d 100644
--- a/guix-science/packages/python.scm
+++ b/guix-science/packages/python.scm
@@ -32,6 +32,7 @@
32 #:use-module (gnu packages maths) 32 #:use-module (gnu packages maths)
33 #:use-module (gnu packages mpi) 33 #:use-module (gnu packages mpi)
34 #:use-module (gnu packages pdf) 34 #:use-module (gnu packages pdf)
35 #:use-module (gnu packages perl)
35 #:use-module (gnu packages protobuf) 36 #:use-module (gnu packages protobuf)
36 #:use-module (gnu packages python) 37 #:use-module (gnu packages python)
37 #:use-module (gnu packages python-build) 38 #:use-module (gnu packages python-build)
@@ -1322,3 +1323,297 @@ reverse-mode differentiation (a.k.a. backpropagation) via grad as well
1322as forward-mode differentiation, and the two can be composed 1323as forward-mode differentiation, and the two can be composed
1323arbitrarily to any order.") 1324arbitrarily to any order.")
1324 (license license:asl2.0))) 1325 (license license:asl2.0)))
1326
1327(define-public python-tensorflow
1328 (package
1329 (name "python-tensorflow")
1330 (version "2.13.1")
1331 (source
1332 (origin
1333 (method git-fetch)
1334 (uri (git-reference
1335 (url "https://github.com/tensorflow/tensorflow/")
1336 (commit (string-append "v" version))))
1337 (file-name (git-file-name name version))
1338 (sha256
1339 (base32 "09mfskmpvpbq919wibnw3bnhi1y3hkx3qrzm72gdr0gsivn1yb3w"))))
1340 (build-system gnu-build-system)
1341 (arguments
1342 (list
1343 #:modules
1344 '((guix build gnu-build-system)
1345 (guix build utils)
1346 (srfi srfi-1)
1347 (ice-9 string-fun))
1348 #:tests? #false ;there are none
1349 #:phases
1350 #~(modify-phases %standard-phases
1351 (replace 'configure
1352 (lambda* (#:key inputs #:allow-other-keys)
1353 (define bazel-out
1354 (string-append (getenv "NIX_BUILD_TOP") "/output"))
1355 (mkdir-p bazel-out)
1356 (with-directory-excursion bazel-out
1357 (invoke "tar" "xf" #$(bazel-vendored-inputs
1358 #:source (package-source this-package)
1359 #:name "tensorflow"
1360 #:version version
1361 #:inputs
1362 (append (standard-packages)
1363 (package-inputs this-package)
1364 (package-propagated-inputs this-package)
1365 (package-native-inputs this-package))
1366 #:search-paths
1367 (map search-path-specification->sexp
1368 (package-transitive-native-search-paths
1369 this-package))
1370 #:extra-configuration
1371 (with-imported-modules (source-module-closure '((guix build utils)
1372 (guix build union)
1373 (guix build gnu-build-system)))
1374 #~(begin
1375 (use-modules (guix build union))
1376 (union-build (string-append (getenv "NIX_BUILD_TOP") "/site-library")
1377 (parse-path (getenv "GUIX_PYTHONPATH")))
1378 (setenv "PYTHON_LIB_PATH" (string-append (getenv "NIX_BUILD_TOP") "/site-library"))
1379 (setenv "PYTHON_BIN_PATH"
1380 (string-append
1381 #$(this-package-input "python-wrapper")
1382 "/bin/python"))
1383 (setenv "TF_PYTHON_VERSION"
1384 #$(version-major+minor
1385 (package-version (this-package-input "python-wrapper"))))
1386 (setenv "TF_SYSTEM_LIBS"
1387 (string-join (list
1388 ;;"absl_py"
1389 ;;"boringssl"
1390 "com_github_grpc_grpc"
1391 ;;"com_google_protobuf"
1392 "curl"
1393 "cython"
1394 ;;"dill_archive"
1395 "double_conversion"
1396 "flatbuffers"
1397 ;;"functools32_archive"
1398 ;;"gast_archive"
1399 "gif"
1400 "hwloc"
1401 "icu"
1402 ;;"jsoncpp_git"
1403 "libjpeg_turbo"
1404 "zlib")
1405 ","))))
1406 #:bazel-targets
1407 (list "//tensorflow/tools/pip_package:build_pip_package"
1408 "//tensorflow/tools/lib_package:libtensorflow")
1409 #:bazel-arguments
1410 #~(list
1411 "--extra_toolchains=@bazel_tools//tools/python:autodetecting_toolchain_nonstrict"
1412 "--action_env=PYTHON_LIB_PATH"
1413 "--host_action_env=PYTHON_LIB_PATH"
1414 "--action_env=PYTHON_BIN_PATH"
1415 "--host_action_env=PYTHON_BIN_PATH"
1416 ;; "--action_env=GUIX_PYTHONPATH"
1417 ;; "--action_env=PYTHONPATH"
1418 ;; "--host_action_env=GUIX_PYTHONPATH"
1419 ;; "--host_action_env=PYTHONPATH"
1420 (string-append "--python_path="
1421 #$(this-package-input "python-wrapper")
1422 "/bin/python"))
1423 #:hash
1424 "17rwl7vvc0yrky3g9nz4wvs84xyrbyqz0cxfzm5fs51p4vz7mr5d")))
1425
1426 ;; Rewrite dangling links to current build directory
1427 (for-each (lambda (file)
1428 (let ((new-target
1429 (string-replace-substring
1430 (readlink file)
1431 "GUIX_BUILD_TOP" (getenv "NIX_BUILD_TOP"))))
1432 (delete-file file)
1433 (symlink new-target file)))
1434 (find-files bazel-out
1435 (lambda (file-name stat)
1436 (and (eq? (stat:type stat) 'symlink)
1437 (string-contains (readlink file-name)
1438 "GUIX_BUILD_TOP")))
1439 #:stat lstat))
1440 (setenv "HOME" (getenv "NIX_BUILD_TOP"))
1441
1442 ;; Bazel aborts when a source file includes a header
1443 ;; that isn't declared. It prints something like this:
1444 ;;
1445 ;; "this rule is missing dependency declarations for
1446 ;; the following files included by..."
1447 ;;
1448 ;; Since we pass through C_INCLUDE_PATH and
1449 ;; CPLUS_INCLUDE_PATH there are many headers that are
1450 ;; visible to the toolchain, but that Bazel refuses to
1451 ;; allow.
1452 ;;
1453 ;; The biggest problem is that the kernel headers are
1454 ;; never declared as dependencies anywhere, so we need
1455 ;; to modify the toolchain declaration to allow headers
1456 ;; from this location.
1457 ;;
1458 ;; There are other headers that cause trouble, though,
1459 ;; such as those for zlib in the
1460 ;; @com_google_protobuf//:protobuf target. There must
1461 ;; be some other mechanism to fix this (e.g. in the
1462 ;; protobuf target itself), but I find it easier to just
1463 ;; allow all locations that appear on these INCLUDE_PATH
1464 ;; variables.
1465 (substitute* (string-append bazel-out "/external/local_config_cc/BUILD")
1466 (("cxx_builtin_include_directories = \\[" m)
1467 (string-append m
1468 (string-join
1469 (map
1470 (lambda (dir) (string-append "\"" dir "\""))
1471 (append (parse-path (getenv "C_INCLUDE_PATH") '())
1472 (parse-path (getenv "CPLUS_INCLUDE_PATH") '())))
1473 "," 'suffix))))))
1474 (replace 'build
1475 (lambda* (#:key parallel-build? #:allow-other-keys)
1476 (define %build-directory (getenv "NIX_BUILD_TOP"))
1477 (define %bazel-out
1478 (string-append %build-directory "/output"))
1479 (define %bazel-user-root
1480 (string-append %build-directory "/tmp"))
1481 (setenv "BAZEL_USE_CPP_ONLY_TOOLCHAIN" "1")
1482 (setenv "USER" "homeless-shelter")
1483 (setenv "TF_SYSTEM_LIBS"
1484 (string-join (list
1485 ;;"absl_py"
1486 ;;"boringssl"
1487 "com_github_grpc_grpc"
1488 ;;"com_google_protobuf"
1489 "curl"
1490 "cython"
1491 ;;"dill_archive"
1492 "double_conversion"
1493 "flatbuffers"
1494 ;;"functools32_archive"
1495 ;;"gast_archive"
1496 "gif"
1497 "hwloc"
1498 "icu"
1499 ;;"jsoncpp_git"
1500 "libjpeg_turbo"
1501 "zlib")
1502 ","))
1503 (apply invoke "bazel"
1504 "--batch"
1505 (string-append "--output_base=" %bazel-out)
1506 (string-append "--output_user_root=" %bazel-user-root)
1507 "build"
1508 "--nofetch"
1509 "--distinct_host_configuration=false"
1510 "--curses=no"
1511 "--verbose_failures"
1512 "--subcommands"
1513 "--strategy=Genrule=local"
1514 "--toolchain_resolution_debug=\".*\""
1515 "--local_ram_resources=HOST_RAM*.5"
1516 "--local_cpu_resources=HOST_CPUS*.75"
1517 "--action_env=PATH"
1518 "--action_env=GUIX_PYTHONPATH"
1519 "--action_env=PYTHONPATH"
1520 "--action_env=LIBRARY_PATH"
1521 "--action_env=C_INCLUDE_PATH"
1522 "--action_env=CPLUS_INCLUDE_PATH"
1523 "--action_env=GUIX_LOCPATH"
1524 "--action_env=TF_SYSTEM_LIBS"
1525 "--host_action_env=TF_SYSTEM_LIBS"
1526 "--host_action_env=PATH"
1527 "--host_action_env=GUIX_PYTHONPATH"
1528 "--host_action_env=PYTHONPATH"
1529 "--host_action_env=LIBRARY_PATH"
1530 "--host_action_env=C_INCLUDE_PATH"
1531 "--host_action_env=CPLUS_INCLUDE_PATH"
1532 "--host_action_env=GUIX_LOCPATH"
1533 "-c" "opt"
1534 "--jobs"
1535 (if parallel-build?
1536 (number->string (parallel-job-count))
1537 "1")
1538 (list "//tensorflow/tools/pip_package:build_pip_package"
1539 "//tensorflow/tools/lib_package:libtensorflow"))))
1540 (delete 'install))))
1541 (inputs
1542 (list curl
1543 double-conversion
1544 flatbuffers-next
1545 giflib
1546 grpc
1547 hwloc
1548 icu4c
1549 jsoncpp
1550 libjpeg-turbo
1551 openssl
1552 ;; XXX: With our own version of Protobuf we see this error
1553 ;; on "import jax":
1554 ;;
1555 ;; [libprotobuf ERROR google/protobuf/descriptor_database.cc:642] File already exists in database: xla/xla_data.proto
1556 ;; [libprotobuf FATAL google/protobuf/descriptor.cc:1984] CHECK failed: GeneratedDatabase()->Add(encoded_file_descriptor, size):
1557 ;; terminate called after throwing an instance of 'google::protobuf::FatalException'
1558 ;; what(): CHECK failed: GeneratedDatabase()->Add(encoded_file_descriptor, size):
1559 ;;
1560 ;; This problem might not affect Tensorflow but I don't
1561 ;; want to risk it at this point.
1562 ;;protobuf-3.20
1563 ;;`(,protobuf-3.20 "static")
1564 pybind11
1565 python-absl-py
1566 python-cython
1567 python-numpy
1568 python-scipy
1569 python-six
1570 python-wrapper
1571 ;; Wrong version of snappy?
1572 ;; external/tsl/tsl/platform/default/port.cc:328:11: error:
1573 ;; 'RawCompressFromIOVec' is not a member of 'snappy'; did
1574 ;; you mean 'RawUncompressToIOVec'?
1575 ;; snappy
1576 zlib))
1577 (propagated-inputs
1578 (list python-absl-py
1579 python-cachetools
1580 python-certifi
1581 python-charset-normalizer
1582 python-grpcio
1583 python-h5py
1584 python-idna
1585 python-jax
1586 python-markdown
1587 python-markupsafe
1588 python-ml-dtypes
1589 python-numpy
1590 python-oauthlib
1591 python-opt-einsum
1592 python-packaging
1593 python-portpicker
1594 python-protobuf
1595 python-psutil
1596 python-pyasn1
1597 python-requests
1598 python-requests-oauthlib
1599 python-rsa
1600 python-scipy
1601 python-six
1602 python-termcolor
1603 python-urllib3
1604 python-werkzeug))
1605 (native-inputs
1606 (list perl
1607 python-lit python-pypa-build python-setuptools python-wheel
1608 bazel-6
1609 which
1610 `(,openjdk11 "jdk"))) ;for bazel
1611 (home-page "https://tensorflow.org")
1612 (synopsis "Machine learning framework")
1613 (description "TensorFlow is a flexible platform for building and
1614training machine learning models. It provides a library for high
1615performance numerical computation and includes high level Python APIs,
1616including both a sequential API for beginners that allows users to
1617build models quickly by plugging together building blocks and a
1618subclassing API with an imperative style for advanced research.")
1619 (license license:asl2.0)))