projects/guix·blob kernel-updates · refs

7566 lines · 303.3 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2015-2026 Ricardo Wurmus <[email protected]>
3;;; Copyright © 2016, 2020-2024 Efraim Flashner <[email protected]>
4;;; Copyright © 2016, 2017, 2020 Marius Bakke <[email protected]>
5;;; Copyright © 2016 Hartmut Goebel <[email protected]>
6;;; Copyright © 2018, 2019, 2020 Tobias Geerinckx-Rice <[email protected]>
7;;; Copyright © 2018 Mark Meyer <[email protected]>
8;;; Copyright © 2018 Ben Woodcroft <[email protected]>
9;;; Copyright © 2018 Fis Trivial <[email protected]>
10;;; Copyright © 2018 Julien Lepiller <[email protected]>
11;;; Copyright © 2018 Björn Höfling <[email protected]>
12;;; Copyright © 2019 Nicolas Goaziou <[email protected]>
13;;; Copyright © 2019, 2020 Guillaume Le Vaillant <[email protected]>
14;;; Copyright © 2019 Brett Gilio <[email protected]>
15;;; Copyright © 2020 Konrad Hinsen <[email protected]>
16;;; Copyright © 2020 Edouard Klein <[email protected]>
17;;; Copyright © 2020-2025 Vinicius Monego <[email protected]>
18;;; Copyright © 2020, 2021, 2022, 2023 Maxim Cournoyer <[email protected]>
19;;; Copyright © 2022-2025 Nicolas Graves <[email protected]>
20;;; Copyright © 2022 Kiran Shila <[email protected]>
21;;; Copyright © 2022 Wiktor Zelazny <[email protected]>
22;;; Copyright © 2023 zamfofex <[email protected]>
23;;; Copyright © 2023 Navid Afkhami <[email protected]>
24;;; Copyright © 2023 Zheng Junjie <[email protected]>
25;;; Copyright © 2023 Troy Figiel <[email protected]>
26;;; Copyright © 2024-2026 Sharlatan Hellseher <[email protected]>
27;;; Copyright © 2024 David Pflug <[email protected]>
28;;; Copyright © 2024 Timothee Mathieu <[email protected]>
29;;; Copyright © 2024 Spencer King <[email protected]>
30;;; Copyright © 2024, 2025 David Elsing <[email protected]>
31;;; Copyright © 2024, 2025 Andy Tai <[email protected]>
32;;; Copyright © 2025 Lapearldot <[email protected]>
33;;; Copyright © 2025, 2026 Cayetano Santos <[email protected]>
34;;; Copyright © 2025 Janneke Nieuwenhuizen <[email protected]>
35;;; Copyright © 2025 Romain Garbage <[email protected]>
36;;; Copyright © 2026 Nguyễn Gia Phong <[email protected]>
37;;; Copyright © 2026 Goran Vukoman <[email protected]>
38;;; Copyright © 2026 bdunahu <[email protected]>
39;;;
40;;; This file is part of GNU Guix.
41;;;
42;;; GNU Guix is free software; you can redistribute it and/or modify it
43;;; under the terms of the GNU General Public License as published by
44;;; the Free Software Foundation; either version 3 of the License, or (at
45;;; your option) any later version.
46;;;
47;;; GNU Guix is distributed in the hope that it will be useful, but
48;;; WITHOUT ANY WARRANTY; without even the implied warranty of
49;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50;;; GNU General Public License for more details.
51;;;
52;;; You should have received a copy of the GNU General Public License
53;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
54
55(define-module (gnu packages machine-learning)
56 #:use-module (gnu packages algebra)
57 #:use-module (gnu packages assembly)
58 #:use-module (gnu packages audio)
59 #:use-module (gnu packages autotools)
60 #:use-module (gnu packages base)
61 #:use-module (gnu packages bash)
62 #:use-module (gnu packages bdw-gc)
63 #:use-module (gnu packages boost)
64 #:use-module (gnu packages build-tools)
65 #:use-module (gnu packages c)
66 #:use-module (gnu packages calendar)
67 #:use-module (gnu packages check)
68 #:use-module (gnu packages cmake)
69 #:use-module (gnu packages compression)
70 #:use-module (gnu packages cpp)
71 #:use-module (gnu packages cran)
72 #:use-module (gnu packages curl)
73 #:use-module (gnu packages databases)
74 #:use-module (gnu packages dejagnu)
75 #:use-module (gnu packages digest)
76 #:use-module (gnu packages dns)
77 #:use-module (gnu packages documentation)
78 #:use-module (gnu packages freedesktop)
79 #:use-module (gnu packages gcc)
80 #:use-module (gnu packages gettext)
81 #:use-module (gnu packages gl)
82 #:use-module (gnu packages glib)
83 #:use-module (gnu packages graphviz)
84 #:use-module (gnu packages gstreamer)
85 #:use-module (gnu packages guile)
86 #:use-module (gnu packages haskell-xyz)
87 #:use-module (gnu packages image)
88 #:use-module (gnu packages image-processing)
89 #:use-module (gnu packages imagemagick)
90 #:use-module (gnu packages jupyter)
91 #:use-module (gnu packages language)
92 #:use-module (gnu packages libedit)
93 #:use-module (gnu packages libevent)
94 #:use-module (gnu packages libffi)
95 #:use-module (gnu packages linux)
96 #:use-module (gnu packages llvm)
97 #:use-module (gnu packages logging)
98 #:use-module (gnu packages maths)
99 #:use-module (gnu packages monitoring)
100 #:use-module (gnu packages mpi)
101 #:use-module (gnu packages nss)
102 #:use-module (gnu packages ocaml)
103 #:use-module (gnu packages onc-rpc)
104 #:use-module (gnu packages oneapi)
105 #:use-module (gnu packages opencl)
106 #:use-module (gnu packages parallel)
107 #:use-module (gnu packages pdf)
108 #:use-module (gnu packages perl)
109 #:use-module (gnu packages pkg-config)
110 #:use-module (gnu packages pretty-print)
111 #:use-module (gnu packages protobuf)
112 #:use-module (gnu packages pulseaudio)
113 #:use-module (gnu packages python)
114 #:use-module (gnu packages python-build)
115 #:use-module (gnu packages python-check)
116 #:use-module (gnu packages python-crypto)
117 #:use-module (gnu packages python-science)
118 #:use-module (gnu packages python-web)
119 #:use-module (gnu packages python-xyz)
120 #:use-module (gnu packages qt)
121 #:use-module (gnu packages rdf)
122 #:use-module (gnu packages regex)
123 #:use-module (gnu packages rocm)
124 #:use-module (gnu packages rpc)
125 #:use-module (gnu packages rust)
126 #:use-module (gnu packages sdl)
127 #:use-module (gnu packages serialization)
128 #:use-module (gnu packages sphinx)
129 #:use-module (gnu packages sqlite)
130 #:use-module (gnu packages ssh)
131 #:use-module (gnu packages statistics)
132 #:use-module (gnu packages swig)
133 #:use-module (gnu packages time)
134 #:use-module (gnu packages tls)
135 #:use-module (gnu packages valgrind)
136 #:use-module (gnu packages version-control)
137 #:use-module (gnu packages video)
138 #:use-module (gnu packages vulkan)
139 #:use-module (gnu packages web)
140 #:use-module (gnu packages xdisorg)
141 #:use-module (gnu packages xml)
142 #:use-module (gnu packages xorg)
143 #:use-module (gnu packages)
144 #:use-module (guix build-system cargo)
145 #:use-module (guix build-system cmake)
146 #:use-module (guix build-system copy)
147 #:use-module (guix build-system gnu)
148 #:use-module (guix build-system ocaml)
149 #:use-module (guix build-system pyproject)
150 #:use-module (guix build-system r)
151 #:use-module (guix build-system trivial)
152 #:use-module (guix download)
153 #:use-module (guix gexp)
154 #:use-module (guix git-download)
155 #:use-module ((guix licenses) #:prefix license:)
156 #:use-module (guix packages)
157 #:use-module (guix svn-download)
158 #:use-module (guix utils)
159 #:use-module (ice-9 match))
160
161(define-public dlpack
162 (package
163 (name "dlpack")
164 (version "1.2")
165 (source
166 (origin
167 (method git-fetch)
168 (uri (git-reference
169 (url "https://github.com/dmlc/dlpack")
170 (commit (string-append "v" version))))
171 (file-name (git-file-name name version))
172 (sha256
173 (base32 "1zm28s4das0isa5rrh5a1c6iv1k1mcjqgnihbva74s78d52a7hpn"))))
174 (build-system cmake-build-system)
175 (arguments (list #:tests? #f)) ;No tests.
176 (home-page "https://dmlc.github.io/dlpack/latest/")
177 (synopsis "In memory tensor structure")
178 (description
179 "DLPack is an in-memory tensor structure for sharing tensors among
180frameworks.")
181 (license license:asl2.0)))
182
183(define-public fasttext
184 (package
185 (name "fasttext")
186 (version "0.9.2")
187 (source
188 (origin
189 (method git-fetch)
190 (uri (git-reference
191 (url "https://github.com/facebookresearch/fastText")
192 (commit (string-append "v" version))))
193 (file-name (git-file-name name version))
194 (sha256
195 (base32 "07cz2ghfq6amcljaxpdr5chbd64ph513y8zqmibfx2xwfp74xkhn"))))
196 (build-system cmake-build-system)
197 ;; Tests require downloading of test data.
198 (arguments
199 (list
200 #:tests? #false
201 #:phases
202 #~(modify-phases %standard-phases
203 (add-after 'unpack 'gcc-14-fix
204 (lambda _
205 (substitute* "src/args.cc"
206 (("#include <unordered_map>" all)
207 (string-append all "\n#include <cstdint>"))))))))
208 (home-page "https://github.com/facebookresearch/fastText")
209 (synopsis "Library for fast text representation and classification")
210 (description "fastText is a library for efficient learning of word
211representations and sentence classification.")
212 (license license:expat)))
213
214(define-public ggml
215 (package
216 (name "ggml")
217 (version "0.25.2") ;sync with llama.cpp
218 (source
219 (origin
220 (method git-fetch)
221 (uri (git-reference
222 (url "https://github.com/ggml-org/ggml")
223 (commit (string-append "v" version))))
224 (file-name (git-file-name name version))
225 (sha256
226 (base32 "0ww5wk2d6ldy2l5fxh4nr259mnwdpypp316h383as46cbvywyh60"))))
227 (build-system cmake-build-system)
228 (arguments
229 (list
230 #:configure-flags
231 #~(list #$(string-append "-DGGML_BUILD_COMMIT=" version)
232 "-DBUILD_SHARED_LIBS_DEFAULT=ON"
233 "-DGGML_BACKEND_DL=ON"
234 (string-append "-DGGML_BACKEND_DIR="
235 #$output "/lib/backends")
236 "-DGGML_VULKAN=ON"
237 "-DGGML_BUILD_TESTS=ON"
238 "-DGGML_OPENCL=ON"
239 ;; Defaults to ON upstream; ggml-opencl.cpp's own
240 ;; ggml_opencl_is_device_supported() unconditionally
241 ;; rejects every non-Adreno (non-Qualcomm) device when
242 ;; this is compiled in, regardless of how capable the
243 ;; device actually is.
244 "-DGGML_OPENCL_USE_ADRENO_KERNELS=OFF"
245 "-DGGML_NATIVE_DEFAULT=OFF" ;no '-march=native'
246 "-DGGML_BLAS_DEFAULT=ON"
247 "-DGGML_BLAS_VENDOR_DEFAULT=OpenBLAS")))
248 (inputs
249 (list glslang
250 openblas
251 openblas-ilp64
252 opencl-icd-loader
253 shaderc
254 spirv-headers
255 spirv-tools
256 vulkan-headers
257 vulkan-loader))
258 (native-inputs
259 (list opencl-headers pkg-config python-minimal-wrapper))
260 (properties '((tunable? . #true)))
261 (home-page "https://github.com/ggml-org/ggml")
262 (synopsis "Tensor library for machine learning")
263 (description "@code{ggml} is a @acronym{ML, Machine Learning} library
264written in C and C++ with a focus on transformer inference, similar to ML
265libraries such as PyTorch and TensorFlow.")
266 (license license:expat)))
267
268(define-public ggml-for-whisper
269 (package
270 (inherit ggml)
271 (name "ggml-for-whisper")
272 (version "0.15.1") ;sync whisper.cpp
273 (source
274 (origin
275 (method git-fetch)
276 (uri (git-reference
277 (url "https://github.com/ggml-org/ggml")
278 (commit (string-append "v" version))))
279 (file-name (git-file-name name version))
280 (sha256
281 (base32 "06bw4dbnzmy9wz3k6g4a2vf7yjn7xpqzam4ra6mxv3lkvhz0fhsg"))))))
282
283(define-public git-ai
284 (package
285 (name "git-ai")
286 (version "1.1.18")
287 (source (origin
288 (method git-fetch)
289 (uri (git-reference
290 (url "https://github.com/git-ai-project/git-ai")
291 (commit (string-append "v" version))))
292 (file-name (git-file-name name version))
293 (sha256
294 (base32 "0yf864shgi5b35s0f6frds0lf9jwwn8qw4pxiniplhnxadrbpx2f"))))
295 (build-system cargo-build-system)
296 (arguments
297 (list #:install-source? #f
298 #:cargo-test-flags
299 ''("--"
300 ;;This test requires network access.
301 "--skip=test_load_ai_touched_files_for_specific_commits"
302 ;;This test fails in the build environment.
303 "--skip=exit_status_was_interrupted_on_sigint")
304 #:phases
305 #~(modify-phases %standard-phases
306 (add-after 'unpack 'patch-/bin/sh
307 (lambda _
308 (substitute* (list "tests/integration/continue_session.rs"
309 "tests/integration/diff.rs"
310 "tests/integration/stats.rs"
311 "tests/integration/status_ignore.rs"
312 "tests/integration/git_ai_hooks.rs"
313 "tests/integration/hook_forwarding.rs"
314 "tests/integration/hook_modes.rs"
315 "tests/integration/rebase.rs")
316 (("#!/bin/sh") (string-append "#!" (which "sh"))))))
317 (add-after 'unpack 'set-home
318 (lambda _
319 (setenv "HOME" (getenv "TMPDIR"))))
320 (add-before 'check 'setup-git-path
321 (lambda* (#:key inputs #:allow-other-keys)
322 (let ((git (assoc-ref inputs "git-minimal"))
323 (home (getenv "HOME")))
324 (mkdir-p (string-append home "/.git-ai"))
325 (let ((port (open-file
326 (string-append home "/.git-ai/config.json")
327 "a")))
328 (format port "{\"git_path\": \"~a/bin/git\"}" git)
329 (close port))
330
331 (substitute* "src/config.rs"
332 (("\"/usr/bin/git\"")
333 (string-append "\"" git "/bin/git\""))))))
334 (add-before 'check 'git-init
335 (lambda _
336 ;;The tests expect a git repo with at least one commit.
337 (invoke "git" "init")
338 (invoke "git" "config" "--global" "user.email" "[email protected]")
339 (invoke "git" "config" "--global" "user.name" "User Name")
340 (invoke "git" "add" ".")
341 (invoke "git" "commit" "-m" "Commit all."))))))
342 (native-inputs (list
343 git-minimal/pinned ;for tests
344 pkg-config))
345 (inputs
346 (cons*
347 libgit2 libssh2 openssl sqlite zlib (cargo-inputs 'git-ai)))
348 (home-page "https://usegitai.com/")
349 (synopsis "Git extension for tracking LLM-generated code")
350 (description "@code{git-ai} is an extension for git that tracks which
351lines of code were created by an LLM along with metadata about how and why.")
352 (license license:asl2.0)))
353
354(define-public python-apricot-select
355 (package
356 (name "python-apricot-select")
357 ;; 0.6.1 was released in 2021
358 (properties '((commit . "962f597a57fcb880a3b19befa7a3eebccc6b5228")
359 (revision . "0")))
360 (version (git-version "0.6.1"
361 (assoc-ref properties 'revision)
362 (assoc-ref properties 'commit)))
363 (source
364 (origin
365 (method git-fetch)
366 (uri (git-reference
367 (url "https://github.com/jmschrei/apricot")
368 (commit (assoc-ref properties 'commit))))
369 (file-name (git-file-name name version))
370 (sha256
371 (base32 "16hj76nzdr4pbx7wy5f3237f9c1d0yizmz1skix0rwlvjpj3rc9x"))))
372 (build-system pyproject-build-system)
373 (arguments
374 ;; See: <https://github.com/jmschrei/apricot/issues/19>.
375 (list #:tests? #f)) ;tests are very compue havy
376 (native-inputs
377 (list python-pytest
378 python-pytest-xdist
379 python-setuptools
380 python-scikit-learn))
381 (propagated-inputs
382 (list python-numba
383 python-numpy
384 python-scipy
385 python-tqdm))
386 (home-page "https://github.com/jmschrei/apricot")
387 (synopsis "Submodular selection of representative sets for ML models")
388 (description
389 "@code{apricot} implements submodular optimization for the purpose of
390summarizing massive data sets into minimally redundant subsets that are still
391representative of the original data. These subsets are useful for both
392visualizing the modalities in the data and for training accurate machine
393learning models with just a fraction of the examples and compute.")
394 (license license:expat)))
395
396(define-public python-autograd-gamma
397 (package
398 (name "python-autograd-gamma")
399 (version "0.5.0")
400 (source
401 (origin
402 (method git-fetch)
403 (uri (git-reference
404 (url "https://github.com/CamDavidsonPilon/autograd-gamma")
405 ;; The 5.0.0 version is not tagged, but can only be this commit.
406 (commit "5876e0320865c592ed4a370c6a6ef282cf163480")))
407 (file-name (git-file-name name version))
408 (sha256
409 (base32 "0hpjnpw7bsy1xja4pnxx5fvv7xly72lp3hdazhr9zbmn6s7vcs19"))))
410 (build-system pyproject-build-system)
411 (native-inputs
412 (list python-pytest
413 python-setuptools))
414 (propagated-inputs
415 (list python-autograd
416 python-scipy))
417 (home-page "https://github.com/CamDavidsonPilon/autograd-gamma")
418 (synopsis
419 "Autograd-compatible approximations to the gamma family of functions")
420 (description
421 "This package provides Autograd-compatible approximations to the gamma
422family of functions.")
423 (license license:expat)))
424
425(define-public python-burr
426 (package
427 (name "python-burr")
428 (version "0.42.0")
429 (source
430 (origin
431 (method git-fetch)
432 (uri (git-reference
433 (url "https://github.com/apache/burr/")
434 (commit (string-append "burr-" version))))
435 (file-name (git-file-name name version))
436 (sha256
437 (base32 "0a2sf72qy9jkamg6r7d37mv7ayp698h031md7arfyq7v8q9q121n"))))
438 (build-system pyproject-build-system)
439 (arguments
440 (list
441 #:phases
442 '(modify-phases %standard-phases
443 ;; Avoid "async def functions are not natively supported." with 70+
444 ;; test failures. This hack triggers a bunch of warnings, because
445 ;; now also synchronous tests are marked with @pytest.mark.asyncio,
446 ;; but at least the tests run successfully.
447 (add-after 'unpack 'patch-tests
448 (lambda _
449 (substitute* "tests/common/test_async_utils.py"
450 (("from typing.*" m)
451 (string-append m "\
452import asyncio
453import pytest
454pytestmark = pytest.mark.asyncio\n")))
455 (substitute* '("tests/visibility/test_tracing.py"
456 "tests/core/test_parallelism.py"
457 "tests/core/test_action.py"
458 "tests/core/test_application.py"
459 "tests/test_end_to_end.py")
460 (("^import asyncio.*" m)
461 (string-append m "\
462import pytest
463pytestmark = pytest.mark.asyncio\n"))))))
464 ;; There are integration tests and examples comparing Burr to and
465 ;; interfacing with alternatives, such as the overly complex langchain.
466 ;; We should not add them here just to run these tests.
467 #:test-flags
468 #~(list "--ignore-glob=tests/integration**"
469 "--ignore-glob=examples/**"
470 "--ignore-glob=burr/examples/**"
471 "--ignore=tests/core/test_graphviz_display.py"
472 "--ignore=tests/core/test_persistence.py")))
473 (native-inputs
474 (list python-flit-core
475 python-anyio
476 python-pytest
477 python-pytest-asyncio
478 python-setuptools))
479 ;; Burr has very few hard dependencies. Including these optional packages
480 ;; makes it more useful, though.
481 (propagated-inputs
482 (list python-pydantic ;optional
483 python-pydantic-settings ;optional
484 python-loguru
485 python-requests))
486 (home-page "https://burr.apache.org/")
487 (synopsis "Build applications that make decisions")
488 (description
489 "Apache Burr makes it easy to develop applications that make
490decisions (chatbots, agents, simulations, etc...) from simple Python building
491blocks. Apache Burr works well for any application that uses LLMs, and can
492integrate with any of your favorite frameworks. Burr includes a UI that can
493track/monitor/trace your system in real time, along with pluggable
494persisters (e.g. for memory) to save and load application state.")
495 (license license:asl2.0)))
496
497(define-public python-faster-whisper
498 (package
499 (name "python-faster-whisper")
500 (version "1.2.0")
501 (source
502 (origin
503 (method git-fetch)
504 (uri (git-reference
505 (url "https://github.com/SYSTRAN/faster-whisper")
506 (commit (string-append "v" version))))
507 (file-name (git-file-name name version))
508 (sha256
509 (base32 "0wmc9aszpnbr60l5v97np0rc3zsz4pldjald7kmnr668rhpakzcj"))))
510 (build-system pyproject-build-system)
511 ;; XXX: Currently tests requires model download, which we'd rather avoid
512 ;; in Guix unless we're sure about the FOSS weights. To test in source :
513 ;; guix shell -D python-faster-whisper -- pytest
514 (arguments (list #:tests? #f))
515 (propagated-inputs (list (list onnxruntime "python")
516 python-av
517 python-ctranslate2
518 python-huggingface-hub
519 python-tokenizers
520 python-tqdm))
521 (native-inputs (list python-numpy
522 python-pytest
523 python-setuptools))
524 (home-page "https://github.com/SYSTRAN/faster-whisper")
525 (synopsis "Whisper transcription reimplementation")
526 (description
527 "This package provides a reimplementation of OpenAI's Whisper model using
528CTranslate2, which is a inference engine for transformer models.")
529 (license license:expat)))
530
531(define-public python-fasttext
532 (package
533 (inherit fasttext)
534 (name "python-fasttext")
535 (build-system pyproject-build-system)
536 (propagated-inputs (list python-numpy python-scipy))
537 (inputs (list fasttext))
538 (native-inputs (list pybind11-2 python-setuptools python-wheel))))
539
540(define-public python-funsor
541 (package
542 (name "python-funsor")
543 (version "0.4.7")
544 (source
545 (origin
546 (method git-fetch)
547 (uri (git-reference
548 (url "https://github.com/pyro-ppl/funsor")
549 (commit version)))
550 (file-name (git-file-name name version))
551 (sha256
552 (base32 "1ragxy19qfaczn3wfpamg0giqyiscxvm366r3md255lfafzwj96i"))))
553 (build-system pyproject-build-system)
554 (arguments
555 (list
556 ;; tests: 7665 passed, 3949 skipped, 71 xfailed, 2 xpassed, 8 warnings
557 #:test-flags
558 #~(list "--numprocesses" (number->string (min 8 (parallel-job-count)))
559 ;; XXX: The project has no updates since 2023 and probably not
560 ;; compatible with current Python science stack (NumPy, SciPy,
561 ;; Pandas...).
562 ;;
563 ;; See open issues:
564 ;; <https://github.com/pyro-ppl/funsor/issues/609>
565 ;; <https://github.com/pyro-ppl/funsor/pull/610>
566 ;;
567 ;; TypeError: argument of type 'property' is not iterable
568 "--ignore=test/examples/test_sensor_fusion.py"
569 "--ignore=test/torch/test_provenance.py"
570 ;; The most of the tests fail with error: ValueError: Cannot
571 ;; convert to Funsor: tensor..
572 #$@(map (lambda (test) (string-append "--deselect=test/"
573 test))
574 (list "pyro/test_convert.py::test_dist_to_funsor_bernoulli"
575 "pyro/test_convert.py::test_dist_to_funsor_categorical"
576 "pyro/test_convert.py::test_dist_to_funsor_independent"
577 "pyro/test_convert.py::test_dist_to_funsor_masked"
578 "pyro/test_convert.py::test_dist_to_funsor_mvn"
579 "pyro/test_convert.py::test_dist_to_funsor_normal"
580 "pyro/test_convert.py::test_funsor_to_cat_and_mvn"
581 "pyro/test_convert.py::test_funsor_to_mvn"
582 "pyro/test_convert.py::test_matrix_and_mvn_to_funsor"
583 "pyro/test_convert.py::test_matrix_and_mvn_to_funsor_diag"
584 "pyro/test_convert.py::test_mvn_to_funsor"
585 "pyro/test_convert.py::test_tensor_funsor_tensor"
586 "pyro/test_distribution.py::test_categorical_log_prob"
587 "pyro/test_distribution.py::test_categorical_sample"
588 "pyro/test_hmm.py::test_discrete_categorical_log_prob"
589 "pyro/test_hmm.py::test_discrete_diag_normal_log_prob"
590 "pyro/test_hmm.py::test_discrete_mvn_log_prob"
591 "pyro/test_hmm.py::test_discrete_normal_log_prob"
592 "pyro/test_hmm.py::test_gaussian_hmm_log_prob"
593 "pyro/test_hmm.py::test_gaussian_hmm_log_prob_null_dynamics"
594 "pyro/test_hmm.py::test_gaussian_mrf_log_prob"
595 "pyro/test_hmm.py::test_switching_linear_hmm_log_prob"
596 "pyro/test_hmm.py::test_switching_linear_hmm_log_prob_alternating"
597 "pyro/test_hmm.py::test_switching_linear_hmm_shape"
598 "pyroapi/test_pyroapi.py::test_generate_data"
599 "pyroapi/test_pyroapi.py::test_generate_data_plate"
600 "pyroapi/test_pyroapi.py::test_local_param_ok"
601 "pyroapi/test_pyroapi.py::test_mean_field_ok"
602 "pyroapi/test_pyroapi.py::test_nested_plate_plate_ok"
603 "pyroapi/test_pyroapi.py::test_nonempty_model_empty_guide_ok"
604 "pyroapi/test_pyroapi.py::test_optimizer"
605 "pyroapi/test_pyroapi.py::test_plate_ok"
606 "test_tensor.py::test_function_of_numeric_array")))))
607 (native-inputs
608 (list python-pandas
609 python-pillow
610 python-pyro-api
611 python-pytest
612 python-pytest-xdist
613 python-requests
614 python-scipy
615 python-setuptools
616 python-torchvision))
617 (propagated-inputs
618 (list python-makefun
619 python-multipledispatch
620 python-numpy
621 python-opt-einsum
622 python-typing-extensions
623 ;; [optional]
624 ;; python-jax
625 ;; python-jaxlib
626 ;; python-numpyro
627 python-pyro-ppl
628 python-pytorch))
629 (home-page "https://github.com/pyro-ppl/funsor")
630 (synopsis "Tensor-like library for functions and distributions")
631 (description
632 "This package provides a tensor-like library for functions and
633distributions.")
634 (license license:asl2.0)))
635
636(define-public fann
637 ;; The last release is 14 years old.
638 (let ((commit "1783cbf6239a597c4d29f694e227e22b8d4f4bf6")
639 (revision "2"))
640 (package
641 (name "fann")
642 (version (git-version "2.2.0" revision commit))
643 (source
644 (origin
645 (method git-fetch)
646 (uri (git-reference
647 (url "https://github.com/libfann/fann")
648 (commit commit)))
649 (modules '((guix build utils)))
650 (snippet #~(delete-file-recursively "lib/googletest"))
651 (file-name (git-file-name name version))
652 (sha256
653 (base32
654 "0jlcxl0czlr3982mak3935mb08i2f368f0jsxca91ppgfd596ldr"))))
655 (build-system cmake-build-system)
656 (arguments
657 (list
658 #:phases
659 #~(modify-phases %standard-phases
660 (add-after 'unpack 'remove-googletest
661 (lambda _
662 (substitute* "CMakeLists.txt"
663 (("ADD_SUBDIRECTORY\\( lib/googletest \\)")
664 ""))))
665 (replace 'check
666 (lambda* (#:key tests? #:allow-other-keys)
667 (when tests?
668 (with-directory-excursion "tests"
669 (invoke "./fann_tests"))))))))
670 (native-inputs (list googletest-1.13))
671 (home-page "https://leenissen.dk/")
672 (synopsis "Fast Artificial Neural Network")
673 (description
674 "FANN is a neural network library, which implements multilayer
675artificial neural networks in C with support for both fully connected and
676sparsely connected networks.")
677 (license license:lgpl2.1))))
678
679(define-public libsvm
680 (package
681 (name "libsvm")
682 (version "337")
683 (source
684 (origin
685 (method git-fetch)
686 (uri (git-reference
687 (url "https://github.com/cjlin1/libsvm/")
688 (commit (string-append "v" version))))
689 (file-name (git-file-name name version))
690 (sha256
691 (base32 "0rd4balgr62jisml6q682klkcxn8f8mjc5rc69rl2bzvdbrk3xia"))))
692 (build-system gnu-build-system)
693 (arguments
694 (list
695 #:tests? #f ;no "check" target
696 #:phases
697 #~(modify-phases %standard-phases
698 (delete 'configure)
699 (add-after 'build 'build-lib
700 (lambda _
701 (invoke "make" "lib")))
702 (replace 'install
703 ;no "install" target
704 (lambda _
705 (for-each (lambda (file)
706 (install-file file
707 (string-append #$output "/bin")))
708 '("svm-train" "svm-predict" "svm-scale"))
709 (install-file "libsvm.so.4"
710 (string-append #$output "/lib"))
711 (symlink (string-append #$output "/lib/libsvm.so.4")
712 (string-append #$output "/lib/libsvm.so"))
713 (install-file "svm.h"
714 (string-append #$output "/include/"
715 #$name)))))))
716 (native-inputs (list python-minimal-wrapper))
717 (home-page "https://www.csie.ntu.edu.tw/~cjlin/libsvm/")
718 (synopsis "Library for Support Vector Machines")
719 (description
720 "LIBSVM is a machine learning library for support vector
721classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
722distribution estimation (one-class SVM). It supports multi-class
723classification.")
724 (license license:bsd-3)))
725
726(define-public python-gpy
727 (package
728 (name "python-gpy")
729 (version "1.14.2")
730 (source
731 (origin
732 (method git-fetch)
733 (uri (git-reference
734 (url "https://github.com/SheffieldML/GPy")
735 (commit (string-append "v" version))))
736 (file-name (git-file-name name version))
737 (sha256
738 (base32 "1l0yxidhsf9s87fcc7v1l38dywq9ps6nr1d84r1nmblp9dgmibr2"))))
739 (build-system pyproject-build-system)
740 (arguments
741 (list
742 #:phases
743 #~(modify-phases %standard-phases
744 (add-after 'unpack 'compatibility
745 (lambda _
746 ;; This file uses Python 2 statements
747 (delete-file "GPy/testing/mpi_test__.py"))))))
748 (native-inputs
749 (list python-cython
750 python-pods
751 python-pytest
752 python-setuptools))
753 (propagated-inputs
754 (list python-numpy
755 python-paramz
756 python-scipy
757 python-six ;hard dependency
758 ;; [optional]
759 python-matplotlib
760 python-plotly))
761 (home-page "https://sheffieldml.github.io/GPy/")
762 (synopsis "The Gaussian Process Toolbox")
763 (description
764 "@command{GPy} is a Gaussian Process (GP) framework written in Python,
765from the Sheffield machine learning group. GPy implements a range of machine
766learning algorithms based on GPs.")
767 (license license:bsd-3)))
768
769(define-public python-libsvm
770 (package
771 (inherit libsvm)
772 (name "python-libsvm")
773 (build-system pyproject-build-system)
774 (arguments
775 (list
776 #:tests? #f ;no "check" target
777 #:phases
778 #~(modify-phases %standard-phases
779 (add-before 'build 'chdir
780 (lambda _
781 (chdir "python"))))))
782 (native-inputs (list python-setuptools))
783 (propagated-inputs (list libsvm python-scipy))
784 (synopsis "Python bindings of libSVM")))
785
786(define-public python-mcfit
787 ;; PyPI variant fails during compile-bytecode phase: "IndentationError:
788 ;; expected an indented block after function definition on line 10
789 ;; (mkfit.py, line 15)".
790 ;; GitHub provides no release tags, use the latest commit from the master
791 ;; branch.
792 ;; See: <https://github.com/eelregit/mcfit/issues/5>.
793 (let ((commit "be3a5cf9c474e16875126adcd35ba785fb781ebb")
794 (revision "0"))
795 (package
796 (name "python-mcfit")
797 (version (git-version "0.0.22" revision commit))
798 (source
799 (origin
800 (method git-fetch)
801 (uri (git-reference
802 (url "https://github.com/eelregit/mcfit")
803 (commit commit)))
804 (sha256
805 (base32 "120ybwhrqpn9a9q96m6l8pw8a7cdz705vzqn3s87wnffa8nslbsi"))))
806 (build-system pyproject-build-system)
807 (native-inputs
808 (list python-pytest
809 python-setuptools
810 python-wheel))
811 (propagated-inputs
812 (list python-mpmath
813 python-numpy
814 python-scipy))
815 (home-page "https://github.com/eelregit/mcfit")
816 (synopsis "Multiplicatively convolutional fast integral transforms")
817 (description
818 "This package provides multiplicatively convolutional fast integral
819transforms.")
820 (license license:gpl3+))))
821
822(define-public python-minisbd
823 (package
824 (name "python-minisbd")
825 (version "0.9.5")
826 (source
827 (origin
828 (method git-fetch)
829 (uri (git-reference
830 (url "https://github.com/LibreTranslate/MiniSBD")
831 (commit (string-append "v" version))))
832 (file-name (git-file-name name version))
833 (sha256
834 (base32 "1dfflfx39vq1fijrzmfq43hva2ackbx7pj6ixpxbq48p1v9r715a"))))
835 (build-system pyproject-build-system)
836 (arguments (list #:tests? #f)) ;no tests
837 (native-inputs
838 (list python-hatchling))
839 (propagated-inputs
840 (list python-filelock
841 python-numpy
842 (list onnxruntime "python")))
843 (home-page "https://github.com/LibreTranslate/MiniSBD")
844 (synopsis "Sentence boundary detection Python library")
845 (description
846 "This package provides a Python library for fast sentence boundary
847detection. It uses 8bit quantized ONNX models for inference, thus making it
848fast and lightweight.")
849 (license license:agpl3+)))
850
851(define-public python-ml-collections
852 (package
853 (name "python-ml-collections")
854 (version "1.1.0")
855 (source
856 (origin
857 (method git-fetch)
858 (uri (git-reference
859 (url "https://github.com/google/ml_collections")
860 (commit (string-append "v" version))))
861 (sha256
862 (base32 "1lv7vs84v4zwyrqg2zdlkrx3x6w08j9lyz74m8vk55ysl4399pqv"))))
863 (build-system pyproject-build-system)
864 (arguments
865 (list
866 ;; tests: 373 passed, 1 skipped, 81 warnings
867 #:test-flags
868 #~(list "--ignore=docs/"
869 "--ignore=ml_collections/config_dict/examples/examples_test.py")))
870 (native-inputs
871 (list python-flit-core
872 python-pytest))
873 (propagated-inputs
874 (list python-absl-py
875 python-pyyaml))
876 (home-page "https://github.com/google/ml_collections")
877 (synopsis "Python collections designed for Machine Learning usecases")
878 (description
879 "ML Collections is a library of Python collections designed for Machine
880Learning usecases.")
881 (license license:asl2.0)))
882
883(define-public python-ml-dtypes
884 (package
885 (name "python-ml-dtypes")
886 (version "0.5.4")
887 (source
888 (origin
889 (method git-fetch)
890 (uri (git-reference
891 (url "https://github.com/jax-ml/ml_dtypes")
892 (commit (string-append "v" version))))
893 (file-name (git-file-name name version))
894 (sha256
895 (base32 "0q6y0m1jh0a2hj0x887gp361zbrsfz93csr8hm3pkamg354plczc"))
896 (modules '((guix build utils)))
897 (snippet
898 ;; Do not use bundled eigen.
899 '(delete-file-recursively "third_party/eigen"))))
900 (build-system pyproject-build-system)
901 (arguments
902 (list
903 ;; tests: 2087 passed, 17 skipped, 2 deselected, 2720 subtests passed
904 #:test-flags
905 ;; Arrays are not equal
906 #~(list (string-append "--deselect=ml_dtypes/tests/"
907 "custom_float_test.py::CustomFloatNumPyTest"
908 "::testArange_float8_e4m3b11fnuz")
909 (string-append "--deselect=ml_dtypes/tests/custom_float_test.py"
910 "::CustomFloatNumPyTest"
911 "::testArange_float8_e4m3b11fnuz_multi_threaded"))
912 #:phases
913 #~(modify-phases %standard-phases
914 (add-after 'unpack 'use-eigen-package
915 (lambda* (#:key inputs #:allow-other-keys)
916 (substitute* "setup.py"
917 (("third_party/eigen")
918 (search-input-directory inputs "include/eigen3")))))
919 (add-after 'install 'symlink-lib
920 (lambda* (#:key inputs outputs #:allow-other-keys)
921 (for-each
922 (lambda (file)
923 (symlink file
924 (string-append #$output "/lib/ml_dtypes.so")))
925 (find-files (site-packages inputs outputs) "\\.so$")))))))
926 (inputs (list eigen-for-python-ml-dtypes))
927 (propagated-inputs (list python-numpy))
928 (native-inputs (list pybind11
929 python-absl-py
930 python-pytest
931 python-setuptools))
932 (home-page "https://github.com/jax-ml/ml_dtypes")
933 (synopsis "NumPy dtype extensions used in machine learning")
934 (description
935 "This package is a stand-alone implementation of several
936NumPy @code{dtype} extensions used in machine learning libraries, including:
937
938@itemize
939@item @code{bfloat16}: an alternative to the standard @code{float16} format
940@item @code{float8_*}: several experimental 8-bit floating point
941 representations including:
942 @itemize
943 @item @code{float8_e4m3b11fnuz}
944 @item @code{float8_e4m3fn}
945 @item @code{float8_e4m3fnuz}
946 @item @code{float8_e5m2}
947 @item @code{float8_e5m2fnuz}
948 @end itemize
949@item @code{int4} and @code{uint4}: low precision integer types.
950@end itemize
951")
952 (license license:asl2.0)))
953
954(define-public llama-cpp
955 ;; llama.cpp itself now tags real semantic-version releases (unlike the
956 ;; old "b<N>" raw-build-number scheme this package used to track), but
957 ;; those releases carry no binary assets of their own -- only a
958 ;; "nightly-tag.txt" pointing at the "b<N>"-tagged nightly build they
959 ;; correspond to, which is where the prebuilt web UI tarball (below)
960 ;; actually lives.
961 (let ((ui-build "11146")) ;from that tag's nightly-tag.txt
962 (package
963 (name "llama-cpp")
964 (version "0.5.0")
965 (source
966 (origin
967 (method git-fetch)
968 (uri (git-reference
969 (url "https://github.com/ggml-org/llama.cpp")
970 (commit (string-append "v" version))))
971 (file-name (git-file-name name version))
972 (sha256
973 (base32 "0q13scf0ygxrj4zjwcdcpi1j2ncxzqzcbmfcg068vw4c9avrbm1j"))))
974 (build-system cmake-build-system)
975 (arguments
976 (list
977 ;; ctest includes a fast-growing set of network-dependent tests
978 ;; (test-download-model and everything that depends on its
979 ;; FIXTURES_REQUIRED, several test-recurrent-state-rollback-*
980 ;; variants, test-jinja-py, ...); the previous approach of
981 ;; patching each one out by name (llama-cpp-disable-tests.patch)
982 ;; already stopped applying cleanly after upstream added more of
983 ;; them, so just skip ctest entirely instead of re-patching it
984 ;; again every version bump.
985 #:tests? #f
986 #:configure-flags
987 #~(list "-DBUILD_SHARED_LIBS=ON"
988 "-DLLAMA_USE_SYSTEM_GGML=ON")
989 #:phases
990 #~(modify-phases %standard-phases
991 ;; See :
992 ;; llama.cpp/issues/23105#issuecomment-4531264818
993 (add-before 'build 'get-ui
994 (lambda _
995 (with-directory-excursion "tools/ui"
996 (copy-file #$(this-package-input "ui.tar.gz") "ui.tar.gz")
997 (invoke "tar" "xvf" "ui.tar.gz")
998 (rename-file #$(string-append "llama-b" ui-build) "dist"))))
999 (add-after 'install 'remove-tests
1000 (lambda _
1001 (for-each delete-file
1002 (find-files (string-append #$output "/bin")
1003 "^test-")))))))
1004 (inputs
1005 (list ggml openssl
1006 (origin
1007 (method url-fetch)
1008 (uri
1009 (format #f "~a/releases/download/b~a/llama-b~a-ui.tar.gz"
1010 "https://github.com/ggml-org/llama.cpp"
1011 ui-build ui-build))
1012 (file-name "ui.tar.gz")
1013 (sha256
1014 (base32 "1wm69rrlhr505q1ww0vs01y9y8lai8pj3lnx8yq80y873lxyfaw3")))))
1015 (properties '((tunable? . #true))) ;use AVX512, FMA, etc. when available
1016 (home-page "https://github.com/ggml-org/llama.cpp")
1017 (synopsis "Port of Facebook's LLaMA model in C/C++")
1018 (description "This package provides a port to Facebook's LLaMA collection
1019of foundation language models. It requires models parameters to be downloaded
1020independently to be able to run a LLaMA model.")
1021 (license license:expat))))
1022
1023(define-public llama-cpp-scripts
1024 (package
1025 (inherit llama-cpp)
1026 (name "llama-cpp-scripts")
1027 (version "0.0.0") ;from pyproject.toml
1028 (build-system pyproject-build-system)
1029 (arguments
1030 (list
1031 #:test-flags
1032 #~(list "--ignore=scripts/snapdragon"
1033 "--ignore=tools/server/tests")))
1034 (inputs '())
1035 (propagated-inputs
1036 (list python-numpy
1037 python-pytorch
1038 python-protobuf
1039 python-sentencepiece
1040 python-transformers
1041 python-gguf))
1042 (native-inputs (list python-poetry-core python-pytest))
1043 (properties '())
1044 (synopsis "Scripts that ship with @code{llama.cpp}")
1045 (description "This package includes the Python scripts included in
1046@code{llama.cpp}. These scripts are necessary for format conversion, shader
1047generation, etc.")
1048 (license license:expat)))
1049
1050(define-public whisper-cpp
1051 (package
1052 (name "whisper-cpp")
1053 (version "1.9.1") ;keep in sync with ggml-for-whisper
1054 (source (origin
1055 (method git-fetch)
1056 (uri (git-reference
1057 (url "https://github.com/ggml-org/whisper.cpp")
1058 (commit (string-append "v" version))))
1059 (file-name (git-file-name name version))
1060 (sha256
1061 (base32
1062 "1mpmmqm83qy39a1zqphy059x2crzwll2j34ypgwwghy2ji6nc2xm"))))
1063 (build-system cmake-build-system)
1064 (arguments
1065 (list
1066 #:configure-flags
1067 #~(list "-DBUILD_SHARED_LIBS=ON"
1068 "-DWHISPER_SDL2=TRUE"
1069 "-DWHISPER_COMMON_FFMPEG=TRUE"
1070 "-DWHISPER_USE_SYSTEM_GGML=ON")
1071 #:phases
1072 #~(modify-phases %standard-phases
1073 #$@(if (target-32bit?)
1074 '((add-after 'unpack 'skip-failing-tests
1075 (lambda _
1076 ;; 32-bit system
1077 ;; large model does not fit in RAM in 32-bit system,
1078 ;; disable large model test
1079 (substitute* "tests/CMakeLists.txt"
1080 (("LABELS \"large\"")
1081 "DISABLED true")))))
1082 '())
1083 (add-after 'unpack 'fix-parakeet-test
1084 (lambda _
1085 ;; Unlike whisper-cli, test-parakeet does not load the
1086 ;; dynamically loadable ggml backends, so it aborts with
1087 ;; "GGML_ASSERT(device) failed" since our ggml is built
1088 ;; with -DGGML_BACKEND_DL=ON.
1089 (substitute* "tests/test-parakeet.cpp"
1090 (("#include \"parakeet\\.h\"")
1091 "#include \"parakeet.h\"\n#include \"ggml-backend.h\"")
1092 (("int main\\(\\) \\{")
1093 "int main() {\n ggml_backend_load_all();"))))
1094 (add-after 'unpack 'skip-failing-vad-tests
1095 (lambda _
1096 (substitute* "tests/CMakeLists.txt"
1097 ;; error: failed to read audio data as wav (Unknown error)
1098 (("\\$\\{VAD_TEST\\} PROPERTIES LABELS \"unit\"")
1099 "${VAD_TEST} PROPERTIES DISABLED true")
1100 ;; error: failed to read audio data as wav (Unknown error)
1101 (("\\$\\{VAD_TEST\\} PROPERTIES LABELS \"base;en\"")
1102 "${VAD_TEST} PROPERTIES DISABLED true")))))))
1103 (native-inputs
1104 (list git-minimal/pinned pkg-config))
1105 (inputs
1106 (list ffmpeg ggml-for-whisper sdl2))
1107 (synopsis "OpenAI's Whisper model in C/C++")
1108 (description
1109 "This package is a high-performance inference of OpenAI's
1110Whisper automatic speech recognition (ASR) model, implemented in plain C/C++
1111without dependencies, with
1112@itemize
1113@item AVX intrinsics support for x86 architectures
1114@item VSX intrinsics support for POWER architectures
1115@item Mixed F16 / F32 precision
1116@item 4-bit and 5-bit integer quantization support
1117@item Zero memory allocations at runtime
1118@item Support for CPU-only inference
1119@item Efficient GPU support for NVIDIA
1120@item OpenVINO Support
1121@item C-style API
1122@end itemize")
1123 (properties '((tunable? . #true))) ;use AVX512, FMA, etc. when available
1124 (home-page "https://github.com/ggml-org/whisper.cpp/")
1125 (license license:expat)))
1126
1127(define-public mcl
1128 (package
1129 (name "mcl")
1130 (version "14.137")
1131 (source (origin
1132 (method url-fetch)
1133 (uri (string-append
1134 "http://micans.org/mcl/src/mcl-"
1135 (string-replace-substring version "." "-")
1136 ".tar.gz"))
1137 (sha256
1138 (base32
1139 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
1140 (build-system gnu-build-system)
1141 (arguments
1142 (list
1143 #:configure-flags
1144 #~(list "--enable-blast"
1145 (string-append "CFLAGS=-fcommon -g -O2"
1146 " -Wno-error=implicit-function-declaration"))))
1147 (inputs
1148 (list perl))
1149 (home-page "https://micans.org/mcl/")
1150 (synopsis "Clustering algorithm for graphs")
1151 (description
1152 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
1153fast and scalable unsupervised cluster algorithm for graphs (also known as
1154networks) based on simulation of (stochastic) flow in graphs.")
1155 ;; In the LICENCE file and web page it says "The software is licensed
1156 ;; under the GNU General Public License, version 3.", but in several of
1157 ;; the source code files it suggests GPL3 or later.
1158 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
1159 (license license:gpl3)))
1160
1161(define-public ocaml-mcl
1162 (package
1163 (name "ocaml-mcl")
1164 (version "12-068oasis4")
1165 (source
1166 (origin
1167 (method git-fetch)
1168 (uri (git-reference
1169 (url "https://github.com/fhcrc/mcl")
1170 (commit version)))
1171 (file-name (git-file-name name version))
1172 (sha256
1173 (base32
1174 "0009dc3h2jp3qg5val452wngpqnbfyhbcxylghq0mrjqxx0jdq5p"))))
1175 (build-system ocaml-build-system)
1176 (arguments
1177 `(#:phases
1178 (modify-phases %standard-phases
1179 (add-before 'configure 'patch-paths
1180 (lambda _
1181 (substitute* "setup.ml"
1182 (("LDFLAGS=-fPIC")
1183 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh")))
1184 (("-std=c89") "-std=gnu99 -fcommon")
1185
1186 ;; This is a mutable string, which is no longer supported. Use
1187 ;; a byte buffer instead.
1188 (("String.make \\(String.length s\\)")
1189 "Bytes.make (String.length s)")
1190
1191 ;; These two belong together.
1192 (("OASISString.replace_chars")
1193 "Bytes.to_string (OASISString.replace_chars")
1194 ((" s;")
1195 " s);"))
1196 (substitute* "myocamlbuild.ml"
1197 (("std=c89") "std=gnu99 -fcommon"))
1198 ;; Since we build with a more recent OCaml, we have to use C99 or
1199 ;; later. This causes problems with the old C code.
1200 (substitute* "src/impala/matrix.c"
1201 (("restrict") "restrict_"))
1202 #t)))))
1203 (native-inputs
1204 (list ocamlbuild))
1205 (home-page "https://github.com/fhcrc/mcl")
1206 (synopsis "OCaml wrappers around MCL")
1207 (description
1208 "This package provides OCaml bindings for the MCL graph clustering
1209algorithm.")
1210 (license license:gpl3)))
1211
1212(define-public openmm
1213 (package
1214 (name "openmm")
1215 (version "8.5.2")
1216 (source
1217 (origin
1218 (method git-fetch)
1219 (uri (git-reference
1220 (url "https://github.com/openmm/openmm")
1221 (commit version)))
1222 (file-name (git-file-name name version))
1223 (sha256
1224 (base32
1225 "0y62jg9jl4hrwgcpak6gm7pyvr509msx72a5yp2bqlqir2fa0qzn"))))
1226 (build-system cmake-build-system)
1227 (arguments
1228 (list
1229 #:configure-flags
1230 '(list "-DOPENMM_BUILD_SHARED_LIB=TRUE"
1231 "-DOPENMM_BUILD_REFERENCE_TESTS=FALSE" ;takes too long on ci
1232 "-DOPENMM_BUILD_C_AND_FORTRAN_WRAPPERS=TRUE"
1233 "-DOPENMM_BUILD_PYTHON_WRAPPERS=TRUE"
1234 "-DOPENMM_BUILD_CUDA_LIB=FALSE")
1235 #:phases
1236 #~(modify-phases %standard-phases
1237 (add-after 'unpack 'patch-wrappers-python-install
1238 (lambda _
1239 (substitute* "wrappers/python/CMakeLists.txt"
1240 (("install --root=\\\\\\$ENV\\{DESTDIR\\}/")
1241 (string-append "install --prefix=" #$output
1242 " --root=/ --single-version-externally-managed")))))
1243 (add-after 'unpack 'remove-shaky-tests
1244 (lambda _
1245 ;; These tests may unpredictably fail in CI, even passing
1246 ;; locally.
1247 (for-each delete-file
1248 (append '("./serialization/tests/TestSerializeIntegrator.cpp")
1249 (find-files "./platforms"
1250 (string-append "Test.*"
1251 "(BrownianIntegrat|"
1252 "LangevinIntegrator)"
1253 "\\.cpp$"))))))
1254 (add-after 'install 'install-python
1255 (lambda _
1256 (invoke "make" "PythonInstall"))))))
1257 (inputs
1258 (list python-wrapper))
1259 (propagated-inputs
1260 (list python-numpy))
1261 (native-inputs
1262 (list doxygen
1263 gfortran
1264 opencl-headers
1265 python-cython
1266 python-setuptools
1267 swig-4.4))
1268 (home-page "https://github.com/openmm/openmm/")
1269 (synopsis "Toolkit for molecular simulation")
1270 (description
1271 "OpenMM is a toolkit for molecular simulation. It can be used either as
1272a stand-alone application for running simulations, or as a library you call
1273from your own code.")
1274 ;; All licenses are listed in <docs-source/licenses/Licenses.txt>.
1275 (license (list license:cc-by3.0 ;PdbxReader
1276 license:expat ;API, Reference Platform, CPU Platform, VkFFT
1277 license:gpl3 ;Hilbert Curve
1278 license:lgpl3)))) ;CUDA and OpenCL Platforms
1279
1280(define-public r-rcppml/devel
1281 (let ((commit "2beac6580174f8f3ef4ac6fdb2ca2b65705d265a")
1282 (revision "3"))
1283 (package
1284 (name "r-rcppml-devel")
1285 (version (git-version "0.5.6" revision commit))
1286 (source (origin
1287 (method git-fetch)
1288 (uri (git-reference
1289 (url "https://github.com/zdebruine/RcppML")
1290 (commit commit)))
1291 (file-name (git-file-name name version))
1292 (sha256
1293 (base32
1294 "0nv4w2a31bhccblnp5jqylpf9dbbwv07mpkxma40gp8r12k6sv0r"))))
1295 (properties `((upstream-name . "RcppML")))
1296 (build-system r-build-system)
1297 ;; Reported here: https://github.com/zdebruine/RcppML/issues/71
1298 (arguments (list #:tests? #false))
1299 (propagated-inputs (list r-matrix r-rcpp))
1300 (native-inputs (list r-knitr r-testthat))
1301 (home-page "https://github.com/zdebruine/RcppML")
1302 (synopsis "Rcpp machine learning Library")
1303 (description
1304 "This package provides fast machine learning algorithms including
1305matrix factorization and divisive clustering for large sparse and dense
1306matrices.")
1307 (license license:gpl3+))))
1308
1309(define-public openfst
1310 (package
1311 (name "openfst")
1312 (version "1.8.4")
1313 (source (origin
1314 (method url-fetch)
1315 (uri (string-append "https://www.openfst.org/twiki/pub/FST/"
1316 "FstDownload/openfst-" version ".tar.gz"))
1317 (sha256
1318 (base32
1319 "05l057mx1cmbm2jm99mrg75qgz4ca5r78n002mkpxl4j7mpvpsx8"))))
1320 (build-system gnu-build-system)
1321 (arguments '(#:configure-flags '("--enable-ngram-fsts")))
1322 (home-page "https://www.openfst.org")
1323 (synopsis "Library for weighted finite-state transducers")
1324 (description "OpenFst is a library for constructing, combining,
1325optimizing, and searching weighted finite-state transducers (FSTs).")
1326 (license license:asl2.0)))
1327
1328(define openfst-for-vosk
1329 (package
1330 (inherit openfst)
1331 (version "1.8.0")
1332 (source
1333 (origin
1334 (method url-fetch)
1335 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
1336 "FstDownload/openfst-" version ".tar.gz"))
1337 (sha256
1338 (base32 "0h2lfhhihg63b804hrcljnkggijbjmp84i5g8q735wb09y9z2c4p"))
1339 (patches
1340 (search-patches "openfst-for-vosk-fix-unique-ptr.patch"))))
1341 (arguments
1342 '(#:configure-flags
1343 '("--enable-shared" "--enable-far" "--enable-ngram-fsts"
1344 "--enable-lookahead-fsts" "--with-pic" "--disable-bin")))))
1345
1346(define-public sentencepiece
1347 (package
1348 (name "sentencepiece")
1349 (version "0.2.1")
1350 (source
1351 (origin
1352 (method git-fetch)
1353 (uri
1354 (git-reference
1355 (url "https://github.com/google/sentencepiece/")
1356 (commit (string-append "v" version))))
1357 (file-name (git-file-name name version))
1358 (sha256
1359 (base32 "1yzsaam3kk9fqzxfc3nm2pskwq1bdgkrijmcmzmg5x0338rn0hmb"))))
1360 (build-system cmake-build-system)
1361 (arguments (list #:tests? #f)) ;no tests
1362 (native-inputs (list gperftools))
1363 (home-page "https://github.com/google/sentencepiece")
1364 (synopsis "Unsupervised tokenizer for Neural Network-based text generation")
1365 (description
1366 "SentencePiece is an unsupervised text tokenizer and detokenizer mainly
1367for Neural Network-based text generation systems where the vocabulary size is
1368predetermined prior to the neural model training. SentencePiece implements
1369subword units---e.g., byte-pair-encoding (BPE) and unigram language
1370model---with the extension of direct training from raw sentences.
1371SentencePiece allows us to make a purely end-to-end system that does not
1372depend on language-specific pre- or post-processing.")
1373 (license license:asl2.0)))
1374
1375(define-public stable-diffusion-cpp
1376 (package
1377 (name "stable-diffusion-cpp")
1378 (version "827-97d2990")
1379 (source
1380 (origin
1381 (method git-fetch)
1382 (uri (git-reference
1383 (url "https://github.com/leejet/stable-diffusion.cpp")
1384 (commit (string-append "master-" version))
1385 ;; For libwebm 1.0.0, libwepb 1.6.0, and custom fork of ggml.
1386 (recursive? #t)))
1387 (file-name (git-file-name name version))
1388 (sha256
1389 (base32 "1p9b8jvqsxd0dn8ccn0zhxs9nwqx3l20qbp9ybg2dirpja4i0xfm"))))
1390 (build-system cmake-build-system)
1391 (arguments
1392 (list
1393 #:tests? #f ;no tests
1394 ;; see docs/build.md
1395 #:configure-flags
1396 #~(list "-DSD_BUILD_SHARED_LIBS=ON")
1397 #:phases
1398 #~(modify-phases %standard-phases
1399 (add-before 'configure 'set-CXXFLAGS
1400 (lambda _
1401 (setenv "CXXFLAGS" "-DGGML_MAX_NAME=128"))))))
1402 (properties '((tunable? . #true))) ;use AVX512, FMA, etc. when available
1403 (home-page "https://github.com/leejet/stable-diffusion.cpp")
1404 (synopsis "Diffusion model inference in pure C/C++")
1405 (description
1406 "This package provides a Plain C/C++ implementation based
1407on ggml, working in the same way as llama.cpp. It supports diffusion models
1408such as SD, Flux, Wan, Qwen and Image,Z-Image.")
1409 (license license:expat)))
1410
1411(define-public python-hopcroftkarp
1412 ;; This commit fixes a broken import, but has not been released to PyPI.
1413 (let ((commit "2846e1dd3265d95d2bddb0cf4190b830cbb4efe6")
1414 (revision "1"))
1415 (package
1416 (name "python-hopcroftkarp")
1417 (version (git-version "1.2.5" revision commit))
1418 (source
1419 (origin
1420 (method git-fetch)
1421 (uri (git-reference
1422 (url "https://github.com/sofiatolaosebikan/hopcroftkarp")
1423 (commit commit)))
1424 (file-name (git-file-name name version))
1425 (sha256
1426 (base32 "018ilrp41fcclmb5lsml3aijwbmhbq3m7wy65hr1fryj0avic8fr"))))
1427 (build-system pyproject-build-system)
1428 (arguments (list #:test-backend #~'unittest))
1429 (native-inputs (list python-setuptools python-wheel))
1430 (home-page "https://github.com/sofiatolaosebikan/hopcroftkarp")
1431 (synopsis "Implementation of the Hopcroft-Karp algorithm")
1432 (description
1433 "This package implements the Hopcroft-Karp algorithm, producing a maximum
1434cardinality matching from a bipartite graph.")
1435 (license license:gpl3))))
1436
1437(define-public python-paramz
1438 (package
1439 (name "python-paramz")
1440 (version "0.10.0")
1441 (source
1442 (origin
1443 (method git-fetch)
1444 (uri (git-reference
1445 (url "https://github.com/sods/paramz")
1446 (commit (string-append "v" version))))
1447 (file-name (git-file-name name version))
1448 (sha256
1449 (base32 "0h7m7fzb88cx4f8qq2p34z3jv3f48b46pc11is6592zlmrdp67lf"))))
1450 (build-system pyproject-build-system)
1451 (arguments
1452 (list
1453 ;; tests: 114 passed, 4 skipped, 14 warnings
1454 #:test-flags
1455 ;; Compute instance test which times out.
1456 #~(list (string-append "--deselect=paramz/tests/model_tests.py"
1457 "::TestModel::test_optimize_restarts_parallel"))))
1458 (native-inputs
1459 (list python-pytest
1460 python-setuptools))
1461 (propagated-inputs
1462 (list python-decorator
1463 python-numpy
1464 python-scipy
1465 python-six)) ;hard dependency
1466 (home-page "https://github.com/sods/paramz")
1467 (synopsis "The Parameterization Framework")
1468 (description
1469 "@command{paramz} is a lightweight parameterization framework
1470for parameterized model creation and handling. Its features include:
1471
1472@itemize
1473 @item Easy model creation with parameters.
1474 @item Fast optimized access of parameters for optimization routines.
1475 @item Memory efficient storage of parameters (only one copy in memory).
1476 @item Renaming of parameters.
1477 @item Intuitive printing of models and parameters.
1478 @item Gradient saving directly inside parameters.
1479 @item Gradient checking of parameters.
1480 @item Optimization of parameters.
1481 @item Jupyter notebook integration.
1482 @item Efficient storage of models, for reloading.
1483 @item Efficient caching.
1484@end itemize")
1485 (license license:bsd-3)))
1486
1487(define-public python-persim
1488 (package
1489 (name "python-persim")
1490 (version "0.3.8")
1491 (source
1492 (origin
1493 (method url-fetch)
1494 (uri (pypi-uri "persim" version))
1495 (sha256
1496 (base32 "03d4kgakpgj54c3pl9dkqrkbmj6w13gmczkds5jagf3n85c1hgg1"))))
1497 (build-system pyproject-build-system)
1498 (native-inputs
1499 (list python-pytest python-setuptools))
1500 (propagated-inputs
1501 (list python-deprecated
1502 python-hopcroftkarp
1503 python-joblib
1504 python-matplotlib
1505 python-numpy
1506 python-scikit-learn
1507 python-scipy))
1508 (home-page "https://persim.scikit-tda.org")
1509 (synopsis "Tools for analyzing persistence diagrams in Python")
1510 (description
1511 "This package includes a variety of tools used to analyze persistence diagrams.
1512It currently houses implementations of
1513@itemize
1514@item Persistence images
1515@item Persistence landscapes
1516@item Bottleneck distance
1517@item Modified Gromov–Hausdorff distance
1518@item Sliced Wasserstein kernel
1519@item Heat kernel
1520@item Diagram plotting
1521@end itemize
1522")
1523 (license license:expat))) ; MIT License
1524
1525(define-public python-pomegranate
1526 (package
1527 (name "python-pomegranate")
1528 (version "1.1.0")
1529 (source
1530 (origin
1531 (method git-fetch)
1532 (uri (git-reference
1533 (url "https://github.com/jmschrei/pomegranate")
1534 (commit (string-append "v" version))))
1535 (file-name (git-file-name name version))
1536 (sha256
1537 (base32 "0arx5wik4ywna7k7g5y3ggwz98fl1hgap0278pph3c77ap8afqd7"))))
1538 (build-system pyproject-build-system)
1539 (arguments
1540 (list
1541 ;; tests: 830 passed, 19 deselected, 529 warnings
1542 #:test-flags
1543 #~(list #$@(map (lambda (test) (string-append "--deselect="
1544 "tests/distributions/"
1545 test))
1546 ;; _pickle.UnpicklingError: Weights only load failed.
1547 (list "test_bernoulli.py::test_serialization"
1548 "test_categorical.py::test_serialization"
1549 "test_exponential.py::test_serialization"
1550 "test_gamma.py::test_serialization"
1551 "test_independent_component.py::test_serialization"
1552 "test_normal_diagonal.py::test_serialization"
1553 "test_normal_full.py::test_serialization"
1554 "test_poisson.py::test_serialization"
1555 "test_student_t.py::test_serialization"
1556 "test_uniform.py::test_serialization"
1557 ;; Arrays are not almost equal to 3 decimals
1558 "test_categorical.py::test_sample"
1559 "test_independent_component.py::test_sample"
1560 "test_joint_categorical.py::test_sample"
1561 "test_joint_categorical.py::test_sample"))
1562 #$@(map (lambda (test) (string-append "--deselect="
1563 "tests/"
1564 test))
1565 ;; _pickle.UnpicklingError: Weights only load failed.
1566 (list "test_bayes_classifier.py::test_serialization"
1567 "test_gmm.py::test_serialization"
1568 "test_kmeans.py::test_serialization"
1569 ;; Arrays are not almost equal to 3 decimals
1570 "test_bayesian_network.py::test_sample"
1571 "test_gmm.py::test_sample"
1572 "test_markov_chain.py::test_sample"
1573 "test_markov_chain.py::test_sample")))))
1574 (native-inputs
1575 (list python-cython
1576 python-pytest
1577 python-setuptools))
1578 (propagated-inputs
1579 (list python-apricot-select
1580 python-networkx
1581 python-numpy
1582 python-scikit-learn
1583 python-scipy
1584 python-pytorch))
1585 (home-page "https://pypi.python.org/pypi/pomegranate/")
1586 (synopsis "Graphical models library for Python")
1587 (description
1588 "Pomegranate is a graphical models library for Python, implemented in
1589Cython for speed.")
1590 (license license:expat)))
1591
1592(define-public python-pot
1593 (package
1594 (name "python-pot")
1595 (version "0.9.7.post1")
1596 (source
1597 (origin
1598 (method git-fetch)
1599 (uri (git-reference
1600 (url "https://github.com/PythonOT/POT")
1601 (commit version)))
1602 (file-name (git-file-name name version))
1603 (sha256
1604 (base32 "1pcsvxsmilz3xwa8lm5cgllbjjrx9q92nxm2vmb8jlwhh56wan0g"))))
1605 (build-system pyproject-build-system)
1606 ;; tests: 1885 passed, 60 skipped, 6 xfailed, 9288 warnings
1607 (arguments
1608 (list
1609 #:phases
1610 #~(modify-phases %standard-phases
1611 (add-after 'unpack 'use-system-eigen
1612 (lambda* (#:key inputs #:allow-other-keys)
1613 (substitute* "setup.py"
1614 (("os\\.path\\.join\\(ROOT, \"deps/eigen\"\\)")
1615 (format #f "~s"
1616 (search-input-directory inputs
1617 "include/eigen3")))))))))
1618 (native-inputs
1619 (list python-cython
1620 python-pytest
1621 python-setuptools))
1622 (inputs
1623 (list eigen))
1624 (propagated-inputs
1625 (list python-numpy
1626 python-scipy
1627 ;; [optional]
1628 python-autograd
1629 python-cvxopt
1630 ;; python-jax
1631 ;; python-jaxlib
1632 python-matplotlib
1633 python-pymanopt
1634 python-pytorch
1635 python-pytorch-geometric
1636 python-scikit-learn))
1637 (home-page "https://github.com/PythonOT/POT")
1638 (synopsis "Python Optimal Transport Library")
1639 (description
1640 "This Python library provides several solvers for optimization problems
1641related to Optimal Transport for signal, image processing and machine
1642learning.")
1643 (license license:expat)))
1644
1645(define-public python-pymanopt
1646 (package
1647 (name "python-pymanopt")
1648 (version "2.2.1")
1649 (source
1650 (origin
1651 (method url-fetch)
1652 (uri (pypi-uri "pymanopt" version))
1653 (sha256
1654 (base32 "1nm1yz5hbj1valqq23r8c1g9rhfdndfswlqv6xrnvc3f8fd95167"))))
1655 (build-system pyproject-build-system)
1656 (arguments
1657 (list
1658 ;; Tests require jax and tensorflow, which are optional.
1659 #:tests? #false
1660 #:phases
1661 '(modify-phases %standard-phases
1662 ;; This is probably a bad idea. We don't have scipy 1.13 just yet.
1663 (add-after 'unpack 'relax-requirements
1664 (lambda _
1665 (substitute* "pyproject.toml"
1666 ((",!=1.12\\.\\*") "")))))))
1667 (propagated-inputs (list python-numpy python-scipy))
1668 (native-inputs (list python-autograd
1669 python-matplotlib
1670 python-pytest
1671 python-setuptools
1672 python-setuptools-scm
1673 python-wheel))
1674 (home-page "https://pymanopt.org/")
1675 (synopsis "Toolbox for optimization on Riemannian manifolds")
1676 (description
1677 "This package is a toolbox for optimization on Riemannian manifolds with
1678support for automatic differentiation.")
1679 (license license:bsd-3)))
1680
1681(define-public python-ripser
1682 (package
1683 (name "python-ripser")
1684 (version "0.6.14")
1685 (source
1686 (origin
1687 (method git-fetch)
1688 (uri (git-reference
1689 (url "https://github.com/scikit-tda/ripser.py")
1690 (commit (string-append "v" version))))
1691 (file-name (git-file-name name version))
1692 (sha256
1693 (base32
1694 "00na7dpvpc5vwjwgh9ndqrqlswgrzgqf1s7rxfv1vy5wn63fz3m7"))))
1695 (build-system pyproject-build-system)
1696 (propagated-inputs (list python-numpy python-persim python-scikit-learn
1697 python-scipy))
1698 (native-inputs
1699 (list python-cython
1700 python-pytest
1701 python-setuptools))
1702 (home-page "https://ripser.scikit-tda.org")
1703 (synopsis "Persistent homology library for Python")
1704 (description
1705 "This package implements a variety of persistent homology algorithms. It
1706provides an interface for
1707@itemize
1708@item computing persistence cohomology of sparse and dense data sets
1709@item visualizing persistence diagrams
1710@item computing lowerstar filtrations on images
1711@item computing representative cochains
1712@end itemize
1713")
1714 (license license:expat))) ; MIT License
1715
1716(define-public python-sacrebleu
1717 (package
1718 (name "python-sacrebleu")
1719 (version "2.6.0")
1720 (source (origin
1721 (method git-fetch)
1722 (uri (git-reference
1723 (url "https://github.com/mjpost/sacrebleu")
1724 (commit (string-append "v" version))))
1725 (file-name (git-file-name name version))
1726 (sha256
1727 (base32
1728 "0d1s5f4cv668cjpz7zjxl0mjn7jhl6b0y9mx3cf78frzszglvya7"))))
1729 (build-system pyproject-build-system)
1730 (arguments
1731 (list
1732 #:test-flags
1733 ;; These all need internet access.
1734 '(list "-k" "not test_api_get_source \
1735and not test_api_get_reference \
1736and not test_maybe_download \
1737and not test_process_to_text \
1738and not test_get_files_and_fieldnames \
1739and not test_source_and_references \
1740and not test_wmt22_references")
1741 #:phases
1742 '(modify-phases %standard-phases
1743 ;; Needed for tests.
1744 (add-before 'check 'set-HOME
1745 (lambda _ (setenv "HOME" "/tmp"))))))
1746 (propagated-inputs (list python-colorama
1747 python-lxml
1748 python-numpy
1749 python-portalocker
1750 python-regex
1751 python-tabulate))
1752 (native-inputs (list python-pytest python-setuptools python-setuptools-scm))
1753 (home-page "https://github.com/mjpost/sacrebleu")
1754 (synopsis
1755 "Compute shareable, comparable, and reproducible BLEU, chrF, and TER scores")
1756 (description
1757 "This is a package for hassle-free computation of shareable, comparable,
1758and reproducible BLEU, chrF, and TER scores for natural language processing.")
1759 (license license:asl2.0)))
1760
1761(define-public python-safetensors
1762 (package
1763 (name "python-safetensors")
1764 (version "0.4.3")
1765 (source
1766 (origin
1767 (method url-fetch)
1768 (uri (pypi-uri "safetensors" version))
1769 (sha256
1770 (base32 "1hhiwy67jarm70l0k26fs1cjhzkgzrh79q14bklj2yp0qi8gr19g"))
1771 (modules '((guix build utils)
1772 (ice-9 ftw)))
1773 (snippet
1774 #~(begin ;Only keep bindings.
1775 (for-each
1776 (lambda (file)
1777 (unless (member file '("." ".." "bindings" "PKG-INFO"))
1778 (delete-file-recursively file)))
1779 (scandir "."))
1780 (for-each
1781 (lambda (file)
1782 (unless (member file '("." ".."))
1783 (rename-file (string-append "bindings/python/" file)
1784 file)))
1785 (scandir "bindings/python"))
1786 (substitute* "Cargo.toml"
1787 (("^path = .*") ""))))))
1788 (build-system cargo-build-system)
1789 (arguments
1790 (list
1791 #:install-source? #f
1792 #:phases
1793 #~(modify-phases %standard-phases
1794 (add-before 'check 'install-rust-library
1795 (lambda _
1796 (copy-file "target/release/libsafetensors_rust.so"
1797 "py_src/safetensors/_safetensors_rust.so")))
1798 (replace 'check
1799 (lambda* (#:key tests? #:allow-other-keys)
1800 (when tests?
1801 (setenv "PYTHONPATH" (string-append (getcwd) "/py_src"))
1802 (invoke "python3"
1803 "-m" "pytest"
1804 "-n" "auto"
1805 "--dist=loadfile"
1806 "-s" "-v" "./tests/"
1807 ;; Missing jax and tensorflow dependency
1808 "--ignore=./tests/test_flax_comparison.py"
1809 "--ignore=./tests/test_tf_comparison.py"))))
1810 (add-after 'install 'install-python
1811 (lambda _
1812 (let* ((pversion #$(version-major+minor
1813 (package-version python)))
1814 (lib (string-append #$output "/lib/python" pversion
1815 "/site-packages/"))
1816 (info (string-append lib "safetensors-"
1817 #$(package-version this-package)
1818 ".dist-info")))
1819 (mkdir-p info)
1820 (copy-file "PKG-INFO" (string-append info "/METADATA"))
1821 (copy-recursively
1822 "py_src/safetensors"
1823 (string-append lib "safetensors"))))))))
1824 (inputs
1825 (cargo-inputs 'python-safetensors))
1826 (native-inputs
1827 (list python-h5py
1828 python-minimal
1829 python-numpy
1830 python-pytest
1831 python-pytest-xdist
1832 python-pytorch))
1833 (home-page "https://huggingface.co/docs/safetensors")
1834 (synopsis "Simple and safe way to store and distribute tensors")
1835 (description
1836 "This package provides a fast (zero-copy) and safe (dedicated) format for
1837storing tensors safely.")
1838 (license license:asl2.0)))
1839
1840(define-public python-sentencepiece
1841 (package
1842 (inherit sentencepiece)
1843 (name "python-sentencepiece")
1844 (build-system pyproject-build-system)
1845 (arguments
1846 (list
1847 #:phases
1848 #~(modify-phases %standard-phases
1849 (add-after 'unpack 'chdir
1850 (lambda _
1851 (chdir "python"))))))
1852 (native-inputs
1853 (list pkg-config protobuf python-pytest python-setuptools))
1854 (propagated-inputs (list sentencepiece))
1855 (synopsis "SentencePiece python wrapper")
1856 (description "This package provides a Python wrapper for the SentencePiece
1857unsupervised text tokenizer.")))
1858
1859(define-public python-sentence-transformers
1860 (package
1861 (name "python-sentence-transformers")
1862 (version "5.5.0")
1863 (source
1864 (origin
1865 (method git-fetch)
1866 (uri (git-reference
1867 (url "https://github.com/UKPLab/sentence-transformers/")
1868 (commit (string-append "v" version))))
1869 (file-name (git-file-name name version))
1870 (sha256
1871 (base32
1872 "0x6b6gvsasdmm40gr5ld5gwxggpb2j285jv4scvws1bp2s193k9i"))))
1873 (build-system pyproject-build-system)
1874 (arguments
1875 (list #:tests? #f)) ;network access is required
1876 (propagated-inputs (list python-huggingface-hub
1877 python-numpy
1878 python-pillow
1879 python-pytorch
1880 python-typing-extensions
1881 python-scikit-learn
1882 python-scipy
1883 python-tqdm
1884 python-transformers))
1885 (native-inputs (list python-setuptools))
1886 (home-page "https://www.SBERT.net")
1887 (synopsis "Multilingual text embeddings")
1888 (description "This framework provides an easy method to compute dense
1889vector representations for sentences, paragraphs, and images. The models are
1890based on transformer networks like BERT / RoBERTa / XLM-RoBERTa and achieve
1891state-of-the-art performance in various tasks. Text is embedded in vector
1892space such that similar text are closer and can efficiently be found using
1893cosine similarity.
1894
1895This package provides easy access to pretrained models for more than 100
1896languages, fine-tuned for various use-cases.
1897
1898Further, this framework allows an easy fine-tuning of custom embeddings
1899models, to achieve maximal performance on your specific task.")
1900 (license license:asl2.0)))
1901
1902(define-public python-spacy-legacy
1903 (package
1904 (name "python-spacy-legacy")
1905 (version "3.0.12")
1906 (source (origin
1907 (method url-fetch)
1908 (uri (pypi-uri "spacy-legacy" version))
1909 (sha256
1910 (base32
1911 "0x57aw1qgjrzgapsv1cwymqlck2anqm1bisvryhpq7bfkc66wzdk"))))
1912 (build-system pyproject-build-system)
1913 ;; This package depends on spacy, which depends on this package.
1914 (arguments (list #:tests? #false))
1915 (native-inputs (list python-pytest python-setuptools python-wheel))
1916 (home-page "https://spacy.io")
1917 (synopsis "Legacy registered functions for spaCy backwards compatibility")
1918 (description
1919 "This package contains legacy registered functions for spaCy backwards
1920compatibility.")
1921 (license license:expat)))
1922
1923(define-public python-spacy-loggers
1924 (package
1925 (name "python-spacy-loggers")
1926 (version "1.0.4")
1927 (source (origin
1928 (method url-fetch)
1929 (uri (pypi-uri "spacy-loggers" version))
1930 (sha256
1931 (base32
1932 "0a5zjfxd0mci7pwda24ihg55whalpmjby4bvpgar2013f6zq7yg6"))))
1933 (build-system pyproject-build-system)
1934 ;; This package depends on spacy, which depends on this package.
1935 (arguments (list #:tests? #false))
1936 (native-inputs (list python-pytest python-setuptools python-wheel))
1937 (home-page "https://github.com/explosion/spacy-loggers")
1938 (synopsis "Logging utilities for SpaCy")
1939 (description "This package provides logging utilities for the SpaCy
1940natural language processing framework.")
1941 (license license:expat)))
1942
1943(define-public python-spacy
1944 (package
1945 (name "python-spacy")
1946 (version "3.8.14")
1947 (source
1948 (origin
1949 (method git-fetch)
1950 (uri (git-reference
1951 (url "https://github.com/explosion/spaCy")
1952 (commit (string-append "release-v" version))))
1953 (file-name (git-file-name name version))
1954 (sha256
1955 (base32 "0inb1x7gmf1j7kcr35v472hia4lkn1qr234snqkz27rqglzhvmy3"))))
1956 (build-system pyproject-build-system)
1957 (arguments
1958 (list
1959 ;; tests: 3605 passed, 1232 skipped, 6 deselected, 24 xfailed, 7
1960 ;; xpassed, 5 subtests passed
1961 #:test-flags
1962 #~(list #$@(map (lambda (test)
1963 (string-append "--deselect=tests/" test))
1964 (list
1965 ;; Fail to compare setup.cfg and requirements.txt
1966 ;; versions.
1967 "package/test_requirements.py::test_build_dependencies"
1968 ;; Result
1969 ;; DeprecationWarning('datetime.datetime.utcfromtimestamp()
1970 ;; is deprecated and scheduled for removal in a future
1971 ;; version. Use timezone-aware objects to represent
1972 ;; datetimes in UTC:
1973 ;; datetime.datetime.fromtimestamp(timestamp,
1974 ;; datetime.UTC).'
1975 "test_cli_app.py::test_project_assets"
1976 "test_cli_app.py::test_project_push_pull"
1977 ;; AssertionError: Registry 'loggers' missing entries.
1978 "test_registry_population.py::test_registry_entries"
1979 ;; Tests require network access.
1980 "test_cli.py::test_download_compatibility"
1981 "test_cli.py::test_validate_compatibility_table")))
1982 #:phases
1983 #~(modify-phases %standard-phases
1984 (add-before 'check 'remove-local-spacy
1985 (lambda _
1986 (copy-recursively "spacy/tests" "tests")
1987 ;; This would otherwise interfere with finding the installed
1988 ;; spacy when running tests.
1989 (delete-file-recursively "spacy"))))))
1990 (propagated-inputs (list python-catalogue
1991 python-cymem
1992 python-jinja2
1993 python-murmurhash
1994 python-numpy
1995 python-preshed
1996 python-pydantic
1997 python-requests
1998 python-spacy-legacy
1999 python-spacy-loggers
2000 python-srsly
2001 python-thinc
2002 python-tqdm
2003 python-typer
2004 python-wasabi
2005 python-weasel))
2006 (native-inputs
2007 (list python-cython
2008 python-pytest
2009 python-mock
2010 python-setuptools))
2011 (home-page "https://spacy.io")
2012 (synopsis "Natural Language Processing (NLP) in Python")
2013 (description
2014 "SpaCy is a library for advanced Natural Language Processing in Python
2015and Cython. It comes with pretrained pipelines and currently supports
2016tokenization and training for 70+ languages. It features state-of-the-art
2017speed and neural network models for tagging, parsing, named entity
2018recognition, text classification and more, multi-task learning with pretrained
2019transformers like BERT, as well as a production-ready training system and easy
2020model packaging, deployment and workflow management.")
2021 (license license:expat)))
2022
2023(define-public python-stanza
2024 (package
2025 (name "python-stanza")
2026 (version "1.10.1")
2027 (source
2028 (origin
2029 (method git-fetch)
2030 (uri (git-reference
2031 (url "https://github.com/stanfordnlp/stanza")
2032 (commit (string-append "v" version))))
2033 (sha256
2034 (base32 "0zcpzmbv0aafircl12m3x5999hxpg2hzm1xxv97pz09y4v589snj"))))
2035 (build-system pyproject-build-system)
2036 (arguments
2037 (list
2038 #:phases
2039 #~(modify-phases %standard-phases
2040 (add-before 'check 'set-up-check
2041 (lambda _
2042 ;; Cherry pick from stanza/tests/setup.py,
2043 ;; which downloads many datasets
2044 (mkdir-p "stanza_test/out")
2045 (copy-file "stanza/tests/data/example_french.json"
2046 "stanza_test/out/example_french.json"))))
2047 ;; tests: 288 passed, 361 deselected, 1 warning
2048 #:test-flags
2049 #~(list
2050 "-k"
2051 (string-join
2052 '("not CoreNLP" "EnglishPipeline" "FrenchPipeline"
2053 "SentimentPipeline" "TestTrainer"
2054 "amt_annotator" "arabic_pos" "bert"
2055 "charlm" "conllu" "convert_units"
2056 "data_objects" "defaultdict_config"
2057 "depparse" "dictionary" "download"
2058 "ensemble" "example" "finetune" "install"
2059 "langid" "lemmatizer" "long_paragraph" "long_tokens"
2060 "model" "morphology" "multilingual" "mwt"
2061 "pipeline_" "pretrain" "process_doc"
2062 "read_snippets" "register" "reload"
2063 "requirements" "resources" "retag"
2064 "score" "semgrex" "serialized" "server_" "ssurgeon"
2065 "tagger" "test_core" "test_one_sentence" "test_tokenizer"
2066 "text_processing" "tokenize_files" "tokensregex"
2067 "train_pipeline" "training" "tsurgeon")
2068 " and not ") ;exclude tests requiring datasets
2069 "stanza/tests")))
2070 (native-inputs (list python-pytest
2071 python-setuptools
2072 python-transformers))
2073 (propagated-inputs (list python-emoji
2074 python-networkx
2075 python-numpy
2076 python-protobuf
2077 python-pytorch
2078 python-requests
2079 python-tqdm))
2080 (home-page "https://stanfordnlp.github.io/stanza/")
2081 (synopsis "Stanford NLP Python library for many human languages")
2082 (description
2083 "Stanza is a collection of accurate and efficient tools
2084for the linguistic analysis of many human languages. Starting from raw text,
2085Stanza divides it into sentences and words, and then can recognize
2086parts of speech and entities, do syntactic analysis, and more.")
2087 (license license:asl2.0)))
2088
2089(define-public onnx
2090 (package
2091 (name "onnx")
2092 (version "1.17.0")
2093 (source (origin
2094 (method git-fetch)
2095 (uri (git-reference
2096 (url "https://github.com/onnx/onnx")
2097 (commit (string-append "v" version))))
2098 (sha256
2099 (base32
2100 "1i6bh4z2xzz1maykr0xmrwfybm6i3g38vnx7hsls8hr58rdr30zn"))
2101 (file-name (git-file-name name version))
2102 (patches (search-patches
2103 "onnx-shared-libraries.patch"
2104 "onnx-skip-model-downloads.patch"))
2105 (modules '((guix build utils)))
2106 (snippet '(delete-file-recursively "third_party"))))
2107 (build-system pyproject-build-system)
2108 (arguments
2109 (list
2110 ;; python-nbval depends transitively on Rust.
2111 #:tests?
2112 (->bool (member (or (%current-target-system)
2113 (%current-system))
2114 (package-transitive-supported-systems python-nbval)))
2115 ;; tests: 4610 passed, 3044 skipped, 7 deselected, 13 warnings, 98
2116 ;; subtests passed
2117 #:test-flags
2118 ;; XXX: Onnx is on old version and might need to be updated, see:
2119 ;; <https://codeberg.org/guix/guix/issues/9443>.
2120 #~(list #$@(map (lambda (ls) (string-append "--deselect=onnx/"
2121 (string-join ls "::")))
2122 '(("test/test_backend_reference.py"
2123 "OnnxBackendNodeModelTest"
2124 "test_affine_grid_2d_align_corners_expanded_cpu")
2125 ("test/test_backend_reference.py"
2126 "OnnxBackendNodeModelTest"
2127 "test_affine_grid_2d_expanded_cpu")
2128 ("test/test_backend_reference.py"
2129 "OnnxBackendNodeModelTest"
2130 "test_affine_grid_3d_align_corners_expanded_cpu")
2131 ("test/test_backend_reference.py"
2132 "OnnxBackendNodeModelTest"
2133 "test_affine_grid_3d_expanded_cpu")
2134 ("test/tools_test.py" "TestToolsFunctions"
2135 "test_replace_range")
2136 ("test/tools_test.py"
2137 "TestToolsFunctions" "test_replace_range_function")
2138 ("test/tools_test.py"
2139 "TestToolsFunctions" "test_replace_range_graph"))))
2140 #:phases
2141 #~(modify-phases %standard-phases
2142 (add-before 'build 'pass-cmake-arguments
2143 (lambda* (#:key outputs tests? #:allow-other-keys)
2144 ;; For derived package use
2145 (substitute* "CMakeLists.txt"
2146 (("set\\(ONNX_ROOT.*") "")
2147 (("\\$\\{ROOT_DIR\\}(/tools.*)" _ rest)
2148 (string-append "${PROJECT_SOURCE_DIR}" rest)))
2149 ;; Pass options to the CMake-based build process.
2150 (define out
2151 (assoc-ref outputs "out"))
2152
2153 (define args
2154 ;; Copy arguments from 'cmake-build-system', plus ask
2155 ;; for shared libraries.
2156 (list "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
2157 (string-append "-DCMAKE_INSTALL_PREFIX=" out)
2158 "-DCMAKE_INSTALL_LIBDIR=lib"
2159 "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE"
2160 (string-append "-DCMAKE_INSTALL_RPATH=" out
2161 "/lib")
2162 "-DCMAKE_VERBOSE_MAKEFILE=ON"
2163 (string-append "-DONNX_BUILD_TESTS="
2164 (if tests? "ON" "OFF"))
2165 "-DBUILD_SHARED_LIBS=ON"
2166 "-DONNX_USE_PROTOBUF_SHARED_LIBS=ON"
2167 (string-append
2168 "-DONNX_ROOT=" #$(package-source this-package))))
2169
2170 ;; This environment variable is honored by 'setup.py',
2171 ;; which passes it down to 'cmake'.
2172 (setenv "CMAKE_ARGS" (string-join args))
2173
2174 ;; This one is honored by 'setup.py' and passed to 'make -j'.
2175 (setenv "MAX_JOBS"
2176 (number->string (parallel-job-count)))))
2177 (add-before 'check 'make-test-directory-writable
2178 (lambda _
2179 ;; Make things writable for tests.
2180 (setenv "HOME" (getcwd))
2181 (for-each make-file-writable
2182 (find-files "onnx/examples" "."
2183 #:directories? #t))))
2184 (add-after 'install 'install-from-cmake
2185 (lambda _
2186 ;; Run "make install" in the build tree 'setup.py'
2187 ;; created for CMake so that libonnx.so,
2188 ;; libonnx_proto.so, etc. are installed.
2189 (invoke "make" "install"
2190 "-C" ".setuptools-cmake-build"))))))
2191 (native-inputs
2192 (append
2193 (list cmake-minimal
2194 googletest
2195 pybind11-2
2196 python-fb-re2
2197 python-parameterized
2198 python-pytest
2199 python-setuptools
2200 python-wheel)
2201 (filter
2202 (lambda (pkg)
2203 (member (or (%current-target-system)
2204 (%current-system))
2205 (package-transitive-supported-systems pkg)))
2206 (list python-nbval))))
2207 (inputs
2208 (list protobuf))
2209 (propagated-inputs
2210 (list python-numpy python-protobuf python-six python-tabulate
2211 python-typing-extensions))
2212 (home-page "https://onnx.ai/")
2213 (synopsis "Open Neural Network Exchange")
2214 (description
2215 "@acronym{ONNX, Open Neural Network Exchange} is a format for AI models,
2216both deep learning and traditional @acronym{ML, machine learning}. It defines
2217an extensible computation graph model, as well as definitions of built-in
2218operators and standard data types.")
2219 (license license:expat)))
2220
2221(define-public onnx-for-onnxruntime
2222 (package
2223 (inherit onnx)
2224 (name "onnx-for-onnxruntime")
2225 (source
2226 (origin
2227 (inherit (package-source onnx))
2228 (patches (append (search-patches "onnx-1.17.0-for-onnxruntime.patch")
2229 (origin-patches (package-source onnx))))))
2230 ;; Use cmake-build-system instead of pyproject-build-system so that
2231 ;; only the C++ static library is built and installed. The Python
2232 ;; onnx package (with schemas registered) is provided by regular
2233 ;; onnx; this variant has ONNX_DISABLE_STATIC_REGISTRATION=ON which
2234 ;; would break onnx.shape_inference if its Python files ended up on
2235 ;; PYTHONPATH.
2236 (build-system cmake-build-system)
2237 (arguments
2238 (list
2239 #:tests? #f ; tests fail without schema registration
2240 #:configure-flags
2241 #~(list "-DBUILD_SHARED_LIBS=OFF"
2242 "-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF"
2243 ;; Disable ONNX's schema registration so onnxruntime
2244 ;; handles it. See
2245 ;; <https://onnxruntime.ai/docs/build/dependencies.html>.
2246 "-DONNX_DISABLE_STATIC_REGISTRATION=ON"
2247 "-DONNX_BUILD_TESTS=OFF"
2248 "-DONNX_BUILD_BENCHMARKS=OFF"
2249 "-DONNX_ML=ON"
2250 "-DONNX_USE_LITE_PROTO=OFF"
2251 "-DBUILD_ONNX_PYTHON=OFF")))
2252 (inputs (list protobuf-static-for-onnxruntime))
2253 (native-inputs (list python-minimal-wrapper pybind11))
2254 (propagated-inputs '())
2255 (description
2256 "This variant of the ONNX package is built as a static C++ library
2257with schema registration disabled, for linking into onnxruntime. It
2258should not be used standalone.")))
2259
2260(define-public onnx-optimizer
2261 (package
2262 (name "onnx-optimizer")
2263 ;; Note: 0.3.x is *more* recent than 1.5.0.
2264 (version "0.3.19")
2265 (home-page "https://github.com/onnx/optimizer")
2266 (source (origin
2267 (method git-fetch)
2268 (uri (git-reference
2269 (url home-page)
2270 (commit (string-append "v" version))))
2271 (sha256
2272 (base32
2273 "1mx3hsl42na6fr05nh2x3j9kxm56cpfmwk6lwl2cfq9zs3gv929w"))
2274 (file-name (git-file-name name version))
2275 (patches (search-patches "onnx-optimizer-system-library.patch"))
2276 (modules '((guix build utils)))
2277 (snippet '(delete-file-recursively "third_party"))))
2278 (build-system pyproject-build-system)
2279 (arguments
2280 ;; reuse build system tweaks
2281 (substitute-keyword-arguments (package-arguments onnx)
2282 ((#:phases phases)
2283 #~(modify-phases #$phases
2284 (add-after 'pass-cmake-arguments
2285 'pass-onnx-optimizer-cmake-arguments
2286 (lambda _
2287 (setenv
2288 "CMAKE_ARGS"
2289 (string-append
2290 (getenv "CMAKE_ARGS")
2291 " -DONNX_OPT_USE_SYSTEM_PROTOBUF=ON"
2292 " -DCMAKE_CXX_FLAGS=\"-DONNX_ML=1 -DONNX_NAMESPACE=onnx\""))))
2293 (replace 'check
2294 (lambda* (#:key tests? #:allow-other-keys)
2295 (if tests?
2296 (invoke "pytest" "-vv" "-k"
2297 ;; These tests fail with upstream ONNX:
2298 ;; https://github.com/onnx/optimizer/issues/138
2299 (string-append
2300 "not test_fuse_matmul"
2301 " and not test_fuse_consecutive"
2302 " and not test_fuse_transpose")))))))))
2303 (native-inputs
2304 (append
2305 (list cmake-minimal
2306 python-pytest
2307 python-setuptools)
2308 (filter
2309 (lambda (pkg)
2310 (member (or (%current-target-system)
2311 (%current-system))
2312 (package-transitive-supported-systems pkg)))
2313 (list python-nbval))))
2314 (inputs
2315 ;; Must use the same protobuf as onnx to avoid loading two protobuf
2316 ;; libraries causing duplicate schema registration.
2317 (list onnx protobuf pybind11-2))
2318 (propagated-inputs
2319 (list python-numpy))
2320 (synopsis "Library to optimize ONNX models")
2321 (description
2322 "This package provides a C++ and Python library for performing arbitrary
2323optimizations on ONNX models, as well as a growing list of prepackaged
2324optimization passes.
2325
2326Not all possible optimizations can be directly implemented on ONNX graphs---
2327some will need additional backend-specific information---but many can, and the
2328aim is to provide all such passes along with ONNX so that they can be re-used
2329with a single function call.")
2330 (license license:expat)))
2331
2332(define-public onnxruntime
2333 (package
2334 (name "onnxruntime")
2335 (version "1.22.0")
2336 (source
2337 (origin
2338 (method git-fetch)
2339 (uri (git-reference
2340 (url "https://github.com/microsoft/onnxruntime")
2341 (commit (string-append "v" version))))
2342 (file-name (git-file-name name version))
2343 (sha256
2344 (base32 "0z2s79l4wdilssw9lmj319ypyyqi2y0dx0fpwr2yhq8bax3ci50n"))
2345 (patches
2346 (search-patches
2347 ;; SplitToSequence operator was missing bool type support, despite
2348 ;; the ONNX spec allowing it in models. Fixed upstream in 1.23+,
2349 ;; but we cannot upgrade because ROCm support was removed in 1.23.
2350 ;; <https://github.com/microsoft/onnxruntime/pull/24929>
2351 "onnxruntime-1.22.0-splittosequence-bool.patch"))))
2352 (build-system cmake-build-system)
2353 (arguments
2354 (list
2355 #:modules '((guix build cmake-build-system)
2356 (guix build utils)
2357 ((guix build pyproject-build-system) #:prefix py:))
2358 #:imported-modules (append %cmake-build-system-modules
2359 %pyproject-build-system-modules)
2360 #:configure-flags
2361 #~(list "-Donnxruntime_BUILD_UNIT_TESTS=OFF"
2362 "-Donnxruntime_BUILD_SHARED_LIB=ON"
2363 "-Donnxruntime_ENABLE_LTO=ON"
2364 "-Donnxruntime_ENABLE_PYTHON=ON"
2365 "-Donnxruntime_USE_FULL_PROTOBUF=ON"
2366 ;; Link static protobuf, matching upstream's vcpkg approach.
2367 ;; This keeps the protobuf descriptor pool inside
2368 ;; onnxruntime_pybind11_state.so separate from the shared
2369 ;; libprotobuf.so used by the regular onnx Python package.
2370 "-DProtobuf_USE_STATIC_LIBS=ON"
2371 ;; XXX: Fixes build with gcc@14.
2372 "-DCMAKE_CXX_FLAGS=-Wl,-z,noexecstack")
2373 #:phases
2374 #~(modify-phases %standard-phases
2375 (add-after 'unpack 'chdir
2376 (lambda _
2377 (chdir "cmake")))
2378 (add-after 'unpack 'relax-dependencies
2379 (lambda _
2380 (with-output-to-file "cmake/external/eigen.cmake"
2381 (lambda _
2382 (display "find_package(Eigen3 REQUIRED)\n")))
2383 (substitute* "cmake/external/abseil-cpp.cmake"
2384 (("20240722")
2385 (car (string-split #$(package-version
2386 (this-package-input "abseil-cpp"))
2387 #\.))))))
2388 (add-after 'unpack 'fix-numpy
2389 ;; Prevent TypeError: only 0-dimensional arrays can be converted
2390 ;; to Python scalars.
2391 ;; Fixed upstream in 71d2cd0173c863ee67b3a6803aea248c563d5427.
2392 (lambda _
2393 (substitute*
2394 "onnxruntime/python/tools/transformers/fusion_attention.py"
2395 (("float\\(mul_val)") "mul_val.item()"))))
2396 (add-after 'install 'build-python
2397 (lambda _
2398 (invoke "python3" "../setup.py" "bdist_wheel")))
2399 (add-after 'build-python 'install-python
2400 (lambda* (#:key inputs #:allow-other-keys)
2401 ((assoc-ref py:%standard-phases 'install)
2402 #:inputs inputs
2403 #:outputs `(("out" . ,#$output:python)))))
2404 (add-after 'install-python 'add-install-to-pythonpath
2405 (lambda* (#:key inputs #:allow-other-keys)
2406 ((assoc-ref py:%standard-phases 'add-install-to-pythonpath)
2407 #:inputs inputs
2408 #:outputs `(("out" . ,#$output:python)))))
2409 (delete 'check)
2410 (add-after 'add-install-to-pythonpath 'check
2411 (lambda* (#:key tests? #:allow-other-keys)
2412 (with-directory-excursion "../onnxruntime/test/python"
2413 ((assoc-ref py:%standard-phases 'check)
2414 #:tests? tests?
2415 #:test-flags
2416 `(;; XXX: NotImplementedError
2417 "--ignore-glob=quantization/*"
2418 ;; XXX: These tests require transformer models or have
2419 ;; import issues.
2420 "--ignore=transformers/test_generation.py"
2421 "--ignore=transformers/test_gpt2_benchmark.py"
2422 "--ignore=transformers/test_gpt2_to_onnx.py"
2423 "--ignore=transformers/test_optimizer_huggingface_bert.py"
2424 "--ignore=transformers/test_parity_huggingface_gpt_attention.py"
2425 "--ignore=transformers/test_shape_infer_helper.py"
2426 ;; XXX: onnxscript ModuleNotFound
2427 "--ignore=transformers/test_gelu_fusions.py"
2428 "--ignore=transformers/test_gemma3_vision.py"
2429 ;; XXX: PyTorch 2.9 ONNX exporter requires python-onnxscript.
2430 ;; Skip exporter-dependent tests until packaged/enabled.
2431 "--ignore=test_pytorch_export_contrib_ops.py"
2432 "--ignore=transformers/test_parity_gelu.py"
2433 "--ignore=transformers/test_parity_layernorm.py"
2434 "--ignore=transformers/test_phi_vision.py"
2435 ;; XXX: Other failing tests.
2436 "-k" ,(string-append
2437 "not test_gelu_is_fused_by_default"
2438 " and not test_inverse"))))))
2439 (add-after 'check 'python-sanity-check
2440 (lambda* (#:key tests? inputs #:allow-other-keys)
2441 ((assoc-ref py:%standard-phases 'sanity-check)
2442 #:inputs `(("sanity-check.py" . ,#$(default-sanity-check.py))
2443 ,@inputs)
2444 #:outputs `(("out" . ,#$output:python))))))))
2445 (outputs (list "out" "python"))
2446 (inputs
2447 (list abseil-cpp-20250127
2448 boost
2449 cpuinfo
2450 dlpack
2451 c++-gsl
2452 date
2453 eigen-for-onnxruntime
2454 flatbuffers-23.5
2455 googletest
2456 nlohmann-json
2457 onnx-for-onnxruntime
2458 protobuf-static-for-onnxruntime
2459 pybind11-2
2460 re2-next
2461 safeint
2462 zlib))
2463 (native-inputs
2464 (list pkg-config
2465 python-einops
2466 python-wrapper
2467 python-numpy
2468 python-parameterized
2469 python-psutil
2470 python-pytest
2471 python-pytorch
2472 python-sentencepiece
2473 python-setuptools))
2474 (propagated-inputs
2475 (list python-coloredlogs
2476 python-flatbuffers
2477 python-protobuf
2478 python-sympy))
2479 (home-page "https://github.com/microsoft/onnxruntime")
2480 (synopsis "Cross-platform, high performance scoring engine for ML models")
2481 (description
2482 "ONNX Runtime is a performance-focused complete scoring engine
2483for Open Neural Network Exchange (ONNX) models, with an open
2484extensible architecture to continually address the latest developments
2485in AI and Deep Learning. ONNX Runtime stays up to date with the ONNX
2486standard with complete implementation of all ONNX operators, and
2487supports all ONNX releases (1.2+) with both future and backwards
2488compatibility.")
2489 (license license:expat)))
2490
2491(define-public gemmlowp
2492 (let ((commit "16e8662c34917be0065110bfcd9cc27d30f52fdf")
2493 (version "0.1")
2494 (revision "2"))
2495 (package
2496 (name "gemmlowp")
2497 (version (git-version version revision commit))
2498 (source
2499 (origin
2500 (method git-fetch)
2501 (uri (git-reference
2502 (url "https://github.com/google/gemmlowp")
2503 (commit commit)))
2504 (file-name (git-file-name name version))
2505 (sha256
2506 (base32 "02xmrv921al94nihiqrvi8inlq6qc07j0zll3f9qi8322r31x83v"))))
2507 (arguments
2508 (list
2509 #:configure-flags
2510 #~(list #$@(match (%current-system)
2511 ((or "x86_64-linux" "i686-linux")
2512 '("-DCMAKE_CXX_FLAGS=-msse2"))
2513 (_ '()))
2514 "-DBUILD_SHARED_LIBS=ON")
2515 #:phases
2516 #~(modify-phases %standard-phases
2517 ;; This directory contains the CMakeLists.txt.
2518 (add-after 'unpack 'chdir
2519 (lambda _
2520 (chdir "contrib")))
2521 ;; There is no install target
2522 (replace 'install
2523 (lambda _
2524 (let ((lib (string-append #$output "/lib/")))
2525 (install-file "../build/libeight_bit_int_gemm.so" lib)
2526 (for-each
2527 (lambda (dir)
2528 (let ((target (string-append #$output
2529 "/include/gemmlowp/" dir)))
2530 (for-each (lambda (h)
2531 (install-file h target))
2532 (find-files (string-append "../" dir)
2533 "\\.h$"))))
2534 '("meta" "profiling" "public" "fixedpoint"
2535 "eight_bit_int_gemm" "internal"))))))))
2536 (build-system cmake-build-system)
2537 (home-page "https://github.com/google/gemmlowp")
2538 (synopsis "Small self-contained low-precision GEMM library")
2539 (description
2540 "This is a small self-contained low-precision @dfn{general matrix
2541multiplication} (GEMM) library. It is not a full linear algebra library.
2542Low-precision means that the input and output matrix entries are integers on
2543at most 8 bits. To avoid overflow, results are internally accumulated on more
2544than 8 bits, and at the end only some significant 8 bits are kept.")
2545 (license license:asl2.0))))
2546
2547(define-public dlib
2548 (package
2549 (name "dlib")
2550 (version "20.0")
2551 (source
2552 (origin
2553 (method git-fetch)
2554 (uri (git-reference
2555 (url "https://github.com/davisking/dlib.git")
2556 (commit (string-append "v" version))))
2557 (file-name (git-file-name name version))
2558 (sha256
2559 (base32 "1k6jwbb7n842snd2znv0ix8zwa4a35y324jb7mpkj0vn9arzndam"))
2560 (modules '((guix build utils)))
2561 (snippet
2562 '(begin
2563 (delete-file-recursively "dlib/external")))))
2564 (build-system cmake-build-system)
2565 (arguments
2566 (list
2567 #:configure-flags #~(list "-DBUILD_SHARED_LIBS=ON")
2568 #:phases
2569 #~(modify-phases %standard-phases
2570 (add-after 'unpack 'disable-asserts
2571 (lambda _
2572 ;; config.h recommends explicitly enabling or disabling asserts
2573 ;; when building as a shared library. By default neither is set.
2574 (substitute* "dlib/config.h"
2575 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))))
2576 (add-after 'disable-asserts 'disable-failing-tests
2577 (lambda _
2578 ;; One test times out on MIPS, so we need to disable it.
2579 ;; Others are flaky on some platforms.
2580 (let* ((system #$(or (%current-target-system)
2581 (%current-system)))
2582 (disabled-tests (cond
2583 ((string-prefix? "mips64" system)
2584 '("object_detector" ; timeout
2585 "data_io"))
2586 ((string-prefix? "armhf" system)
2587 '("learning_to_track"))
2588 ((string-prefix? "i686" system)
2589 '("optimization"))
2590 (else '()))))
2591 (for-each
2592 (lambda (test)
2593 (substitute* "dlib/test/makefile"
2594 (((string-append "SRC \\+= " test "\\.cpp")) "")))
2595 disabled-tests))))
2596 (add-before 'configure 'fix-test-build-error-with-gcc-14.3
2597 (lambda _
2598 (substitute* "dlib/test/CMakeLists.txt"
2599 ;; Some flags are activated specifically for GCC 14.0 but they
2600 ;; are needed for current GCC version (14.3.0). Let's assume
2601 ;; they are needed for the 14.x branch.
2602 (("14\\.0\\.1")
2603 "14.99")
2604 ;; Tests use deprecated functions from ffmpeg.
2605 (("-Werror\\)")
2606 "-Werror -Wno-error=deprecated-declarations)"))))
2607 (replace 'check
2608 (lambda _
2609 ;; XXX: This causes a rebuild--however, trying to run the tests
2610 ;; without rebuilding causes a lot of errors.
2611 ;; Also, the official way is to rebuild.
2612 (mkdir "../source/dlib/test/build")
2613 (with-directory-excursion "../source/dlib/test/build"
2614 (invoke "cmake" "-DBUILD_SHARED_LIBS=ON" "..")
2615 (invoke "cmake" "--build" "." "--config" "Release")
2616 (invoke "./dtest" "--runall")))))))
2617 (native-inputs
2618 (list pkg-config))
2619 (inputs
2620 (list ffmpeg
2621 giflib
2622 libjpeg-turbo
2623 libjxl
2624 libpng
2625 libwebp
2626 libx11
2627 openblas
2628 pybind11-2
2629 zlib))
2630 (synopsis
2631 "Toolkit for making machine learning and data analysis applications in
2632C++")
2633 (description
2634 "Dlib is a modern C++ toolkit containing machine learning algorithms and
2635tools. It is used in both industry and academia in a wide range of domains
2636including robotics, embedded devices, mobile phones, and large high
2637performance computing environments.")
2638 (home-page "http://dlib.net")
2639 (license license:boost1.0)))
2640
2641(define-public python-scikit-learn
2642 (package
2643 (name "python-scikit-learn")
2644 (version "1.9.0")
2645 (source
2646 (origin
2647 (method git-fetch)
2648 (uri (git-reference
2649 (url "https://github.com/scikit-learn/scikit-learn")
2650 (commit version)))
2651 (file-name (git-file-name name version))
2652 (sha256
2653 (base32 "0ay9zqlv1gimi6smxxjf29rvq3d923hdp34x731gd57rvbf22h3p"))))
2654 (build-system pyproject-build-system)
2655 (arguments
2656 (list
2657 ;; tests: 35838 passed, 11167 skipped, 226 xfailed, 119 xpassed, 5155 warnings
2658 #:test-flags
2659 #~(list "--numprocesses" (number->string (min 8 (parallel-job-count)))
2660 "-m" "not network"
2661 "--pyargs" "sklearn")
2662 #:phases
2663 #~(modify-phases %standard-phases
2664 (add-after 'unpack 'patch-pyproject
2665 (lambda _
2666 (substitute* "pyproject.toml"
2667 ;; FIXME: This line contains regexps and breaks toml parser.
2668 (("notice-rgx.*") ""))))
2669 (add-before 'build 'configure
2670 (lambda _
2671 (setenv "SKLEARN_BUILD_PARALLEL"
2672 (number->string (parallel-job-count)))))
2673 (add-before 'check 'pre-check
2674 (lambda _
2675 ;; Restrict OpenBLAS threads to prevent segfaults while
2676 ;; testing!
2677 (setenv "OPENBLAS_NUM_THREADS" "1")
2678 ;; Some tests require write access to $HOME.
2679 (setenv "HOME" "/tmp")
2680 (delete-file-recursively "sklearn"))))))
2681 (inputs
2682 (list openblas))
2683 (native-inputs
2684 (list gfortran
2685 python-meson
2686 python-pandas
2687 python-pytest
2688 python-pytest-xdist))
2689 (propagated-inputs
2690 (list python-joblib
2691 python-narwhals-minimal ;to reduce closure size
2692 python-numpy
2693 python-scipy
2694 python-threadpoolctl))
2695 (home-page "https://scikit-learn.org/")
2696 (synopsis "Machine Learning in Python")
2697 (description
2698 "Scikit-learn provides simple and efficient tools for data mining and
2699data analysis.")
2700 (license license:bsd-3)))
2701
2702;; 1.7 intorduced breaking changes in API.
2703(define-public python-scikit-learn-1.6
2704 (package
2705 (inherit python-scikit-learn)
2706 (name "python-scikit-learn")
2707 (version "1.6.1")
2708 (source
2709 (origin
2710 (method git-fetch)
2711 (uri (git-reference
2712 (url "https://github.com/scikit-learn/scikit-learn")
2713 (commit version)))
2714 (file-name (git-file-name name version))
2715 (sha256
2716 (base32 "08z1b58n31grfvl42wi6rdwrfhrdhnzkkxhg19iag3zkvkcvxqjl"))))
2717 (arguments
2718 (substitute-keyword-arguments arguments
2719 ((#:test-flags flags)
2720 #~(list "--numprocesses" (number->string (min 8 (parallel-job-count)))
2721 "-m" "not network"
2722 "-k" (string-join
2723 (list "not test_ard_accuracy_on_easy_problem"
2724 "test_check_inplace_ensure_writeable"
2725 "test_check_is_fitted_with_attributes"
2726 "test_covariance"
2727 "test_estimators"
2728 "test_newton_cholesky_fallback_to_lbfgs[42]"
2729 "test_logistic_regression_path_convergence_fail"
2730 "test_linalg_warning_with_newton_solver[42]"
2731 "test_ledoit_wolf"
2732 "test_mcd"
2733 "test_mcd_issue1127"
2734 "test_mcd_support_covariance_is_zero"
2735 "test_oas"
2736 "test_shrunk_covariance"
2737 "test_toy_ard_object")
2738 " and not ")))
2739 ((#:phases phases)
2740 #~(modify-phases #$phases
2741 (add-after 'unpack 'remove-broken-tests
2742 (lambda _
2743 ;; ImportError: cannot import name 'ColMajor' from
2744 ;; 'sklearn.utils._cython_blas'
2745 ;; (<...>/_cython_blas.cpython-311-x86_64-linux-gnu.so)
2746 (delete-file-recursively "sklearn/utils/tests/test_cython_blas.py")))))))))
2747
2748(define-public python-mord
2749 (package
2750 (name "python-mord")
2751 (version "0.7")
2752 (source
2753 (origin
2754 (method url-fetch)
2755 (uri (pypi-uri "mord" version))
2756 (sha256
2757 (base32 "1cvv9b9w69v0inq0zgcw0vmkiq3zn9q9r6clkynpzjik9rrh405n"))))
2758 (build-system pyproject-build-system)
2759 ;; v0.7 does not provide any test cases
2760 ;; v0.6 relies on deprecated scikit-learn functionality
2761 (arguments `(#:tests? #f))
2762 (inputs (list python-numpy python-scipy python-scikit-learn))
2763 (native-inputs (list python-setuptools python-wheel))
2764 (home-page "https://pypi.org/project/mord/")
2765 (synopsis "Ordinal regression models for scikit-learn")
2766 (description
2767 "This package provides a collection of ordinal regression models for
2768machine learning in Python. They are intended to be used with scikit-learn
2769and are compatible with its API.")
2770 (license license:bsd-3)))
2771
2772(define-public python-thinc
2773 (package
2774 (name "python-thinc")
2775 (version "8.3.13")
2776 (source
2777 (origin
2778 (method git-fetch)
2779 (uri (git-reference
2780 (url "https://github.com/explosion/thinc")
2781 ;; XXX: It may be "release-v" as well.
2782 (commit (string-append "v" version))))
2783 (file-name (git-file-name name version))
2784 (sha256
2785 (base32 "04h9lbcaf4xizmcyq10lgr1gsxlgb8w4zcbf9vnzp37bn344cvig"))))
2786 (build-system pyproject-build-system)
2787 (arguments
2788 (list
2789 ;; tests: 1215 passed, 113 skipped, 1657 warnings
2790 #:phases
2791 #~(modify-phases %standard-phases
2792 (add-before 'check 'remove-local-thinc
2793 (lambda _
2794 (copy-recursively "thinc/tests" "tests")
2795 ;; This would otherwise interfere with finding the installed
2796 ;; thinc when running tests.
2797 (delete-file-recursively "thinc"))))))
2798 (propagated-inputs
2799 (list python-blis
2800 python-catalogue
2801 python-confection
2802 python-cymem
2803 python-murmurhash
2804 python-numpy
2805 python-packaging
2806 python-preshed
2807 python-pydantic
2808 python-srsly
2809 python-wasabi))
2810 (native-inputs
2811 (list python-coverage
2812 python-cython
2813 python-mock
2814 python-pytest
2815 python-setuptools))
2816 (home-page "https://github.com/explosion/thinc")
2817 (synopsis "Functional take on deep learning")
2818 (description
2819 "This package provides a functional take on deep learning, compatible
2820with your favorite libraries.")
2821 (license license:expat)))
2822
2823(define-public python-threadpoolctl
2824 (package
2825 (name "python-threadpoolctl")
2826 (version "3.6.0")
2827 (source
2828 (origin
2829 (method git-fetch)
2830 (uri (git-reference
2831 (url "https://github.com/joblib/threadpoolctl")
2832 (commit version)))
2833 (file-name (git-file-name name version))
2834 (sha256
2835 (base32
2836 "1n5gkcw619d9qgnnk46v2v77safj0z8hngb8i75dawq7lan89068"))))
2837 (build-system pyproject-build-system)
2838 (native-inputs
2839 (list python-flit-core python-pytest))
2840 (home-page "https://github.com/joblib/threadpoolctl")
2841 (synopsis "Python helpers for common threading libraries")
2842 (description "Thread-pool Controls provides Python helpers to limit the
2843number of threads used in the threadpool-backed of common native libraries used
2844for scientific computing and data science (e.g. BLAS and OpenMP).")
2845 (license license:bsd-3)))
2846
2847(define-public python-hdbscan
2848 (package
2849 (name "python-hdbscan")
2850 (version "0.8.41")
2851 (source
2852 (origin
2853 (method url-fetch)
2854 (uri (pypi-uri "hdbscan" version))
2855 (sha256
2856 (base32 "0ggzkm153cmgdq88jpdsvcmsipdicri24b957wbz47xjbcz847p4"))))
2857 (build-system pyproject-build-system)
2858 (arguments
2859 (list
2860 #:test-flags
2861 ;; XXX: Test files which fail during test collection.
2862 #~(list "--ignore=hdbscan/tests/test_branches.py"
2863 "--ignore=hdbscan/tests/test_hdbscan.py"
2864 "--ignore=hdbscan/tests/test_rsl.py")
2865 #:phases
2866 #~(modify-phases %standard-phases
2867 (add-before 'check 'pre-check
2868 (lambda _
2869 (delete-file "hdbscan/tests/__init__.py")))
2870 (add-before 'check 'build-extensions
2871 (lambda _
2872 (invoke "python" "setup.py" "build_ext" "--inplace"))))))
2873 (native-inputs
2874 (list python-cython
2875 python-numpy
2876 python-pytest
2877 python-setuptools))
2878 (propagated-inputs
2879 (list python-joblib
2880 python-numpy
2881 python-scikit-learn
2882 python-scipy))
2883 (home-page "https://github.com/scikit-learn-contrib/hdbscan")
2884 (synopsis "High performance implementation of HDBSCAN clustering")
2885 (description "HDBSCAN - Hierarchical Density-Based Spatial Clustering of
2886Applications with Noise. Performs DBSCAN over varying epsilon values and
2887integrates the result to find a clustering that gives the best stability over
2888epsilon. This allows HDBSCAN to find clusters of varying densities (unlike
2889DBSCAN), and be more robust to parameter selection. HDBSCAN is ideal for
2890exploratory data analysis; it's a fast and robust algorithm that you can trust
2891to return meaningful clusters (if there are any).")
2892 (license license:bsd-3)))
2893
2894(define-public python-pynndescent
2895 (package
2896 (name "python-pynndescent")
2897 (version "0.6.0")
2898 (source
2899 (origin
2900 (method url-fetch)
2901 (uri (pypi-uri "pynndescent" version))
2902 (sha256
2903 (base32 "1x94mjdf62f2yqql50qn0qjh4bkhwdvx7xx9aph421s0bgxy1zbz"))))
2904 (build-system pyproject-build-system)
2905 (arguments
2906 (list
2907 #:test-flags
2908 ;; Error from ScikitLearn: The 'metric' parameter of pairwise_distances
2909 ;; must be a str among <...>. Fixed in upcomming release of pynndescent.
2910 #~(list (string-append "--deselect=pynndescent/tests/test_distances.py"
2911 "::test_binary_check[sokalmichener]")
2912 (string-append "--deselect=ynndescent/tests/test_distances.py"
2913 "::test_sparse_binary_check[sokalmichener]")
2914 (string-append "--deselect=pynndescent/tests/test_distances.py"
2915 "::test_sparse_binary_check[sokalmichener]"))))
2916 (native-inputs (list python-pytest python-setuptools))
2917 (propagated-inputs (list python-joblib
2918 python-llvmlite
2919 python-numba
2920 python-scikit-learn
2921 python-scipy))
2922 (home-page "https://github.com/lmcinnes/pynndescent")
2923 (synopsis "Nearest neighbor descent for approximate nearest neighbors")
2924 (description
2925 "PyNNDescent provides a Python implementation of Nearest Neighbor Descent
2926for k-neighbor-graph construction and approximate nearest neighbor search.")
2927 (license license:bsd-2)))
2928
2929(define-public python-opentsne
2930 (package
2931 (name "python-opentsne")
2932 (version "1.0.2")
2933 (source
2934 (origin
2935 (method git-fetch) ;no tests in PyPI release
2936 (uri (git-reference
2937 (url "https://github.com/pavlin-policar/openTSNE")
2938 (commit (string-append "v" version))))
2939 (file-name (git-file-name name version))
2940 (sha256
2941 (base32 "1jn15h8b53z6ah47y51y8y4m0mk20xr6l2kd27ffr0hxswbifmkv"))))
2942 (build-system pyproject-build-system)
2943 (arguments
2944 (list
2945 #:phases
2946 #~(modify-phases %standard-phases
2947 ;; Benchmarks require the 'macosko2015' data files.
2948 (add-after 'unpack 'delete-benchmark
2949 (lambda _
2950 (delete-file-recursively "benchmarks")))
2951 (add-before 'check 'preparations
2952 (lambda _
2953 ;; Numba needs a writable dir to cache functions.
2954 (setenv "NUMBA_CACHE_DIR" "/tmp")
2955 ;; Rebuild extensions to run tests.
2956 (invoke "python" "setup.py" "build_ext" "--inplace"))))))
2957 (native-inputs (list python-cython python-pytest python-setuptools
2958 python-wheel))
2959 (inputs (list fftw))
2960 (propagated-inputs (list python-numpy python-pynndescent
2961 python-scikit-learn python-scipy))
2962 (home-page "https://github.com/pavlin-policar/openTSNE")
2963 (synopsis "Extensible, parallel implementations of t-SNE")
2964 (description
2965 "This is a modular Python implementation of t-Distributed Stochastic
2966Neighbor Embedding (t-SNE), a popular dimensionality-reduction algorithm for
2967visualizing high-dimensional data sets.")
2968 (license license:bsd-3)))
2969
2970;; XXX: Potentially it is an abandonware, no releases or any updates since
2971;; 2021, consider to remove when become incompatible with propagated inputs.
2972(define-public python-scikit-rebate
2973 (package
2974 (name "python-scikit-rebate")
2975 (version "0.62")
2976 (source
2977 (origin
2978 (method url-fetch)
2979 (uri (pypi-uri "skrebate" version))
2980 (sha256
2981 (base32 "0n55ghvnv7rxqa5agq6a4892ad0ghha165b0g4ghwr9gqm6ss3dj"))))
2982 (build-system pyproject-build-system)
2983 ;; There are no tests on PyPI, tests in git repo require an old release of
2984 ;; python-scikit-learn
2985 (arguments '(#:tests? #f))
2986 (native-inputs
2987 (list python-setuptools))
2988 (propagated-inputs
2989 (list python-numpy python-scipy python-scikit-learn python-joblib))
2990 (home-page "https://epistasislab.github.io/scikit-rebate/")
2991 (synopsis "Relief-based feature selection algorithms for Python")
2992 (description "Scikit-rebate is a scikit-learn-compatible Python
2993implementation of ReBATE, a suite of Relief-based feature selection algorithms
2994for Machine Learning. These algorithms excel at identifying features that are
2995predictive of the outcome in supervised learning problems, and are especially
2996good at identifying feature interactions that are normally overlooked by
2997standard feature selection algorithms.")
2998 (license license:expat)))
2999
3000(define-public python-cleanlab
3001 (package
3002 (name "python-cleanlab")
3003 (version "2.9.0")
3004 (source (origin
3005 (method git-fetch)
3006 (uri (git-reference
3007 (url "https://github.com/cleanlab/cleanlab")
3008 (commit (string-append "v" version))))
3009 (file-name (git-file-name name version))
3010 (sha256
3011 (base32
3012 "1fks57i3a297fcm1k4bs48x9cc7rs0jp4ij92r42pd1n0x60jznh"))))
3013 (build-system pyproject-build-system)
3014 (arguments
3015 (list
3016 ;; tests: 616 passed, 3 deselected, 99 warnings
3017 #:test-flags
3018 ;; This test fails because the newer version of scikit learn returns one
3019 ;; more classification result than expected. This should be harmless.
3020 #~(list "-k" "not test_aux_inputs"
3021 ;; Requires Tensorflow
3022 "--ignore=tests/test_frameworks.py"
3023 ;; These need datasets, which needs jax, so it could only live in
3024 ;; the guix-science channel.
3025 "--ignore-glob=tests/datalab/**"
3026 ;; Tries to download datasets from the internet at runtime.
3027 "--ignore=tests/test_dataset.py"
3028 ;; Test requiring not packaged dataset.
3029 "--ignore=tests/spurious_correlation/test_correlation_visualizer.py"
3030 "--ignore=tests/spurious_correlation/test_spurious_correlation.py"
3031 ;; AssertionError: assert 'Annotators [1] did not label any
3032 ;; examples.' in 'labels_multiannotator cannot have columns with
3033 ;; all NaN, each annotator must annotator at least one example.
3034 "--deselect=tests/test_multiannotator.py::test_label_quality_scores_multiannotator"
3035 ;; These tests were not updated to the last numpy update.
3036 ;; Try enabling them on the next update.
3037 (string-append "--deselect=tests/test_object_detection.py::"
3038 "test_return_issues_ranked_by_scores")
3039 (string-append "--deselect=tests/test_object_detection.py::"
3040 "test_bad_input_find_label_issues_internal"))
3041 #:phases
3042 #~(modify-phases %standard-phases
3043 (add-after 'unpack 'remove-datasets
3044 (lambda _
3045 (delete-file "tests/datalab/conftest.py"))))))
3046 (propagated-inputs
3047 (list python-numpy
3048 python-pandas
3049 python-scikit-learn
3050 python-termcolor
3051 python-tqdm))
3052 (native-inputs
3053 (list ;; python-dataset ; https://github.com/huggingface/datasets
3054 python-matplotlib
3055 python-pytest
3056 python-pytorch
3057 python-setuptools
3058 python-torchvision
3059 python-typing-extensions))
3060 (home-page "https://cleanlab.ai")
3061 (synopsis "Automatically find and fix dataset issues")
3062 (description
3063 "cleanlab automatically finds and fixes errors in any ML dataset. This
3064data-centric AI package facilitates machine learning with messy, real-world
3065data by providing clean labels during training.")
3066 (license license:agpl3+)))
3067
3068(define-public python-cma
3069 (package
3070 (name "python-cma")
3071 (version "4.4.4")
3072 (source (origin
3073 (method url-fetch)
3074 (uri (pypi-uri "cma" version))
3075 (sha256
3076 (base32
3077 "0w41k8dk8g1ngx797dzag5xcwws77sfnfriim874rq6wnmadcav3"))))
3078 (build-system pyproject-build-system)
3079 (arguments
3080 (list #:test-backend #~'custom
3081 #:test-flags #~'("src/cma/test.py")))
3082 (native-inputs (list python-pytest python-setuptools))
3083 (propagated-inputs (list python-numpy))
3084 (home-page "https://github.com/CMA-ES/pycma")
3085 (synopsis "Python implementation of CMA-ES")
3086 (description "This package provides a Python implementation of the
3087@acronym{CMA-ES, Covariance Matrix Adaptation Evolution Strategy} algorithm
3088and a few related numerical optimization tools.")
3089 (license license:bsd-3)))
3090
3091(define-public python-cmaes
3092 (package
3093 (name "python-cmaes")
3094 (version "0.13.0")
3095 (source
3096 (origin
3097 (method git-fetch) ;no tests in PyPI
3098 (uri (git-reference
3099 (url "https://github.com/CyberAgentAILab/cmaes")
3100 (commit (string-append "v" version))))
3101 (sha256
3102 (base32 "1fqy7829isg3j00849ifya4ncf9qpm0b3jhw47ibjn4jv0kn4zmh"))
3103 (file-name (git-file-name name version))))
3104 (build-system pyproject-build-system)
3105 (native-inputs (list python-pytest python-setuptools))
3106 (propagated-inputs (list python-numpy))
3107 (home-page "https://github.com/CyberAgentAILab/cmaes")
3108 (synopsis "CMA-ES implementation for Python")
3109 (description "This package provides provides an implementation of the
3110Covariance Matrix Adaptation Evolution Strategy (CMA-ES) for Python.")
3111 (license license:expat)))
3112
3113(define-public python-autograd
3114 (package
3115 (name "python-autograd")
3116 (version "1.8.0")
3117 (source
3118 (origin
3119 (method git-fetch)
3120 (uri (git-reference
3121 (url "https://github.com/HIPS/autograd")
3122 (commit (string-append "v" version))))
3123 (sha256
3124 (base32 "054pkhzz0h9p1jzva8774wb9dj7rvax4rcpr8ava971kbimdr2lk"))
3125 (file-name (git-file-name name version))))
3126 (build-system pyproject-build-system)
3127 (native-inputs
3128 (list python-hatchling
3129 python-pytest
3130 python-pytest-cov ; This package has a custom way of running tests.
3131 python-pytest-xdist))
3132 (propagated-inputs
3133 (list python-future
3134 python-numpy))
3135 (home-page "https://github.com/HIPS/autograd")
3136 (synopsis "Efficiently computes derivatives of NumPy code")
3137 (description
3138 "Autograd can automatically differentiate native Python and NumPy code.
3139It can handle a large subset of Python's features, including loops, ifs,
3140recursion and closures, and it can even take derivatives of derivatives of
3141derivatives. It supports reverse-mode differentiation
3142(a.k.a. backpropagation), which means it can efficiently take gradients of
3143scalar-valued functions with respect to array-valued arguments, as well as
3144forward-mode differentiation, and the two can be composed arbitrarily. The
3145main intended application of Autograd is gradient-based optimization.")
3146 (license license:expat)))
3147
3148(define-public python-torchdiffeq
3149 ;; There are neither releases nor tags.
3150 (let ((commit "657943acefa826ef04c025ebeb1ff5e9d60dc268")
3151 (revision "1"))
3152 (package
3153 (name "python-torchdiffeq")
3154 (version (git-version "0.2.5" revision commit))
3155 (source
3156 (origin
3157 (method git-fetch)
3158 (uri (git-reference
3159 (url "https://github.com/rtqichen/torchdiffeq")
3160 (commit commit)))
3161 (file-name (git-file-name name version))
3162 (sha256
3163 (base32 "15ccm7m0k3jjvx0sxz4s453pb0sxlbg5569dqlvj6ql74jl356x0"))))
3164 (build-system pyproject-build-system)
3165 (arguments
3166 (list
3167 #:test-flags
3168 #~(list
3169 ;; This starts failing with [email protected], it looks like a regression
3170 ;; in the fortran to C rewrite of LSODA.
3171 "-k" "not test_min_max_step"
3172 "tests/run_all.py")))
3173 (propagated-inputs (list python-numpy python-scipy python-pytorch))
3174 (native-inputs (list python-pytest python-setuptools))
3175 (home-page "https://github.com/rtqichen/torchdiffeq")
3176 (synopsis "ODE solvers and adjoint sensitivity analysis in PyTorch")
3177 (description
3178 "This tool provides ordinary differential equation solvers implemented
3179in PyTorch. Backpropagation through ODE solutions is supported using the
3180adjoint method for constant memory cost.")
3181 (license license:expat))))
3182
3183(define-public lightgbm
3184 (package
3185 (name "lightgbm")
3186 (version "2.0.12")
3187 (source
3188 (origin
3189 (method git-fetch)
3190 (uri (git-reference
3191 (url "https://github.com/Microsoft/LightGBM")
3192 (commit (string-append "v" version))))
3193 (sha256
3194 (base32 "0jlvyn7k81dzrh9ij3zw576wbgiwmmr26rzpdxjn1dbpc3njpvzi"))
3195 (file-name (git-file-name name version))))
3196 (build-system cmake-build-system)
3197 (arguments
3198 (list
3199 #:configure-flags
3200 #~(list "-DUSE_MPI=ON")
3201 #:phases
3202 #~(modify-phases %standard-phases
3203 (replace 'check
3204 (lambda* (#:key tests? #:allow-other-keys)
3205 (when tests?
3206 (with-directory-excursion "../source"
3207 (invoke "pytest" "tests/c_api_test/test_.py"))))))))
3208 (native-inputs (list python python-pytest))
3209 (inputs (list openmpi))
3210 (propagated-inputs (list python-numpy python-scipy))
3211 (home-page "https://github.com/Microsoft/LightGBM")
3212 (synopsis "Gradient boosting framework based on decision tree algorithms")
3213 (description
3214 "LightGBM is a gradient boosting framework that uses tree based learning
3215algorithms. It is designed to be distributed and efficient with the following
3216advantages:
3217
3218@itemize
3219@item Faster training speed and higher efficiency
3220@item Lower memory usage
3221@item Better accuracy
3222@item Parallel and GPU learning supported (not enabled in this package)
3223@item Capable of handling large-scale data
3224@end itemize
3225")
3226 (license license:expat)))
3227
3228(define-public python-lightgbm
3229 (package/inherit lightgbm
3230 (name "python-lightgbm")
3231 (build-system pyproject-build-system)
3232 (arguments
3233 (list
3234 ;; XXX: Enable when lightgbm is updated.
3235 #:tests? #f
3236 #:phases
3237 #~(modify-phases %standard-phases
3238 (add-after 'unpack 'chdir
3239 (lambda _
3240 (chdir "python-package"))))))
3241 (native-inputs
3242 (list cmake-minimal
3243 python-pytest
3244 python-setuptools))
3245 (propagated-inputs
3246 (list python-numpy
3247 python-scipy
3248 python-scikit-learn))
3249 (synopsis "LightGBM Python Package")))
3250
3251(define-public vowpal-wabbit
3252 ;; Language bindings not included.
3253 (package
3254 (name "vowpal-wabbit")
3255 (version "8.5.0")
3256 (source (origin
3257 (method git-fetch)
3258 (uri (git-reference
3259 (url "https://github.com/JohnLangford/vowpal_wabbit")
3260 (commit version)))
3261 (sha256
3262 (base32
3263 "04bwzk6ifgnz3fmzid8b7avxf9n5pnx9xcjm61nkjng1vv0bpj8x"))
3264 (file-name (git-file-name name version))))
3265 (build-system gnu-build-system)
3266 (arguments
3267 (list
3268 #:configure-flags
3269 #~(list (string-append "--with-boost=" #$(this-package-input "boost")))
3270 #:phases
3271 #~(modify-phases %standard-phases
3272 (add-after 'unpack 'make-files-writable
3273 (lambda _
3274 (for-each make-file-writable (find-files "." ".*"))))
3275 (add-after 'install 'install-more-headers
3276 (lambda _
3277 (for-each
3278 (lambda (file)
3279 (install-file
3280 file (string-append #$output "/include/vowpalwabbit")))
3281 (find-files "vowpalwabbit" "\\.h$")))))))
3282 (inputs
3283 (list boost zlib))
3284 (home-page "https://vowpalwabbit.org")
3285 (synopsis "Fast machine learning library for online learning")
3286 (description "Vowpal Wabbit is a machine learning system with techniques
3287such as online, hashing, allreduce, reductions, learning2search, active, and
3288interactive learning.")
3289 (license license:bsd-3)))
3290
3291(define-public python-hyperopt
3292 (package
3293 (name "python-hyperopt")
3294 (version "0.3.0")
3295 (source
3296 (origin
3297 (method git-fetch)
3298 (uri (git-reference
3299 (url "https://github.com/hyperopt/hyperopt")
3300 (commit (string-append "v" version))))
3301 (file-name (git-file-name name version))
3302 (sha256
3303 (base32 "09qy7v01dy2kk9wpd50ras5m9qzysg6h23lm3yl5ylr8hk7hi8wj"))))
3304 (build-system pyproject-build-system)
3305 (arguments
3306 (list
3307 ;; tests: 225 passed, 2 skipped, 1 deselected, 2 warnings
3308 #:test-flags
3309 #~(list "-m" "not slow"
3310 "--ignore=hyperopt/tests/integration/"
3311 ;; XXX: Segfaulted test.
3312 (string-append "--deselect=hyperopt/tests/unit/"
3313 "test_atpe_basic.py::test_run_basic_search"))))
3314 (native-inputs
3315 (list python-hatchling
3316 python-hatch-vcs
3317 python-pytest))
3318 (propagated-inputs
3319 (list python-cloudpickle
3320 python-networkx
3321 python-numpy
3322 python-scipy
3323 python-tqdm
3324 ;; [optional]
3325 python-lightgbm
3326 python-py4j
3327 python-pymongo
3328 ;; python-pyspark ;not packaged yet in Guix
3329 python-scikit-learn))
3330 (home-page "https://hyperopt.github.io/hyperopt/")
3331 (synopsis "Library for hyperparameter optimization")
3332 (description "Hyperopt is a Python library for serial and parallel
3333optimization over awkward search spaces, which may include real-valued,
3334discrete, and conditional dimensions.")
3335 (license license:bsd-3)))
3336
3337(define-public python-deepxde
3338 (package
3339 (name "python-deepxde")
3340 (version "1.15.0")
3341 (source (origin
3342 (method url-fetch)
3343 (uri (pypi-uri "deepxde" version))
3344 (sha256
3345 (base32
3346 "1m21hkcj386p0bwf19cr6r2kkv0c054yv1ipsl1rqav13g88l3ic"))))
3347 (build-system pyproject-build-system)
3348 (arguments
3349 (list #:tests? #f ; there are no tests
3350 #:phases #~(modify-phases %standard-phases
3351 (add-before 'sanity-check 'writable-home
3352 ;; sanity-check writes ~/.deepxde/config.json to set
3353 ;; the default backend.
3354 (lambda _
3355 (setenv "HOME" "/tmp"))))))
3356 ;; DeepXDE supported backends are TensorFlow (v1 and v2), PyTorch, JAX and
3357 ;; PaddlePaddle. We test with PyTorch because we have it up to date.
3358 (native-inputs (list python-pytorch python-setuptools
3359 python-setuptools-scm))
3360 (propagated-inputs (list python-matplotlib python-numpy
3361 python-scikit-learn python-scikit-optimize
3362 python-scipy))
3363 (home-page "https://deepxde.readthedocs.io/en/latest/")
3364 (synopsis "Library for scientific machine learning")
3365 (description "DeepXDE is a library for scientific machine learning and
3366physics-informed learning. It includes implementations for the PINN
3367(physics-informed neural networks), DeepONet (deep operator network) and
3368MFNN (multifidelity neural network) algorithms.")
3369 (license license:lgpl2.1+)))
3370
3371(define-public python-jaxtyping
3372 (package
3373 (name "python-jaxtyping")
3374 (version "0.3.3")
3375 (source (origin
3376 (method url-fetch)
3377 (uri (pypi-uri "jaxtyping" version))
3378 (sha256
3379 (base32
3380 "11pajw47mj0px787m6f7vwfsi6ajawm9h7fszm3rpbd2dg8wy0w0"))))
3381 (build-system pyproject-build-system)
3382 ;; Tests require JAX, but JAX can't be packaged because it uses the Bazel
3383 ;; build system.
3384 (arguments (list #:tests? #f))
3385 (native-inputs (list python-hatchling))
3386 (propagated-inputs (list python-numpy python-typeguard
3387 python-typing-extensions python-wadler-lindig))
3388 (home-page "https://github.com/google/jaxtyping")
3389 (synopsis
3390 "Type annotations and runtime checking for JAX arrays and others")
3391 (description "@code{jaxtyping} provides type annotations and runtime
3392checking for shape and dtype of JAX arrays, PyTorch, NumPy, TensorFlow, and
3393PyTrees.")
3394 (license license:expat)))
3395
3396;; There have been no proper releases yet.
3397(define-public kaldi
3398 (let ((commit "01aadd7c19372e3eacadec88caabd86162f33d69")
3399 (revision "2"))
3400 (package
3401 (name "kaldi")
3402 (version (git-version "0" revision commit))
3403 (source (origin
3404 (method git-fetch)
3405 (uri (git-reference
3406 (url "https://github.com/kaldi-asr/kaldi")
3407 (commit commit)))
3408 (file-name (git-file-name name version))
3409 (sha256
3410 (base32
3411 "08l31g256wl81fsrm1dvi0d2rq2vk5zq7ihbbiw7hp51iwg2miif"))
3412 (patches
3413 (search-patches "kaldi-openblas-0.3.29-compatibility.patch"
3414 "kaldi-ignore-failing-test.patch"))))
3415 (build-system gnu-build-system)
3416 (arguments
3417 (list
3418 #:test-target "test"
3419 #:configure-flags
3420 (let ((fst (this-package-input "openfst")))
3421 #~(list "--use-cuda=no"
3422 "--shared"
3423 (string-append "--openblas-root="
3424 #$(this-package-input "openblas"))
3425 (string-append "--fst-root=" #$fst)
3426 (string-append "--fst-version=" #$(package-version fst))))
3427 #:phases
3428 #~(modify-phases %standard-phases
3429 (add-after 'unpack 'chdir
3430 (lambda _ (chdir "src")))
3431 (replace 'configure
3432 (lambda* (#:key build system inputs configure-flags
3433 #:allow-other-keys)
3434 (when (not (or (string-prefix? "x86_64" system)
3435 (string-prefix? "i686" system)))
3436 (substitute* "makefiles/linux_openblas.mk"
3437 (("-msse -msse2") "")))
3438 (substitute* "makefiles/default_rules.mk"
3439 (("/bin/bash") (which "bash")))
3440 (substitute* "Makefile"
3441 (("ext_depend: check_portaudio")
3442 "ext_depend:"))
3443 (substitute* '("online/Makefile"
3444 "onlinebin/Makefile"
3445 "gst-plugin/Makefile")
3446 (("../../tools/portaudio/install")
3447 (assoc-ref inputs "portaudio")))
3448 (substitute* "matrix/Makefile" ;temporary test bypass
3449 (("matrix-lib-test sparse-matrix-test") ""))
3450
3451 ;; This `configure' script doesn't support variables passed as
3452 ;; arguments, nor does it support "prefix".
3453 (substitute* "configure"
3454 (("check_for_slow_expf;") "")
3455 ;; This affects the RPATH and also serves as the installation
3456 ;; directory.
3457 (("KALDILIBDIR=`pwd`/lib")
3458 (string-append "KALDILIBDIR=" #$output "/lib")))
3459 (mkdir-p #$output) ; must exist
3460 (setenv "CONFIG_SHELL" (which "bash"))
3461 (apply invoke "./configure" configure-flags)))
3462 (add-after 'build 'build-ext-and-gstreamer-plugin
3463 (lambda _
3464 (invoke "make" "-C" "online" "depend")
3465 (invoke "make" "-C" "online")
3466 (invoke "make" "-C" "onlinebin" "depend")
3467 (invoke "make" "-C" "onlinebin")
3468 (invoke "make" "-C" "gst-plugin" "depend")
3469 (invoke "make" "-C" "gst-plugin")))
3470 ;; TODO: also install the executables.
3471 (replace 'install
3472 (lambda _
3473 (let* ((inc (string-append #$output "/include"))
3474 (lib (string-append #$output "/lib")))
3475 (mkdir-p lib)
3476 ;; The build phase installed symlinks to the actual
3477 ;; libraries. Install the actual targets.
3478 (for-each (lambda (file)
3479 (let ((target (readlink file)))
3480 (delete-file file)
3481 (install-file target lib)))
3482 (find-files lib "\\.so"))
3483 ;; Install headers
3484 (for-each (lambda (file)
3485 (let ((target-dir (string-append inc "/" (dirname file))))
3486 (install-file file target-dir)))
3487 (find-files "." "\\.h"))
3488 (install-file "gst-plugin/libgstonlinegmmdecodefaster.so"
3489 (string-append lib "/gstreamer-1.0"))))))))
3490 (inputs
3491 (list alsa-lib
3492 `(,gfortran "lib")
3493 glib
3494 gstreamer
3495 jack-1
3496 openblas
3497 openfst
3498 portaudio
3499 python))
3500 (native-inputs
3501 (list `(,glib "bin") ; glib-genmarshal
3502 grep
3503 sed
3504 pkg-config
3505 which))
3506 (home-page "https://kaldi-asr.org/")
3507 (synopsis "Speech recognition toolkit")
3508 (description "Kaldi is an extensible toolkit for speech recognition
3509written in C++.")
3510 (license license:asl2.0))))
3511
3512(define kaldi-for-vosk
3513 ;; Commit of branch "vosk"
3514 (let* ((commit "bc5baf14231660bd50b7d05788865b4ac6c34481")
3515 (revision "1")
3516 (openfst openfst-for-vosk))
3517 (package
3518 (inherit kaldi)
3519 (name "kaldi")
3520 (version (git-version "0" revision commit))
3521 (source
3522 (origin
3523 (method git-fetch)
3524 (uri (git-reference
3525 (url "https://github.com/alphacep/kaldi")
3526 (commit commit)))
3527 (file-name (git-file-name name version))
3528 (sha256
3529 (base32 "1y3d6918srr7cn5r72v5wvbdwz9p9j2bjw1x78sfis2r2k60lllw"))
3530 (patches
3531 (search-patches "kaldi-openblas-0.3.29-compatibility.patch"))))
3532 (inputs
3533 (list alsa-lib
3534 glib
3535 gstreamer
3536 jack-2
3537 openblas
3538 openfst
3539 portaudio
3540 python))
3541 (arguments
3542 (list
3543 #:test-target "test"
3544 #:make-flags '(list "online2" "lm" "rnnlm")
3545 #:phases
3546 #~(modify-phases %standard-phases
3547 (add-after 'unpack 'chdir
3548 (lambda _ (chdir "src")))
3549 (replace 'configure
3550 (lambda _
3551 (let ((portaudio #$(this-package-input "portaudio"))
3552 (openfst #$(this-package-input "openfst"))
3553 (openblas #$(this-package-input "openblas")))
3554 #$@(if (target-x86?)
3555 '()
3556 #~((substitute* "makefiles/linux_openblas.mk"
3557 (("-msse -msse2") ""))))
3558 (substitute* "makefiles/default_rules.mk"
3559 (("/bin/bash") (which "bash")))
3560 (substitute* "Makefile"
3561 (("ext_depend: check_portaudio")
3562 "ext_depend:"))
3563 (substitute* '("online/Makefile"
3564 "onlinebin/Makefile"
3565 "gst-plugin/Makefile")
3566 (("../../tools/portaudio/install")
3567 portaudio))
3568 (substitute* "matrix/Makefile" ;temporary test bypass
3569 (("matrix-lib-test sparse-matrix-test") ""))
3570 (substitute* "cudamatrix/Makefile"
3571 ((" cu-array-test") ""))
3572
3573 ;; This `configure' script doesn't support variables passed as
3574 ;; arguments, nor does it support "prefix".
3575 (substitute* "configure"
3576 (("check_for_slow_expf;") "")
3577 ;; This affects the RPATH and also serves as the installation
3578 ;; directory.
3579 (("KALDILIBDIR=`pwd`/lib")
3580 (string-append "KALDILIBDIR=" #$output "/lib"))
3581 (("OPENBLASROOT=\\\"\\$\\(rel2abs ..\\/tools\\/OpenBLAS\\/install\\)\\\"")
3582 (string-append "OPENBLASROOT=\"" openblas "\""))
3583 (("-L\\$OPENBLASLIBDIR -l:libopenblas.a -l:libblas.a -l:liblapack.a -l:libf2c.a")
3584 (string-append "-L$OPENBLASLIBDIR -lopenblas "
3585 "-L" openblas "/lib -lopenblas")))
3586 (mkdir-p #$output) ; must exist
3587 (setenv "CONFIG_SHELL" (which "bash"))
3588 (setenv "OPENFST_VER" #$(package-version openfst))
3589 (invoke "./configure"
3590 "--use-cuda=no"
3591 "--mathlib=OPENBLAS_CLAPACK"
3592 "--shared"
3593 (string-append "--fst-root=" openfst)))))
3594 (add-after 'configure 'optimize-build
3595 (lambda _ (substitute* "kaldi.mk" ((" -O1") " -O3"))))
3596 (replace 'install
3597 (lambda _
3598 (let ((inc (string-append #$output "/include"))
3599 (lib (string-append #$output "/lib")))
3600 ;; The build phase installed symlinks to the actual
3601 ;; libraries. Install the actual targets.
3602 (for-each (lambda (file)
3603 (let ((target (readlink file)))
3604 (delete-file file)
3605 (install-file target lib)))
3606 (find-files lib "\\.so"))
3607 ;; Install headers
3608 (for-each (lambda (file)
3609 (let ((target-dir (string-append inc "/" (dirname file))))
3610 (install-file file target-dir)))
3611 (find-files "." "\\.h")))))))))))
3612
3613(define-public gst-kaldi-nnet2-online
3614 (let ((commit "7888ae562a65bd7e406783ce2c33535bc66a30ef")
3615 (revision "3"))
3616 (package
3617 (name "gst-kaldi-nnet2-online")
3618 (version (git-version "0" revision commit))
3619 (source (origin
3620 (method git-fetch)
3621 (uri (git-reference
3622 (url "https://github.com/alumae/gst-kaldi-nnet2-online")
3623 (commit commit)))
3624 (file-name (git-file-name name version))
3625 (sha256
3626 (base32
3627 "0xp59a6lmx1y24i8bkmxcm27lhm5x5m6y41670yjzhamcbnx8jcr"))))
3628 (build-system gnu-build-system)
3629 (arguments
3630 (list
3631 #:tests? #f ; there are none
3632 #:make-flags
3633 (let ((kaldi (this-package-input "kaldi"))
3634 (bash (this-package-native-input "bash")))
3635 #~(list (string-append "SHELL=" #$bash "/bin/bash")
3636 (string-append "KALDI_ROOT=" #$(package-source kaldi))
3637 (string-append "KALDILIBDIR=" #$kaldi "/lib")
3638 "KALDI_FLAVOR=dynamic"))
3639 #:phases
3640 #~(modify-phases %standard-phases
3641 (add-after 'unpack 'chdir
3642 (lambda _ (chdir "src")))
3643 (replace 'configure
3644 (lambda* (#:key inputs #:allow-other-keys)
3645 (let ((fst-version #$(package-version
3646 (this-package-input "openfst"))))
3647 (setenv "CXXFLAGS"
3648 (string-append
3649 "-fPIC -DOPENFST_VER="
3650 (string-join (string-split fst-version #\.) "0")))
3651 (setenv "CPLUS_INCLUDE_PATH"
3652 (string-join
3653 (append (map (lambda (dir)
3654 (search-input-directory inputs dir))
3655 '("/include/glib-2.0"
3656 "/lib/glib-2.0/include"
3657 "/include/gstreamer-1.0"))
3658 (list (getenv "CPLUS_INCLUDE_PATH")))
3659 ":")))
3660 (substitute* "Makefile"
3661 (("include \\$\\(KALDI_ROOT\\)/src/kaldi.mk") "")
3662 (("\\$\\(error Cannot find") "#"))))
3663 (add-before 'build 'build-depend
3664 (lambda* (#:key make-flags #:allow-other-keys)
3665 (apply invoke "make" "depend" make-flags)))
3666 (replace 'install
3667 (lambda _
3668 (install-file
3669 "libgstkaldinnet2onlinedecoder.so"
3670 (string-append #$output "/lib/gstreamer-1.0")))))))
3671 (inputs
3672 (list glib gstreamer jansson openfst kaldi))
3673 (native-inputs
3674 (list bash `(,glib "bin") pkg-config))
3675 (home-page "https://kaldi-asr.org/")
3676 (synopsis "Gstreamer plugin for decoding speech")
3677 (description "This package provides a GStreamer plugin that wraps
3678Kaldi's @code{SingleUtteranceNnet2Decoder}. It requires iVector-adapted DNN
3679acoustic models. The iVectors are adapted to the current audio stream
3680automatically.")
3681 (license license:asl2.0))))
3682
3683(define-public kaldi-gstreamer-server
3684 ;; This is the tip of the py3 branch
3685 (let ((commit "f79e204d751a5964918001822e4520fa2acfd246")
3686 (revision "3"))
3687 (package
3688 (name "kaldi-gstreamer-server")
3689 (version (git-version "0" revision commit))
3690 (source (origin
3691 (method git-fetch)
3692 (uri (git-reference
3693 (url "https://github.com/alumae/kaldi-gstreamer-server")
3694 (commit commit)))
3695 (file-name (git-file-name name version))
3696 (sha256
3697 (base32
3698 "1iijq8jmgdxr7961inal1ggs496ymxradm51m4sqx8vl983x14y8"))
3699 ;; XXX: Tests are broken beyond repair and are mingled in the
3700 ;; source directory. Remove them to avoid installing them.
3701 ;; See https://github.com/nicolas-graves/kaldi-gstreamer-server
3702 ;; for a fork that tries to repair them, to no avail.
3703 (snippet #~(for-each delete-file
3704 '("kaldigstserver/test-buffer.py"
3705 "kaldigstserver/decoder_test.py"
3706 "kaldigstserver/decoder2_test.py")))))
3707 (build-system gnu-build-system)
3708 (arguments
3709 `(#:tests? #f
3710 #:modules ((guix build utils)
3711 (guix build gnu-build-system)
3712 (srfi srfi-26))
3713 #:phases
3714 (modify-phases %standard-phases
3715 (delete 'configure)
3716 (replace 'build
3717 (lambda _
3718 ;; Migrate to Glib.MainLoop.
3719 (substitute* (find-files "kaldigstserver" "\\.py")
3720 (("GObject\\.threads_init\\(\\)") "")
3721 (("GObject") "GLib"))
3722 ;; Disable hash randomization to ensure the generated .pycs
3723 ;; are reproducible.
3724 (setenv "PYTHONHASHSEED" "0")
3725 (with-directory-excursion "kaldigstserver"
3726 ;; See https://github.com/alumae/kaldi-gstreamer-server/issues/232
3727 (substitute* "master_server.py"
3728 (("\\.replace\\('\\\\.*") ")"))
3729
3730 (for-each (lambda (file)
3731 (apply invoke
3732 `("python"
3733 "-m" "compileall"
3734 "-f" ; force rebuild
3735 ,file)))
3736 (find-files "." "\\.py$")))))
3737 (replace 'install
3738 (lambda* (#:key inputs outputs #:allow-other-keys)
3739 (let* ((out (assoc-ref outputs "out"))
3740 (bin (string-append out "/bin"))
3741 (share (string-append out "/share/kaldi-gstreamer-server/")))
3742 ;; Install Python files
3743 (with-directory-excursion "kaldigstserver"
3744 (for-each (cut install-file <> share)
3745 (find-files "." ".*")))
3746
3747 ;; Install sample configuration files
3748 (for-each (cut install-file <> share)
3749 (find-files "." "\\.yaml"))
3750
3751 ;; Install executables
3752 (mkdir-p bin)
3753 (let* ((server (string-append bin "/kaldi-gst-server"))
3754 (client (string-append bin "/kaldi-gst-client"))
3755 (worker (string-append bin "/kaldi-gst-worker"))
3756 (wrap (lambda (wrapper what)
3757 (with-output-to-file wrapper
3758 (lambda _
3759 (format #t "#!~a
3760export GUIX_PYTHONPATH=~a
3761export GI_TYPELIB_PATH=~a:${GI_TYPELIB_PATH}
3762export GST_PLUGIN_SYSTEM_PATH=~a:${GST_PLUGIN_SYSTEM_PATH}
3763exec ~a ~a~a \"$@\"~%"
3764 (which "bash")
3765 (getenv "GUIX_PYTHONPATH")
3766 (getenv "GI_TYPELIB_PATH")
3767 (getenv "GST_PLUGIN_SYSTEM_PATH")
3768 (which "python") share what)))
3769 (chmod wrapper #o555))))
3770 (for-each wrap
3771 (list server client worker)
3772 (list "master_server.py"
3773 "client.py"
3774 "worker.py")))))))))
3775 (inputs
3776 (list gstreamer
3777 gst-kaldi-nnet2-online
3778 gst-plugins-base
3779 gst-plugins-good
3780 kaldi
3781 python-wrapper
3782 python-pygobject
3783 python-pyyaml
3784 python-tornado))
3785 (home-page "https://github.com/alumae/kaldi-gstreamer-server")
3786 (synopsis "Real-time full-duplex speech recognition server")
3787 (description "This is a real-time full-duplex speech recognition server,
3788based on the Kaldi toolkit and the GStreamer framework and implemented in
3789Python.")
3790 (license license:bsd-2))))
3791
3792(define-public tensorflow-lite
3793 (package
3794 (name "tensorflow-lite")
3795 (version "2.16.2")
3796 (source
3797 (origin
3798 (method git-fetch)
3799 (uri (git-reference
3800 (url "https://github.com/tensorflow/tensorflow")
3801 (commit (string-append "v" version))))
3802 (file-name (git-file-name name version))
3803 (sha256
3804 (base32
3805 "082qqv7987qb559skkh8199v8knigylbxgxvz49v4m3467sd4468"))))
3806 (build-system cmake-build-system)
3807 (outputs (list "out" "python"))
3808 (arguments
3809 (list
3810 #:build-type "Release"
3811 #:imported-modules (append %cmake-build-system-modules
3812 %pyproject-build-system-modules)
3813 #:modules '((ice-9 match)
3814 (srfi srfi-26)
3815 (guix build utils)
3816 (guix build cmake-build-system)
3817 ((guix build pyproject-build-system) #:prefix py:))
3818 #:configure-flags
3819 #~(list
3820 ;; Access some OpenCL functions in mesa-headers
3821 "-DCMAKE_C_FLAGS=-DCL_ENABLE_BETA_EXTENSIONS=1"
3822 "-DCMAKE_CXX_FLAGS=-DCL_ENABLE_BETA_EXTENSIONS=1"
3823 ;; "-DTFLITE_KERNEL_TEST=ON" ; TODO: build tests
3824 ;; so cmake can be used to find this from other packages
3825 "-DTFLITE_ENABLE_INSTALL=ON"
3826
3827 ;; Use Guix's own packages as dependencies.
3828 "-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON"
3829
3830 "-DTFLITE_ENABLE_GPU=ON"
3831 "-DTFLITE_ENABLE_RUY=ON"
3832 "-DTFLITE_ENABLE_XNNPACK=ON"
3833
3834 "-DSYSTEM_PTHREADPOOL=ON"
3835 ;; TODO: turn on Farmhash
3836 ;;"-DSYSTEM_FARMHASH=ON"
3837 (string-append "-Dabsl_DIR=" #$(this-package-input "abseil-cpp")
3838 "/lib/cmake/absl")
3839 (string-append "-DEigen3_DIR=" #$(this-package-input "eigen")
3840 "/share/eigen3/cmake")
3841 (string-append "-DFlatBuffers_DIR="
3842 #$(this-package-input "flatbuffers")
3843 "/lib/cmake/flatbuffers")
3844 (string-append "-DNEON_2_SSE_DIR=" #$(this-package-input "neon2sse")
3845 "/lib/cmake/NEON_2_SSE")
3846 (string-append "-Dcpuinfo_DIR=" #$(this-package-input "cpuinfo")
3847 "/share/cpuinfo")
3848 (string-append "-Druy_DIR=" #$(this-package-input "ruy")
3849 "/lib/cmake/ruy")
3850 (string-append "-DML_DTYPES_LIBRARY_DIRS="
3851 #$(this-package-input "python-ml-dtypes") "/lib")
3852
3853 ;; Don't fetch the sources. We have these already
3854 "-Dml_dtypes_POPULATED=ON"
3855 "-Dgemmlowp_POPULATED=TRUE"
3856 "-Degl_headers_POPULATED=TRUE"
3857 "-Dfp16_headers_POPULATED=TRUE"
3858 "-Dopencl_headers_POPULATED=TRUE"
3859 "-Dopengl_headers_POPULATED=TRUE"
3860 "-Dvulkan_headers_POPULATED=TRUE"
3861 "-Dgoogletest_POPULATED=TRUE"
3862 "-Dgoogle_benchmark_POPULATED=TRUE"
3863 "-Dnsync_POPULATED=TRUE"
3864 "-Dre2_POPULATED=TRUE"
3865 "-Dxnnpack_POPULATED=TRUE"
3866
3867 "-DFFT2D_SOURCE_DIR=/tmp/fft2d"
3868 "-DFARMHASH_SOURCE_DIR=/tmp/farmhash"
3869 (string-append "-Dgemmlowp_ROOT=" #$(this-package-input "gemmlowp")))
3870 #:phases
3871 #~(modify-phases %standard-phases
3872 (add-after 'unpack 'chdir
3873 (lambda _
3874 (chdir "tensorflow/lite")))
3875 (add-after 'chdir 'unbundle-gemmlowp
3876 (lambda _
3877 (call-with-output-file "tools/cmake/modules/gemmlowp.cmake"
3878 (lambda (port)
3879 (display "\
3880add_library(gemmlowp INTERFACE IMPORTED)
3881include_directories(\"${gemmlowp_ROOT}/include/gemmlowp\")" port)))
3882 (call-with-output-file "tools/cmake/modules/ml_dtypes.cmake"
3883 (lambda (port)
3884 (display "\
3885add_library(ml_dtypes INTERFACE IMPORTED)
3886find_library(ML_DTYPES_LIBRARIES
3887 NAMES ml_dtypes.so
3888 PATHS \"${ML_DTYPES_LIBRARY_DIRS}\"
3889 NO_DEFAULT_PATH)" port)))))
3890 (add-after 'chdir 'copy-sources
3891 (lambda _
3892 ;; Don't fetch source code; we already have everything we need.
3893 (substitute* '("tools/cmake/modules/fft2d.cmake"
3894 "tools/cmake/modules/farmhash.cmake"
3895 "tools/cmake/modules/gemmlowp.cmake")
3896 (("^ *OverridableFetchContent_Populate.*") ""))
3897
3898 (mkdir-p "/tmp/farmhash")
3899 (with-directory-excursion "/tmp/farmhash"
3900 (copy-recursively #$(this-package-native-input "farmhash-src") ".")
3901 (for-each make-file-writable (find-files ".")))
3902
3903 (mkdir-p "/tmp/fft2d")
3904 (with-directory-excursion "/tmp/fft2d"
3905 (copy-recursively #$(this-package-native-input "fft2d-src") ".")
3906 (for-each make-file-writable (find-files ".")))))
3907 (add-after 'copy-sources 'opencl-fix
3908 (lambda _
3909 (substitute* "delegates/gpu/cl/opencl_wrapper.h"
3910 (("cl_ndrange_kernel_command_properties_khr")
3911 "cl_command_properties_khr"))))
3912 (add-after 'opencl-fix 'absl-fix
3913 (lambda _
3914 (substitute* '("delegates/gpu/cl/cl_operation.h"
3915 "delegates/gpu/common/task/qcom_thin_filter_desc.cc"
3916 "delegates/gpu/common/tasks/special/thin_pointwise_fuser.cc")
3917 (("#include <vector>")
3918 "#include <vector>\n\n#include \"absl/strings/str_cat.h\"\n"))))
3919 (add-after 'opencl-fix 'stdint-fix
3920 (lambda _
3921 (substitute* "kernels/internal/spectrogram.cc"
3922 (("#include <math.h>")
3923 "#include <math.h>\n#include <cstdint>\n"))))
3924 (add-after 'stdint-fix 'gemmlowp-fix
3925 (lambda _
3926 (substitute* "kernels/internal/common.h"
3927 (("#include \"fixedpoint/fixedpoint\\.h\"")
3928 "#include <fixedpoint/fixedpoint.h>"))))
3929 (add-after 'gemmlowp-fix 'xnn-delegate-fix
3930 ;; undefined function, remove call to it
3931 (lambda _
3932 (substitute* "delegates/xnnpack/xnnpack_delegate.cc"
3933 (("xnn_experiment_enable_adaptive_avx_optimization\\(\\);")
3934 ""))))
3935 (add-after 'build 'build-shared-library
3936 (lambda* (#:key configure-flags #:allow-other-keys)
3937 (mkdir-p "c")
3938 (with-directory-excursion "c"
3939 (apply invoke "cmake" (append configure-flags (list "../../lite/c")))
3940 (invoke "cmake" "--build" "." "-j" (number->string
3941 (parallel-job-count))))))
3942 (add-after 'build-shared-library 'build-benchmark-model
3943 (lambda _
3944 (invoke "cmake" "--build" "." "--target" "benchmark_model"
3945 "-j" (number->string (parallel-job-count)))))
3946 (add-after 'build-benchmark-model 'build-python
3947 (lambda* (#:key configure-flags #:allow-other-keys)
3948 (let ((script (string-append "../lite/tools/pip_package/"
3949 "build_pip_package_with_cmake.sh")))
3950 (substitute* script
3951 (("\"\\$\\{TENSORFLOW_LITE_DIR\\}\"" all)
3952 (string-append "${ADDITIONAL_CMAKE_FLAGS} " all))
3953 (("-D(CMAKE_C[X]*_FLAGS)=\"\\$\\{BUILD_FLAGS\\}" all flag)
3954 (string-append all " ${ADDITIONAL_" flag "}")))
3955 (setenv "BUILD_NUM_JOBS" (number->string (parallel-job-count)))
3956 (let* ((config (map (cut string-split <> #\=) configure-flags))
3957 (c-flags (assoc-ref config "-DCMAKE_C_FLAGS"))
3958 (config (alist-delete "-DCMAKE_C_FLAGS" config))
3959 (cxx-flags (assoc-ref config "-DCMAKE_CXX_FLAGS"))
3960 (config (alist-delete "-DCMAKE_CXX_FLAGS" config)))
3961 (setenv "ADDITIONAL_CMAKE_C_FLAGS"
3962 (string-join c-flags "="))
3963 (setenv "ADDITIONAL_CMAKE_CXX_FLAGS"
3964 (string-join cxx-flags "="))
3965 (setenv "ADDITIONAL_CMAKE_FLAGS"
3966 (string-join (map (cut string-join <> "=") config)
3967 " ")))
3968 (invoke "sh" script))))
3969 (add-after 'install 'install-extra
3970 (lambda _
3971 (install-file "../build/c/libtensorflowlite_c.so"
3972 (string-append #$output "/lib"))
3973 (install-file "../build/tools/benchmark/benchmark_model"
3974 (string-append #$output "/bin"))))
3975 (add-after 'install-extra 'install-python
3976 (lambda* (#:key inputs outputs #:allow-other-keys)
3977 (with-directory-excursion
3978 "../lite/tools/pip_package/gen/tflite_pip/python3"
3979 ((assoc-ref py:%standard-phases 'install)
3980 #:inputs inputs
3981 #:outputs `(("out" . ,#$output:python))))))
3982 (replace 'check
3983 (lambda* (#:key tests? #:allow-other-keys)
3984 (when tests?
3985 (invoke "ctest" "-L" "plain"))))
3986 (add-after 'install-python 'add-install-to-pythonpath
3987 (lambda* (#:key inputs #:allow-other-keys)
3988 ((assoc-ref py:%standard-phases 'add-install-to-pythonpath)
3989 #:inputs inputs
3990 #:outputs `(("out" . ,#$output:python)))))
3991 (add-after 'add-install-to-pythonpath 'python-sanity-check
3992 (lambda* (#:key tests? inputs #:allow-other-keys)
3993 ((assoc-ref py:%standard-phases 'sanity-check)
3994 #:inputs `(("sanity-check.py" . ,#$(default-sanity-check.py))
3995 ,@inputs)
3996 #:outputs `(("out" . ,#$output:python))))))))
3997 (inputs
3998 (list abseil-cpp
3999 cpuinfo
4000 eigen
4001 fp16
4002 flatbuffers-23.5
4003 gemmlowp
4004 mesa-headers
4005 neon2sse
4006 nsync
4007 opencl-icd-loader
4008 pthreadpool
4009 python ;for its /lib
4010 python-ml-dtypes
4011 ruy
4012 re2
4013 xnnpack
4014 vulkan-headers
4015 zlib))
4016 (propagated-inputs
4017 (list python-numpy))
4018 (native-inputs
4019 (list pkg-config
4020 googletest
4021 pybind11-2
4022 python-setuptools
4023 python-wrapper ;for its /bin
4024 swig-4.0
4025 (origin
4026 (method git-fetch)
4027 (uri (git-reference
4028 (url "https://github.com/google/farmhash")
4029 (commit "816a4ae622e964763ca0862d9dbd19324a1eaf45")))
4030 (file-name "farmhash-src")
4031 (sha256
4032 (base32
4033 "1mqxsljq476n1hb8ilkrpb39yz3ip2hnc7rhzszz4sri8ma7qzp6")))
4034 (origin
4035 (method git-fetch)
4036 (uri (git-reference
4037 (url "https://github.com/petewarden/OouraFFT")
4038 (commit "v1.0")))
4039 (file-name "fft2d-src")
4040 (sha256
4041 (base32
4042 "1gla8m477din9k7jnbkzzbvc0wzw2rn97skxwf0k0mwcdf6vlhcs")))))
4043 (home-page "https://www.tensorflow.org")
4044 (synopsis "Machine learning framework")
4045 (description
4046 "TensorFlow is a flexible platform for building and training machine
4047learning models. This package provides the \"lite\" variant for mobile
4048devices.")
4049 (license license:asl2.0)))
4050
4051(define-public python-tflite-runtime
4052 (package
4053 (inherit tensorflow-lite)
4054 (name "python-tflite-runtime")
4055 (source #f)
4056 (build-system trivial-build-system)
4057 (outputs (list "out"))
4058 (arguments
4059 (list
4060 #:builder
4061 #~(begin
4062 (mkdir #$output)
4063 (symlink (string-append #$tensorflow-lite:python "/lib")
4064 (string-append #$output "/lib")))))
4065 (native-inputs '())))
4066
4067(define-public tflite-micro
4068 (let ((commit "a94423c6b6ee1f30c82d60952d70f749296a5581")
4069 (version "0")
4070 (revision "0"))
4071 (package
4072 (name "tflite-micro")
4073 (version (git-version version revision commit))
4074 (source
4075 (origin
4076 (method git-fetch)
4077 (uri (git-reference
4078 (url "https://github.com/tensorflow/tflite-micro")
4079 (commit commit)))
4080 (file-name (git-file-name name version))
4081 (sha256
4082 (base32 "0q1l4chj4p7vwclcysjmzl017l08kpqh498wpghq1cph641mdp5n"))
4083 (patches (search-patches "tflite-micro_disable_download.patch"))))
4084 (build-system gnu-build-system)
4085 (arguments
4086 (list
4087 #:tests? #f ;there are no tests
4088 #:phases
4089 #~(modify-phases %standard-phases
4090 (add-after 'unpack 'patch-makefile
4091 (lambda _
4092 (let ((makefile "tensorflow/lite/micro/tools/make/Makefile"))
4093 (substitute* makefile
4094 (("BASE_GENDIR := gen")
4095 "BASE_GENDIR := $(BUILD_DIR)")))))
4096 (delete 'configure)
4097
4098 (replace 'build
4099 (lambda _
4100 (let ((makefile "tensorflow/lite/micro/tools/make/Makefile"))
4101 (mkdir-p "../build")
4102 (invoke "make"
4103 "-j"
4104 (number->string (parallel-job-count))
4105 "-f"
4106 makefile
4107 (string-append "BASE_GENDIR=" "../build")
4108 (string-append "PRE_INCLUDES=-I"
4109 #$(this-package-input "gemmlowp")
4110 "/include/gemmlowp"
4111 " -I"
4112 #$(this-package-input
4113 "kissfft-for-tflite-micro")
4114 "/include/kissfft"
4115 " -I"
4116 #$(package-source
4117 kissfft-for-tflite-micro))))))
4118 (replace 'install
4119 (lambda _
4120 (for-each (lambda (f)
4121 (install-file f
4122 (string-append #$output "/lib")))
4123 (find-files "../build" "\\.a$"))
4124 (for-each (lambda (f)
4125 (install-file f
4126 (string-append #$output
4127 "/include/lite/micro")))
4128 (find-files "tensorflow/lite/micro" "\\.h$"))
4129 (for-each (lambda (f)
4130 (install-file f
4131 (string-append #$output
4132 "/include/lite/micro")))
4133 (find-files "signal/micro/kernels" "\\.h$"))
4134 (for-each (lambda (f)
4135 (install-file f
4136 (string-append #$output
4137 "/include/lite/micro")))
4138 (find-files "signal/src" "\\.h$")))))))
4139 (inputs (list flatbuffers-23.5 gemmlowp kissfft-for-tflite-micro ruy))
4140 (native-inputs (list python python-pillow python-numpy))
4141 (home-page "https://ai.google.dev/edge/litert/microcontrollers/overview")
4142 (synopsis
4143 "Infrastructure to enable deployment of ML models to embedded targets ")
4144 (description
4145 "TensorFlow Lite for Microcontrollers is a port of TensorFlow Lite designed
4146to run machine learning models on DSPs, microcontrollers and other devices with
4147limited memory.")
4148 (license license:asl2.0))))
4149
4150
4151(define-public dmlc-core
4152 (package
4153 (name "dmlc-core")
4154 (version "0.5")
4155 (source
4156 (origin
4157 (method git-fetch)
4158 (uri (git-reference
4159 (url "https://github.com/dmlc/dmlc-core")
4160 (commit (string-append "v" version))))
4161 (file-name (git-file-name name version))
4162 (sha256
4163 (base32 "1x4ad1jhn84fywlk031fmv1kxyiscclmrqn9hhj8gz0mh7z9vcrh"))))
4164 (build-system cmake-build-system)
4165 (arguments
4166 (list
4167 #:configure-flags #~(list "-DGOOGLE_TEST=ON")))
4168 (native-inputs
4169 (list googletest python-wrapper))
4170 (home-page "https://github.com/dmlc/dmlc-core")
4171 (synopsis "Common bricks library for machine learning")
4172 (description
4173 "DMLC-Core is the backbone library to support all DMLC projects,
4174offers the bricks to build efficient and scalable distributed machine
4175learning libraries.")
4176 (license license:asl2.0)))
4177
4178(define-public dmlc-core-next
4179 ;; Apache Tvm needs the latest code from git commits in May 2024 or later.
4180 (let ((commit "13341857549852a9a86b1894b5ba84c6276ab381")
4181 (revision "1"))
4182 (package
4183 (inherit dmlc-core)
4184 (name "dmlc-core")
4185 (version (git-version "0.5" revision commit))
4186 (source
4187 (origin
4188 (method git-fetch)
4189 (uri (git-reference
4190 (url "https://github.com/dmlc/dmlc-core")
4191 (commit commit)))
4192 (file-name (git-file-name name version))
4193 (sha256
4194 (base32 "1hj6h103lal3cm5mnry9lrm3d7aij89rxv46yv6y49vzd5hbnfbd")))))))
4195
4196(define-public xgboost
4197 (package
4198 (name "xgboost")
4199 (version "1.7.6")
4200 (source
4201 (origin
4202 (method git-fetch)
4203 (uri (git-reference
4204 (url "https://github.com/dmlc/xgboost")
4205 (commit (string-append "v" version))))
4206 (file-name (git-file-name name version))
4207 (patches (search-patches "xgboost-use-system-dmlc-core.patch"))
4208 (sha256
4209 (base32 "16fbm5y3hn6ccflmbdlmn7krrdq7c0az3mxd8j1d23s9ky8niw05"))))
4210 (build-system cmake-build-system)
4211 (arguments
4212 (list #:configure-flags #~(list "-DGOOGLE_TEST=ON")))
4213 (native-inputs
4214 (list googletest
4215 python-wrapper))
4216 (inputs
4217 (list dmlc-core))
4218 (home-page "https://xgboost.ai/")
4219 (synopsis "Gradient boosting (GBDT, GBRT or GBM) library")
4220 (description
4221 "XGBoost is an optimized distributed gradient boosting library designed
4222to be highly efficient, flexible and portable. It implements machine learning
4223algorithms under the Gradient Boosting framework. XGBoost provides a parallel
4224tree boosting (also known as GBDT, GBM) that solve many data science problems
4225in a fast and accurate way.")
4226 (license license:asl2.0)))
4227
4228(define-public python-xgboost
4229 (package
4230 (inherit xgboost)
4231 (name "python-xgboost")
4232 (source (package-source xgboost))
4233 (build-system pyproject-build-system)
4234 (arguments
4235 (list
4236 #:tests? #f ; all tests require network access
4237 #:phases
4238 #~(modify-phases %standard-phases
4239 (add-after 'unpack 'preparations
4240 (lambda _
4241 ;; Move python-package content to parent directory to silence
4242 ;; some warnings about files not being found if we chdir.
4243 (rename-file "python-package/xgboost" "xgboost")
4244 (rename-file "python-package/README.rst" "README.rst")
4245 (rename-file "python-package/setup.cfg" "setup.cfg")
4246 (rename-file "python-package/setup.py" "setup.py")
4247 ;; Skip rebuilding libxgboost.so.
4248 (substitute* "setup.py"
4249 (("ext_modules=\\[CMakeExtension\\('libxgboost'\\)\\],") "")
4250 (("'install_lib': InstallLib,") ""))
4251 ;; Remove bad dataset. This has been removed in scipy.
4252 (substitute* "tests/python/testing.py"
4253 (("TestDataset\\('boston', get_boston, 'reg:squarederror', 'rmse'\\),")
4254 "")
4255 (("datasets.load_boston")
4256 "datasets.load_digits"))))
4257 (add-after 'install 'install-version-and-libxgboost
4258 (lambda* (#:key inputs #:allow-other-keys)
4259 (let* ((pylib (string-append #$output "/lib/python"
4260 #$(version-major+minor
4261 (package-version python))
4262 "/site-packages"))
4263 (xgbdir (string-append pylib "/xgboost"))
4264 (version-file (string-append xgbdir "/VERSION"))
4265 (libxgboost (string-append (assoc-ref inputs "xgboost")
4266 "/lib/libxgboost.so")))
4267 (with-output-to-file version-file
4268 (lambda ()
4269 (display #$(package-version xgboost))))
4270 (mkdir-p (string-append xgbdir "/lib"))
4271 (symlink libxgboost (string-append xgbdir "/lib"
4272 "/libxgboost.so"))))))))
4273 (native-inputs
4274 (list python-pandas python-pytest python-scikit-learn python-setuptools
4275 python-wheel))
4276 (inputs
4277 (list xgboost))
4278 (propagated-inputs
4279 (list python-numpy python-scipy))
4280 (synopsis "Python interface for the XGBoost library")))
4281
4282(define-public gloo
4283 (let ((version "0.0.0") ; no proper version tag
4284 (commit "54cbae0d3a67fa890b4c3d9ee162b7860315e341")
4285 (revision "4"))
4286 (package
4287 (name "gloo")
4288 (version (git-version version revision commit))
4289 (source
4290 (origin
4291 (method git-fetch)
4292 (uri (git-reference
4293 (url "https://github.com/pytorch/gloo")
4294 (commit commit)))
4295 (file-name (git-file-name name version))
4296 (sha256
4297 (base32
4298 "1zixybyma7zpwdawy1qi2d48g9r65wcjjd4j3j2bhlvjymyw03z2"))))
4299 (build-system cmake-build-system)
4300 (native-inputs
4301 (list googletest))
4302 (inputs
4303 (append (list openssl)
4304 (if (supported-package? rdma-core)
4305 (list rdma-core)
4306 '())))
4307 (arguments
4308 (list #:configure-flags #~'("-DBUILD_SHARED_LIBS=ON"
4309 "-DBUILD_TEST=1"
4310 "-DCMAKE_CXX_STANDARD=17"
4311 #$@(if (this-package-input "rdma-core")
4312 #~("-DUSE_IBVERBS=ON")
4313 #~()))
4314 #:phases
4315 #~(modify-phases %standard-phases
4316 (replace 'check
4317 (lambda* (#:key tests? #:allow-other-keys)
4318 (when tests?
4319 (invoke "make" "gloo_test")))))))
4320 (synopsis "Collective communications library")
4321 (description
4322 "Gloo is a collective communications library. It comes with a
4323number of collective algorithms useful for machine learning applications.
4324These include a barrier, broadcast, and allreduce.")
4325 (home-page "https://github.com/facebookincubator/gloo")
4326 (supported-systems %64bit-supported-systems)
4327 (license license:bsd-3))))
4328
4329(define-public gloo-for-r-torch
4330 (let ((version "0.0.0") ; no proper version tag
4331 (commit "81925d1c674c34f0dc34dd9a0f2151c1b6f701eb")
4332 (revision "2"))
4333 (package
4334 (name "gloo")
4335 (version (git-version version revision commit))
4336 (source
4337 (origin
4338 (method git-fetch)
4339 (uri (git-reference
4340 (url "https://github.com/facebookincubator/gloo")
4341 (commit commit)))
4342 (file-name (git-file-name name version))
4343 (sha256
4344 (base32
4345 "16zs8ndbiv9nppn8bv6lfanzyyssz7g5pawxiqcnafwq3nvxpj9m"))))
4346 (build-system cmake-build-system)
4347 (native-inputs
4348 (list googletest))
4349 (inputs
4350 (append (list openssl-1.1)
4351 (if (supported-package? rdma-core)
4352 (list rdma-core)
4353 '())))
4354 (arguments
4355 (list #:configure-flags #~'("-DBUILD_SHARED_LIBS=ON"
4356 "-DBUILD_TEST=1"
4357 "-DCMAKE_CXX_STANDARD=17"
4358 #$@(if (this-package-input "rdma-core")
4359 #~("-DUSE_IBVERBS=ON")
4360 #~()))
4361 #:phases
4362 #~(modify-phases %standard-phases
4363 (replace 'check
4364 (lambda* (#:key tests? #:allow-other-keys)
4365 (when tests?
4366 (invoke "make" "gloo_test")))))))
4367 (synopsis "Collective communications library")
4368 (description
4369 "Gloo is a collective communications library. It comes with a
4370number of collective algorithms useful for machine learning applications.
4371These include a barrier, broadcast, and allreduce.")
4372 (home-page "https://github.com/facebookincubator/gloo")
4373 (supported-systems %64bit-supported-systems)
4374 (license license:bsd-3))))
4375
4376(define-public python-tensorly
4377 (package
4378 (name "python-tensorly")
4379 (version "0.9.0")
4380 (source (origin
4381 (method git-fetch)
4382 (uri (git-reference
4383 (url "https://github.com/tensorly/tensorly")
4384 (commit version)))
4385 (file-name (git-file-name name version))
4386 (sha256
4387 (base32
4388 "01xdkhzwq7s18pp6433d4dhyblmlhjs87acagxh73vfsqyknb9h3"))))
4389 (build-system pyproject-build-system)
4390 (arguments
4391 (list
4392 #:test-flags
4393 '(list
4394 ;; These tests fail due to missing example, documentation, or tutorial files.
4395 "--ignore=doc/sphinx_ext/sphinx_gallery/tests/test_gen_rst.py"
4396 ;; XXX There is no "get_marker" method.
4397 "--ignore=doc/sphinx_ext/sphinx_gallery/tests/test_gen_gallery.py"
4398 "-k"
4399 (string-append
4400 ;; tutorials/plot_parse.py is not included
4401 "not test_jupyter_notebook"
4402 ;; nor is examples/plot_quantum.py
4403 " and not test_file_is_generated"))))
4404 (propagated-inputs (list python-jsmin python-numpy python-scipy))
4405 (native-inputs (list python-pytest python-sphinx
4406 python-setuptools python-wheel))
4407 (home-page "https://github.com/tensorly/tensorly")
4408 (synopsis "Tensor learning in Python")
4409 (description
4410 "This is a Python library that aims at making tensor learning simple and
4411accessible. It allows performing tensor decomposition, tensor learning and
4412tensor algebra easily. Its backend system allows seamlessly perform
4413computation with NumPy, PyTorch, JAX, MXNet, TensorFlow or CuPy and run
4414methodxs at scale on CPU or GPU.")
4415 (license license:bsd-3)))
4416
4417(define-public python-umap-learn
4418 (package
4419 (name "python-umap-learn")
4420 (version "0.5.12")
4421 (source
4422 (origin
4423 (method git-fetch)
4424 (uri (git-reference
4425 (url "https://github.com/lmcinnes/umap")
4426 (commit (string-append "release-" version))))
4427 (file-name (git-file-name name version))
4428 (sha256
4429 (base32 "18ahwd94z6ravxvgpw3wyclcyzfpig93197znzgsg2350bgnzr1l"))))
4430 (build-system pyproject-build-system)
4431 (arguments
4432 (list
4433 ;; tests: 253 passed, 65 skipped, 56 warnings
4434 #:phases
4435 #~(modify-phases %standard-phases
4436 ;; Numba needs a writable dir to cache functions.
4437 (add-before 'build 'set-numba-cache-dir
4438 (lambda _
4439 (setenv "NUMBA_CACHE_DIR" "/tmp"))))))
4440 (native-inputs
4441 (list python-pytest
4442 python-setuptools))
4443 (propagated-inputs
4444 (list python-numba
4445 python-numpy
4446 python-pynndescent
4447 python-scikit-learn
4448 python-scipy
4449 python-tqdm))
4450 (home-page "https://github.com/lmcinnes/umap")
4451 (synopsis "Uniform Manifold Approximation and Projection")
4452 (description
4453 "Uniform Manifold Approximation and Projection is a dimension reduction
4454technique that can be used for visualization similarly to t-SNE, but also for
4455general non-linear dimension reduction.")
4456 (license license:bsd-3)))
4457
4458;; Requires AVX2 on x86_64-linux.
4459(define-public nnpack
4460 (let ((version "0.0")
4461 (commit "70a77f485e8b934224f3a79efd8edcd84cd377b8")
4462 (revision "2"))
4463 (package
4464 (name "nnpack")
4465 (version (git-version version revision commit))
4466 (home-page "https://github.com/Maratyszcza/NNPACK")
4467 (source (origin
4468 (method git-fetch)
4469 (uri (git-reference (url home-page) (commit commit)))
4470 (file-name (git-file-name name version))
4471 (sha256
4472 (base32
4473 "0c4pw926279s3rlx7mg4l4vhnfy6dh374n6w7zqhcn0bxpym1hv1"))
4474 (patches (search-patches "nnpack-system-libraries.patch"))))
4475 (build-system cmake-build-system)
4476 ;; XXX: The test suite runs but it's very expensive. On x86_64-linux, it
4477 ;; requires AVX2 instructions.
4478 (arguments '(#:tests? #f))
4479 (synopsis "Acceleration package for neural network computations")
4480 (description
4481 "NNPACK is an acceleration package for neural network computations.
4482NNPACK aims to provide high-performance implementations of convnet layers for
4483multi-core CPUs.
4484
4485NNPACK is not intended to be directly used by machine learning researchers;
4486instead it provides low-level performance primitives leveraged in leading deep
4487learning frameworks, such as PyTorch, Caffe2, MXNet, tiny-dnn, Caffe, Torch,
4488and Darknet.")
4489 (inputs
4490 (list cpuinfo
4491 fp16
4492 fxdiv
4493 psimd
4494 pthreadpool
4495 googletest-1.12))
4496 (native-inputs
4497 `(,python
4498 ,@(if (target-x86-64?) (list python-peachpy) '())
4499 ,python-six))
4500 ;; Supported for Linux.
4501 (supported-systems '("x86_64-linux" "armhf-linux" "aarch64-linux"))
4502 (license license:bsd-2))))
4503
4504(define-public qnnpack
4505 (let ((commit "7d2a4e9931a82adc3814275b6219a03e24e36b4c")
4506 (revision "0"))
4507 (package
4508 (name "qnnpack")
4509 (version (git-version "0" revision commit))
4510 (source
4511 (origin
4512 (method git-fetch)
4513 (uri (git-reference
4514 (url "https://github.com/pytorch/qnnpack")
4515 (commit commit)))
4516 (file-name (git-file-name name version))
4517 (sha256
4518 (base32
4519 "1dgzriiaz9arsrfwhx42y4l74wbzn6xvdmllfb66v4pmvi5gpxc5"))
4520 (modules '((guix build utils)))
4521 (snippet
4522 '(delete-file-recursively "deps"))))
4523 (build-system cmake-build-system)
4524 (arguments
4525 (list
4526 ;; The shared library build fails with linker errors, so we build the
4527 ;; static library with -fPIC as in the bundled PyTorch version.
4528 #:configure-flags
4529 ''("-DQNNPACK_LIBRARY_TYPE=static"
4530 "-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
4531 #:phases
4532 #~(modify-phases %standard-phases
4533 (add-after 'unpack 'patch-cmake
4534 (lambda _
4535 (substitute* "CMakeLists.txt"
4536 (("IF.*SOURCE_DIR.*")
4537 "IF(FALSE)\n")
4538 (("IF\\(NOT TARGET.*")
4539 "IF(FALSE)\n")
4540 (("TARGET_LINK_LIBRARIES.*(fxdiv|psimd|fp16)\\).*")
4541 "")
4542 (("(TARGET_LINK_LIBRARIES.*) fp16 (.*)" _ before after)
4543 (string-append before " " after))))))))
4544 (inputs (list clog cpuinfo fp16 fxdiv psimd pthreadpool))
4545 (native-inputs (list googletest-1.12 googlebenchmark))
4546 (home-page "https://github.com/pytorch/qnnpack")
4547 (synopsis "Quantized Neural Network PACKage")
4548 (description "QNNPACK is a library for low-precision neural network
4549inference. It contains the implementation of common neural network operators
4550on quantized 8-bit tensors.")
4551 (supported-systems
4552 '("armhf-linux" "aarch64-linux" "i686-linux" "x86_64-linux"))
4553 (license license:bsd-3))))
4554
4555(define-public xnnpack
4556 ;; There's currently no tag on this repo.
4557 (let ((version "0.0")
4558 (commit "51a0103656eff6fc9bfd39a4597923c4b542c883")
4559 (revision "4"))
4560 (package
4561 (name "xnnpack")
4562 (version (git-version version revision commit))
4563 (home-page "https://github.com/google/XNNPACK") ;fork of QNNPACK
4564 (source
4565 (origin
4566 (method git-fetch)
4567 (uri (git-reference (url home-page) (commit commit)))
4568 (file-name (git-file-name name version))
4569 (sha256
4570 (base32
4571 "0j4smj8yaxw6r14caqn0dgb8j8mnsq34zp8ixxn11zmgbab306ly"))
4572 (modules '((guix build utils)
4573 (ice-9 ftw)
4574 (ice-9 textual-ports)
4575 (srfi srfi-26)))
4576 (snippet
4577 '(begin
4578 (when (directory-exists? "bench/models")
4579 (delete-file-recursively "bench/models"))
4580 ;; Remove autogenerated files, which contain the string
4581 ;; "Auto-generated file"
4582 (for-each
4583 (lambda (dir)
4584 (for-each
4585 (lambda (name)
4586 (let ((path (string-append dir "/" name)))
4587 (when (call-with-input-file path
4588 (lambda (port)
4589 (string-contains
4590 (get-string-all port)
4591 "Auto-generated file")))
4592 (delete-file path))))
4593 (or (scandir dir (negate (cut member <> '("." ".." "simd"))))
4594 '())))
4595 (cons*
4596 "test" "bench" "src/enums" "src/xnnpack" "gen" "cmake/gen"
4597 (filter file-exists?
4598 (map (cut string-append "src/" <> "/gen")
4599 (scandir "src")))))))))
4600 (build-system cmake-build-system)
4601 (arguments
4602 (list
4603 #:build-type "Release" ;; Debugging symbols require a lot of disk space
4604 #:configure-flags
4605 #~(list "-DXNNPACK_USE_SYSTEM_LIBS=YES"
4606 "-DBUILD_SHARED_LIBS=ON"
4607 "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
4608 "-DXNNPACK_LIBRARY_TYPE=shared"
4609 "-DXNNPACK_BUILD_BENCHMARKS=FALSE"
4610 ;; Tests fail to build with -DXNNPACK_LIBRARY_TYPE=shared:
4611 ;; https://github.com/google/XNNPACK/issues/6285
4612 "-DXNNPACK_BUILD_TESTS=OFF")
4613 #:tests? #f
4614 #:modules '((ice-9 ftw)
4615 (guix build cmake-build-system)
4616 (guix build utils))
4617 #:phases
4618 #~(modify-phases %standard-phases
4619 (add-after 'unpack 'fix-cmake
4620 (lambda _
4621 (substitute* "CMakeLists.txt"
4622 (("TARGET_INCLUDE_DIRECTORIES\\((pthreadpool|cpuinfo).*") "")
4623 (("AMD64") "x86_64"))))
4624 (add-after 'patch-source-shebangs 'generate-files
4625 (lambda _
4626 ;; This script just calls two other scripts.
4627 (delete-file "scripts/generate-tests-and-benchmarks.sh")
4628 ;; The bash scripts run all jobs at once and then wait, so we
4629 ;; convert them to Makefiles.
4630 (for-each
4631 (lambda (name)
4632 (define counter 0) ; For the targets
4633 (define target-deps "")
4634 (when (and (string-prefix? "generate" name)
4635 (string-suffix? ".sh" name))
4636 (let ((file (string-append "scripts/" name)))
4637 (substitute* file
4638 ;; Turn the commands into targets. Avoid comments and
4639 ;; lines starting with - (rest of multilines).
4640 (("\
4641^[[:space:]]*([^ #-].*/.*(\\.sh|\\.py|-o |--output)[^&]*).*$"
4642 _ command)
4643 (begin
4644 (set! counter (+ counter 1))
4645 (string-append "\ntarget" (number->string counter)
4646 ":" target-deps
4647 "\n\t" command)))
4648 ;; Remove trailing '&' characters.
4649 (("&?[[:space:]]*$") "\n")
4650 (("[[:space:]]*wait[[:space:]]*") "")
4651 ;; The commands after this line depend on the
4652 ;; previous commands in the file.
4653 (("JIT requires assembly files to be generated first.*" all)
4654 (begin
4655 (set! target-deps
4656 (string-append
4657 target-deps " target"
4658 (string-join
4659 (map number->string (iota counter 1)) " target")))
4660 all)))
4661 (display (string-append "Running " name "\n"))
4662 (apply invoke "make" "-s" "-f" file "-j"
4663 (number->string (parallel-job-count))
4664 (map
4665 (lambda (i)
4666 (string-append "target" (number->string i)))
4667 (iota counter 1))))))
4668 (scandir "scripts"))
4669 ;; These need to run after the above scripts
4670 (display "Remaining files\n")
4671 (invoke "python3" "tools/update-microkernels.py")
4672 (invoke "python3" "tools/generate-lut-norm-test.py"
4673 "--spec" "test/u8-lut32norm.yaml"
4674 "--output" "test/u8-lut32norm.cc")
4675 ;; Check existence to avoid doubling the phase for r-torch.
4676 (when (file-exists? "test/qd8-f16-qb4w-gemm-minmax.yaml")
4677 (invoke "python3" "tools/generate-gemm-test.py"
4678 "--spec" "test/qd8-f16-qb4w-gemm-minmax.yaml"
4679 "--output-test" "test/qd8-f16-qb4w-gemm-minmax.cc"))
4680 (when (file-exists? "test/qd8-f32-qb4w-gemm-minmax.yaml")
4681 (invoke "python3" "tools/generate-gemm-test.py"
4682 "--spec" "test/qd8-f32-qb4w-gemm-minmax.yaml"
4683 "--output-test" "test/qd8-f32-qb4w-gemm-minmax.cc")))))))
4684 (inputs
4685 (list clog
4686 cpuinfo
4687 pthreadpool
4688 googletest
4689 googlebenchmark
4690 fxdiv
4691 fp16
4692 psimd))
4693 (native-inputs
4694 (list python-pyyaml python-wrapper))
4695 (synopsis "Optimized floating-point neural network inference operators")
4696 (description
4697 "XNNPACK is a highly optimized library of floating-point neural network
4698inference operators for ARM, WebAssembly, and x86 platforms. XNNPACK is not
4699intended for direct use by deep learning practitioners and researchers;
4700instead it provides low-level performance primitives for accelerating
4701high-level machine learning frameworks, such as TensorFlow Lite,
4702TensorFlow.js, PyTorch, and MediaPipe.")
4703 (supported-systems
4704 '("armhf-linux" "aarch64-linux" "riscv64-linux"
4705 "i686-linux" "x86_64-linux"))
4706 (license license:bsd-3))))
4707
4708;; Warning: This package requires AVX2 or AVX-512 instructions.
4709(define-public fbgemm
4710 (package
4711 (name "fbgemm")
4712 (version "1.5.0")
4713 (source (origin
4714 (method git-fetch)
4715 (uri (git-reference
4716 (url "https://github.com/pytorch/fbgemm")
4717 (commit (string-append "v" version))))
4718 (file-name (git-file-name name version))
4719 (sha256
4720 (base32
4721 "0dygcx42iijyhgpj5a8lams1avvc4d0cnvrbgzgxvpf3zx50n01a"))
4722 (patches (search-patches "fbgemm-use-system-libraries.patch"))))
4723 (build-system cmake-build-system)
4724 (arguments
4725 (list
4726 #:configure-flags
4727 ''("-DFBGEMM_LIBRARY_TYPE=shared")
4728 ;; Tests require AVX2 or AVX-512 instructions
4729 #:tests? #f))
4730 (inputs (list cpuinfo))
4731 (propagated-inputs (list asmjit-1.17))
4732 (native-inputs (list pkg-config python googletest))
4733 (home-page "https://github.com/pytorch/fbgemm")
4734 (synopsis "Facebook GEneral Matrix Multiplication")
4735 (description "Low-precision, high-performance matrix-matrix
4736multiplications and convolution library for server-side inference.")
4737 (supported-systems '("x86_64-linux"))
4738 (license license:bsd-3)))
4739
4740(define-public tensorpipe
4741 (let ((commit "bb1473a4b38b18268e8693044afdb8635bc8351b")
4742 (revision "0"))
4743 (package
4744 (name "tensorpipe")
4745 (version (git-version "0" revision commit))
4746 (source (origin
4747 (method git-fetch)
4748 (uri (git-reference
4749 (url "https://github.com/pytorch/tensorpipe")
4750 (commit commit)))
4751 (file-name (git-file-name name version))
4752 (sha256
4753 (base32
4754 "0sbpkd69rzybw2j89sjkf4s0j8vkk96d51bsps28894989a75j6v"))
4755 (modules '((guix build utils)))
4756 (snippet
4757 '(delete-file-recursively "third_party"))))
4758 (build-system cmake-build-system)
4759 (arguments
4760 (list
4761 #:configure-flags
4762 ''("-DBUILD_SHARED_LIBS=ON")
4763 ;; There are no tests
4764 #:tests? #f))
4765 (inputs (list libuv))
4766 (native-inputs (list googletest pkg-config pybind11-2 libnop))
4767 (home-page "https://github.com/pytorch/tensorpipe")
4768 (synopsis "Tensor-aware point-to-point communication primitive for
4769machine learning")
4770 (description "TensorPipe provides a tensor-aware channel to transfer
4771rich objects from one process to another while using the fastest transport for
4772the tensors contained therein.")
4773 (license license:bsd-3))))
4774
4775(define-public tvm
4776 ;; Include a bug fix post 0.19 release.
4777 (let ((commit "d3a2ed68a42f8b51d8ab1533b62e837b9ea74b8e")
4778 (revision "1"))
4779 (package
4780 (name "tvm")
4781 (version (git-version "0.20.dev0" revision commit))
4782 (source
4783 (origin
4784 (method git-fetch)
4785 (uri (git-reference
4786 (url "https://github.com/apache/tvm")
4787 (commit commit)))
4788 (patches (search-patches "tvm_fix_cpptest_build.patch"))
4789 (file-name (git-file-name name version))
4790 (sha256
4791 (base32 "0ng52i0aydljnlrkyg069838c8b311fynhy5976w74smma2m7v72"))))
4792 (build-system cmake-build-system)
4793 (arguments
4794 (list
4795 #:configure-flags
4796 #~(list "-DUSE_OPENCL=ON"
4797 "-DUSE_VULKAN=ON"
4798 "-DUSE_OPENCL_ENABLE_HOST_PTR=ON"
4799 "-DINSTALL_DEV=ON"
4800 "-DUSE_GTEST=ON"
4801 "-DHIDE_PRIVATE_SYMBOLS=ON" ;per upstream build instructions
4802 "-DUSE_LLVM=llvm-config\\ --ignore-libllvm\\ --link-static"
4803 ;; per upstream build instructions
4804 (string-append "-DDLPACK_PATH="
4805 (assoc-ref %build-inputs "dlpack") "/include")
4806 (string-append "-DDMLC_PATH="
4807 (assoc-ref %build-inputs "dmlc-core")
4808 "/include")
4809 (string-append "-DRANG_PATH="
4810 (assoc-ref %build-inputs "rang") "/include"))
4811 #:phases
4812 #~(modify-phases %standard-phases
4813 (replace 'check
4814 (lambda* (#:key source tests? #:allow-other-keys)
4815 (when tests?
4816 (begin
4817 (invoke "make" "-j"
4818 (number->string (parallel-job-count)) "cpptest")
4819 ;; Disable below the actual run of the tests because
4820 ;; several fail due to platform variations (for example,
4821 ;; fp16 tests fail because not supported on CPUs).
4822 ;;
4823 ;; (chdir "..")
4824 ;; (invoke (which "bash")
4825 ;; (string-append source
4826 ;; "/tests/scripts/task_cpp_unittest.sh"))
4827 )))))))
4828 (inputs (list dmlc-core-next
4829 dlpack
4830 libedit
4831 libxml2
4832 llvm-19
4833 opencl-clhpp
4834 opencl-headers-2022
4835 rang
4836 mesa
4837 mesa-opencl
4838 spirv-headers
4839 spirv-tools
4840 vulkan-headers ;TODO; now not building due to missing vta-hw
4841 vulkan-loader
4842 zlib
4843 zstd))
4844 (native-inputs (list bash-minimal
4845 googletest
4846 (module-ref (resolve-interface '(gnu packages debug))
4847 'libbacktrace)
4848 pkg-config
4849 python
4850 python-cython))
4851 (home-page "https://tvm.apache.org/")
4852 (synopsis
4853 "Machine learning compiler framework for CPUs, GPUs and accelerators")
4854 (description
4855 "Apache TVM is a compiler stack for deep learning systems. It is
4856designed to close the gap between the productivity-focused deep learning
4857frameworks, and the performance- and efficiency-focused hardware backends.
4858TVM works with deep learning frameworks to provide end to end compilation to
4859different backends")
4860 (license license:asl2.0))))
4861
4862(define-public usearch
4863 (package
4864 (name "usearch")
4865 (version "2.26.2")
4866 (source
4867 (origin
4868 (method git-fetch)
4869 (uri (git-reference
4870 (url "https://github.com/unum-cloud/usearch")
4871 (commit (string-append "v" version))))
4872 (file-name (git-file-name name version))
4873 (sha256
4874 (base32
4875 "0j8nmqh9q7n15xwlpcs6zd8wr93yl4hn0kbf4v2fcwkkbj6khhzk"))))
4876 (build-system cmake-build-system)
4877 (arguments
4878 (list
4879 #:configure-flags
4880 #~(list "-DUSEARCH_INSTALL=ON"
4881 "-DUSEARCH_BUILD_BENCH_CPP=OFF")))
4882 (inputs (list stringzilla))
4883 (home-page "https://unum.cloud/usearch")
4884 (synopsis "Similarity search engine")
4885 (description "USearch is a free software search and clustering
4886engine. Features include:
4887@itemize
4888@item 10x faster HNSW implementation than FAISS.
4889@item Simple and extensible single C++11 header library.
4890@item SIMD-optimized and user-defined metrics with JIT compilation.
4891@item Hardware-agnostic bf16, e5m2, & i8 - half-precision & quarter-precision support.
4892@item View large indexes from disk without loading into RAM.
4893@item Heterogeneous lookups, renaming/relabeling, and on-the-fly deletions.
4894@item Binary Tanimoto and Sorensen coefficients for Genomics and Chemistry applications.
4895@item Space-efficient point-clouds with uint40_t, accommodating 4B+ size.
4896@item Compatible with OpenMP and custom \"executors\" for fine-grained parallelism.
4897@item Semantic Search and Joins.
4898@item Near-real-time clustering and sub-clustering for Tens or Millions of clusters.
4899@end itemize")
4900 (license license:asl2.0)))
4901
4902(define-public koboldcpp
4903 (package
4904 (name "koboldcpp")
4905 (version "1.122")
4906 (source
4907 (origin
4908 (method git-fetch)
4909 (uri (git-reference
4910 (url "https://github.com/LostRuins/koboldcpp")
4911 (commit (string-append "v" version))))
4912 (file-name (git-file-name name version))
4913 (snippet
4914 #~(begin
4915 (use-modules (guix build utils)
4916 (ice-9 ftw)
4917 (srfi srfi-26))
4918 (delete-file-recursively "lib")
4919 (for-each delete-file (find-files "." "\\.(dll|exe|bat)$"))))
4920 (sha256
4921 (base32 "184336v6n3a3l7gvirm230rkknn93i91710wpr6190sdg5rbmmgl"))))
4922 (build-system gnu-build-system)
4923 (arguments
4924 (list
4925 #:tests? #f ;no tests
4926 #:imported-modules %pyproject-build-system-modules
4927 #:modules '((guix build gnu-build-system)
4928 ((guix build pyproject-build-system) #:prefix python:)
4929 (guix build utils))
4930 #:make-flags
4931 #~(list (string-append "CC=" #$(cc-for-target))
4932 "LLAMA_VULKAN=1"
4933 "LLAMA_PORTABLE=1"
4934 "LLAMA_USE_BUNDLED_GLSLC=0") ;; TODO: add CLBLAS
4935 #:phases
4936 #~(modify-phases %standard-phases
4937 (delete 'configure)
4938 (replace 'install
4939 (lambda _
4940 (for-each
4941 (lambda (f)
4942 (install-file f (string-append #$output "/bin")))
4943 (append (list "koboldcpp.py"
4944 "vulkan-shaders-gen"
4945 "vulkan-shaders-gen-noext")
4946 ;; koboldcpp.py expects .so's
4947 ;; to be in the same directory
4948 (find-files "." "\\.so$")))))
4949 (add-after 'install 'python-wrap
4950 (lambda* (#:key inputs outputs #:allow-other-keys)
4951 ;; Upstream removed the executable flag.
4952 (chmod (search-input-file outputs "bin/koboldcpp.py") #o744)
4953 (wrap-program (search-input-file outputs "bin/koboldcpp.py")
4954 `("GUIX_PYTHONPATH" =
4955 (,(getenv "GUIX_PYTHONPATH")
4956 ,(python:site-packages inputs outputs)))))))))
4957 (inputs
4958 (list bash-minimal
4959 python
4960 python-customtkinter
4961 spirv-headers
4962 spirv-tools
4963 vulkan-headers
4964 vulkan-loader)) ;TODO: add OpenCL
4965 (native-inputs
4966 (list shaderc))
4967 (properties '((tunable? . #t)))
4968 (home-page "https://github.com/lostruins/koboldcpp")
4969 (synopsis "AI text-generation software for GGML and GGUF models")
4970 (description "KoboldCpp is an easy-to-use AI text-generation software for
4971GGML and GGUF models, builds off llama.cpp and adds many additional features:
4972
4973@itemize
4974@item Runs on CPU or GPU, supports full or partial offloaded
4975@item LLM text generation (Supports all GGML and GGUF models, backwards
4976compatibility with ALL past models)
4977@item Image Generation (Stable Diffusion 1.5, SDXL, SD3, Flux)
4978@item Speech-To-Text (Voice Recognition) via Whisper
4979@item Text-To-Speech (Voice Generation) via OuteTTS, Kokoro, Parler and Dia
4980@item Provides many compatible APIs endpoints for many popular webservices
4981(KoboldCppApi OpenAiApi OllamaApi A1111ForgeApi ComfyUiApi
4982WhisperTranscribeApi XttsApi OpenAiSpeechApi)
4983@item Bundled KoboldAI Lite UI with editing tools, save formats, memory,
4984world info, author's note, characters, scenarios
4985@item Includes multiple modes (chat, adventure, instruct, storywriter)
4986and UI Themes (aesthetic roleplay, classic writer, corporate assistant
4987messsenger)
4988@item Supports loading Tavern Character Cards, importing many different
4989data formats from various sites, reading or exporting JSON savefiles
4990and persistent stories
4991@item Many other features including new samplers, regex support
4992websearch, RAG via TextDB, image recognition/vision and more
4993@end itemize
4994
4995All up-to-date GGUF models are supported, and KoboldCpp also includes backward
4996compatibility for older versions/legacy GGML models.")
4997 (license (list license:agpl3 license:expat))))
4998
4999
5000(define-public foxi
5001 (let
5002 ((commit "c278588e34e535f0bb8f00df3880d26928038cad")
5003 (revision "0"))
5004 (package
5005 (name "foxi")
5006 (version (git-version "1.4.1" revision commit))
5007 (source (origin
5008 (method git-fetch)
5009 (uri (git-reference
5010 (url "https://github.com/houseroad/foxi")
5011 (commit commit)))
5012 (file-name (git-file-name name version))
5013 (sha256
5014 (base32
5015 "0q3ssm5hmmvwfwx87mnnajbavzgpahybw6rpn8ysr9r095dwgq5a"))
5016 (patches (search-patches "foxi-fix-build.patch"))))
5017 (build-system cmake-build-system)
5018 (arguments
5019 (list
5020 ;; No tests
5021 #:tests? #f))
5022 (home-page "https://github.com/houseroad/foxi")
5023 (synopsis "ONNXIFI with Facebook Extension")
5024 (description "ONNX Interface for Framework Integration is a cross-platform
5025API for loading and executing ONNX graphs on optimized backends. This package
5026contains facebook extensions and is used by PyTorch.")
5027 (license license:expat))))
5028
5029(define-public ideep-pytorch
5030 (package
5031 (name "ideep-pytorch")
5032 (version "3.7.1")
5033 (source
5034 (origin
5035 (method git-fetch)
5036 (uri (git-reference
5037 (url "https://github.com/intel/ideep")
5038 (commit (string-append "pytorch-rls-v" version))))
5039 (file-name (git-file-name name version))
5040 (sha256
5041 (base32
5042 "06h3q86k9jlb1ia6rc8adzqypab7x9dmy2gc49v80ylqxab6azar"))))
5043 (build-system copy-build-system)
5044 (arguments
5045 (list
5046 #:install-plan
5047 ''(("include" "include"))))
5048 (home-page "https://github.com/intel/ideep")
5049 (synopsis "Ideep headers for internal use by PyTorch")
5050 (description "This library is used internally as header-only library by
5051PyTorch.")
5052 (license license:expat)))
5053
5054(define %python-pytorch-version "2.10.0")
5055
5056(define %python-pytorch-src
5057 (origin
5058 (method git-fetch)
5059 (uri (git-reference
5060 (url "https://github.com/pytorch/pytorch")
5061 (commit (string-append "v" %python-pytorch-version))))
5062 (file-name (git-file-name "python-pytorch" %python-pytorch-version))
5063 (sha256
5064 (base32
5065 "05pw5i1fm1i3grj8ksyrprq3an4a5pzn4ii1jkym00d0nabgbkyx"))
5066 (patches (search-patches "python-pytorch-system-libraries.patch"
5067 "python-pytorch-runpath.patch"
5068 "python-pytorch-without-kineto.patch"
5069 ;; Some autogeneration scripts depend on the
5070 ;; compile PyTorch library. Therefore, we create
5071 ;; dummy versions which are regenerated later.
5072 "python-pytorch-fix-codegen.patch"))
5073 (modules '((guix build utils)))
5074 (snippet
5075 '(begin
5076 ;; Bundled or unused code
5077 (for-each
5078 (lambda (dir)
5079 (when (file-exists? dir)
5080 (delete-file-recursively dir)))
5081 '("android"
5082 "aten/src/ATen/native/cuda/cutlass_extensions"
5083 "aten/src/ATen/native/quantized/cpu/qnnpack"
5084 "caffe2/mobile/contrib/libopencl-stub"
5085 "caffe2/mobile/contrib/libvulkan-stub"
5086 "third_party"))
5087
5088 ;; Autogenerated files
5089 (for-each
5090 delete-file
5091 '("aten/src/ATen/nnapi/nnapi_wrapper.cpp"
5092 "aten/src/ATen/nnapi/nnapi_wrapper.h"
5093 ;; These files contain just lists of floating point values and
5094 ;; might be as well hand-written.
5095 ;; "test/cpp/api/init_baseline.h"
5096 ;; "test/cpp/api/optim_baseline.h"
5097 "test/mobile/test_upgrader_bytecode_table_example.cpp"
5098 "torch/csrc/jit/mobile/upgrader_mobile.cpp"
5099 "torch/csrc/jit/runtime/decomposition_registry_util.cpp"
5100 "torch/csrc/jit/runtime/serialized_shape_function_registry.cpp"
5101 "torch/csrc/jit/tensorexpr/external_functions_codegen.cpp"
5102 "torch/csrc/jit/serialization/mobile_bytecode_generated.h"))
5103 (delete-file-recursively ".github")
5104 (for-each
5105 (lambda (dir)
5106 (for-each
5107 delete-file
5108 (find-files dir "\\.cu$")))
5109 '("aten/src/ATen/native/transformers/cuda/flash_attn"
5110 "aten/src/ATen/native/transformers/cuda/mem_eff_attention"
5111 "aten/src/ATen/native/transformers/hip/flash_attn"))))))
5112
5113(define-public qnnpack-pytorch
5114 (package
5115 (inherit qnnpack)
5116 (name "qnnpack-pytorch")
5117 (version (string-append "pytorch-" %python-pytorch-version))
5118 (source
5119 (origin
5120 (inherit %python-pytorch-src)
5121 (patches '())
5122 (modules '((guix build utils)
5123 (srfi srfi-26)
5124 (ice-9 ftw)))
5125 (snippet
5126 '(begin
5127 (rename-file "aten/src/ATen/native/quantized/cpu/qnnpack"
5128 "../qnnpack")
5129 (let ((outdir (getcwd)))
5130 (chdir "..")
5131 (rename-file outdir "dummy")
5132 (rename-file "qnnpack" outdir)
5133 (chdir outdir)
5134 (delete-file-recursively "deps"))))))
5135 (arguments
5136 (substitute-keyword-arguments arguments
5137 ((#:phases phases #~%standard-phases)
5138 #~(modify-phases %standard-phases
5139 (add-after 'unpack 'patch-cmake
5140 (lambda _
5141 (substitute* "CMakeLists.txt"
5142 (("project\\(.*" orig)
5143 (apply
5144 string-append
5145 orig "\n"
5146 (map (lambda (name)
5147 (string-append
5148 "option(" name " \"\" ON)\n"))
5149 '("USE_SYSTEM_CPUINFO" "USE_SYSTEM_FP16" "USE_SYSTEM_FXDIV"
5150 "USE_SYSTEM_PSIMD" "USE_SYSTEM_PTHREADPOOL"))))
5151 (("if.*SOURCE_DIR.*")
5152 "if(FALSE)\n")
5153 (("if\\(NOT TARGET (clog|gtest|benchmark).*")
5154 "if(FALSE)\n")
5155 (("target_link_libraries.*(fxdiv|psimd|fp16)\\).*")
5156 "")
5157 (("(target_link_libraries.*) fp16 (.*)" _ before after)
5158 (string-append before " " after)))))
5159 (add-after 'unpack 'fix-cstring-include
5160 (lambda _
5161 (substitute* "include/pack_block_sparse.h"
5162 (("#include.*<vector>.*" orig)
5163 (string-append orig "\n#include <cstring>\n")))))
5164 (add-after 'install 'install-missing-headers
5165 (lambda _
5166 (for-each
5167 (lambda (name)
5168 (install-file (string-append "../source/include/" name)
5169 (string-append #$output "/include")))
5170 '("pack_block_sparse.h"
5171 "pytorch_qnnpack.h"
5172 "qnnpack_func.h"))
5173 (copy-recursively
5174 "../source/src/qnnpack"
5175 (string-append #$output "/include/qnnpack"))))))
5176 ;; Some tests occasionally fail on i686 due to floating point rounding.
5177 ((#:tests? _ #t)
5178 (not (string-prefix? "i686" (or (%current-target-system)
5179 (%current-system)))))))))
5180
5181;; Please also update python-torchvision when updating this package.
5182(define-public python-pytorch
5183 (package
5184 (name "python-pytorch")
5185 (version %python-pytorch-version)
5186 (source %python-pytorch-src)
5187 (build-system pyproject-build-system)
5188 (arguments
5189 (list
5190 ;; Even only the core tests take a very long time to run.
5191 #:tests? #f
5192 #:phases
5193 #~(modify-phases %standard-phases
5194 (add-after 'unpack 'patch-build-system
5195 (lambda _
5196 (substitute* "pyproject.toml"
5197 (("setuptools\\.build_meta:__legacy__")
5198 "setuptools.build_meta"))))
5199 (add-after 'unpack 'cmake-patches
5200 (lambda* (#:key inputs outputs #:allow-other-keys)
5201 (substitute* "cmake/Dependencies.cmake"
5202 (("#POCKETFFT_INCLUDE_DIR")
5203 (string-append
5204 #$(this-package-native-input "pocketfft-cpp") "/include"))
5205 (("#FP16_INCLUDE_DIR")
5206 (string-append
5207 #$(this-package-input "fp16") "/include"))
5208 (("#CONCURRENTQUEUE_INCLUDE_DIR")
5209 (search-input-directory inputs "include/concurrentqueue"))
5210 ;; Disable opentelemetry
5211 ((".*(add_library|target_include_directories).*opentelemetry.*")
5212 ""))
5213 (substitute* "torch/CMakeLists.txt"
5214 ((".*opentelemetry.*") ""))
5215 ;; Fix Python install directory
5216 (substitute* "caffe2/CMakeLists.txt"
5217 (("\\$\\{Python_SITELIB\\}")
5218 (site-packages inputs outputs)))
5219 ;; Ensure httplib::httplib is defined when used.
5220 (substitute* "cmake/Caffe2Config.cmake.in"
5221 (("include *\\(.*Caffe2Targets\\.cmake.*\\)" all)
5222 (string-append "find_package(httplib REQUIRED)\n" all)))))
5223 ;; This entry point is broken, because it refers to a module that is
5224 ;; (intentionally) not installed
5225 ;; (https://github.com/pytorch/pytorch/pull/134729), which causes
5226 ;; the 'sanity-check phase to fail.
5227 (add-after 'unpack 'remove-fr-trace-script
5228 (lambda _
5229 (substitute* "setup.py"
5230 (("entry_points\\[\"console_scripts\"\\]\\.append\\(") "("))))
5231 (add-after 'remove-fr-trace-script 'skip-pip-redirect
5232 (lambda _
5233 ;; Keep using setup.py directly instead of invoking pip.
5234 (substitute* "setup.py"
5235 (("if arg == \"install\":")
5236 "if False and arg == \"install\":"))))
5237 (add-before 'build 'use-system-libraries
5238 (lambda _
5239 (for-each
5240 (lambda (file)
5241 ;; Check whether the files exist for the
5242 ;; python-pytorch-for-r-torch package
5243 (when (file-exists? file)
5244 (substitute* file
5245 (("\"miniz\\.h\"") "<miniz/miniz.h>")
5246 (("<miniz\\.h>") "<miniz/miniz.h>"))))
5247 '("caffe2/serialize/crc.cc"
5248 "caffe2/serialize/inline_container.cc"
5249 "torch/csrc/inductor/aoti_package/model_package_loader.cpp"))
5250
5251 ;; Fix missing include for getCvarString/getCvarInt.
5252 (substitute* "torch/csrc/distributed/c10d/GlooDeviceFactory.cpp"
5253 (("#include <c10/util/Exception.h>" all)
5254 (string-append
5255 "#include <torch/csrc/distributed/c10d/Utils.hpp>\n\n"
5256 all)))
5257
5258 ;; Fix moodycamel/concurrentqueue includes for system package
5259 (substitute* '("c10/util/Semaphore.h"
5260 "c10/test/util/Semaphore_test.cpp"
5261 "torch/nativert/executor/ParallelGraphExecutor.cpp")
5262 (("<moodycamel/concurrentqueue\\.h>") "<concurrentqueue.h>")
5263 (("<moodycamel/lightweightsemaphore\\.h>")
5264 "<lightweightsemaphore.h>"))
5265
5266 (substitute* "aten/src/ATen/native/vulkan/api/Allocator.h"
5267 (("<include/vk_mem_alloc.h>")
5268 "<vk_mem_alloc.h>"))
5269 ;; Fix missing <algorithm> header for std::for_each in Vulkan API
5270 (substitute* "aten/src/ATen/native/vulkan/api/QueryPool.cpp"
5271 (("#include <utility>" all)
5272 (string-append all "\n#include <algorithm>")))
5273 ;; For Vulkan
5274 (substitute* "CMakeLists.txt"
5275 (("append_cxx_flag.*-Werror=(return-type|range-loop-construct).*") ""))
5276 (substitute*
5277 (cons*
5278 "torch/csrc/Module.cpp"
5279 (map
5280 (lambda (name)
5281 (string-append
5282 "torch/utils/benchmark/utils/valgrind_wrapper/"
5283 name))
5284 '("compat_bindings.cpp" "timer_callgrind_template.cpp")))
5285 (("<callgrind.h>") "<valgrind/callgrind.h>"))
5286 (setenv "USE_VULKAN" "1")
5287 ;; Tell 'setup.py' to let 'CMakeLists.txt' know that we
5288 ;; want to use "system libraries" instead of the bundled
5289 ;; ones.
5290 (setenv "USE_SYSTEM_LIBS" "1")
5291 ;; For oneDNN
5292 (setenv "USE_MKLDNN" "1")
5293 ;; Only works with CUPTI
5294 (setenv "USE_KINETO" "0")
5295 ;; Prevent CMake error by disabling explicitely
5296 (setenv "USE_ITT" "0")
5297 ;; Disable on unsupported systems
5298 (if #$(not (member
5299 (or (%current-target-system)
5300 (%current-system))
5301 (package-transitive-supported-systems qnnpack)))
5302 (setenv "USE_QNNPACK" "0"))
5303 (substitute* '("requirements.txt" "setup.py")
5304 (("sympy>=1\\.13\\.3")
5305 "sympy>=1.13.1"))
5306 ;; Avoid ModuleNotFoundError while preserving setup.py flow.
5307 (substitute* "setup.py"
5308 (("from build_bundled import create_bundled")
5309 "create_bundled = lambda *args, **kwargs: None"))))
5310 (add-after 'use-system-libraries 'skip-nccl-call
5311 (lambda _
5312 ;; Comment-out `checkout_nccl()` invokation in build_pytorch().
5313 (substitute* "tools/build_pytorch_libs.py"
5314 (("^[[:blank:]]*checkout_nccl\\(\\)" all)
5315 (string-append "# " all "\n pass")))))
5316 ;; PyTorch is still built with AVX2 and AVX-512 support selected at
5317 ;; runtime, but these dependencies require it (nnpack only for
5318 ;; x86_64).
5319 (add-before 'build 'disable-avx-dependencies
5320 (lambda _
5321 (setenv "USE_FBGEMM" "0")
5322 (if #$(not
5323 (member (or (%current-target-system)
5324 (%current-system))
5325 '("armhf-linux" "aarch64-linux")))
5326 (setenv "USE_NNPACK" "0"))))
5327 (add-after 'use-system-libraries 'set-max-jobs
5328 (lambda _
5329 (setenv "MAX_JOBS" (number->string (parallel-job-count)))))
5330 (add-after 'set-max-jobs 'codegen1
5331 (lambda _
5332 (with-directory-excursion "torch/csrc/jit/tensorexpr"
5333 (setenv "PYTHONPATH" "../../../..")
5334 (invoke "python3" "codegen_external.py")
5335 (setenv "PYTHONPATH" #f))
5336
5337 (invoke "python3" "aten/src/ATen/nnapi/codegen.py")
5338
5339 (invoke "bash" "tools/gen_flatbuffers.sh")
5340
5341 ;; Generate dummy files as the generation depends on the compiled
5342 ;; library. They are regenerated later.
5343 (setenv "PYTHONPATH" ".")
5344 (invoke "python3"
5345 "torchgen/operator_versions/gen_mobile_upgraders.py"
5346 "dummy")
5347 (setenv "PYTHONPATH" #f)
5348
5349 (invoke "python3"
5350 "torchgen/shape_functions/gen_jit_shape_functions.py"
5351 "dummy")
5352
5353 (invoke "python3"
5354 "torchgen/decompositions/gen_jit_decompositions.py"
5355 "dummy")))
5356 ;; Properly generate autogenerated files ...
5357 (add-after 'install 'codegen2
5358 (lambda* (#:key inputs outputs #:allow-other-keys)
5359 (add-installed-pythonpath inputs outputs)
5360 (invoke "python3"
5361 "torchgen/operator_versions/gen_mobile_upgraders.py")
5362 (invoke "python3"
5363 "torchgen/shape_functions/gen_jit_shape_functions.py")
5364 (invoke "python3"
5365 "torchgen/decompositions/gen_jit_decompositions.py")))
5366 ;; ... rebuild their dependencies ...
5367 (add-after 'codegen2 'build2
5368 (lambda _
5369 (invoke "python3" "setup.py" "build")))
5370 ;; ... and install again.
5371 (add-after 'build2 'install2
5372 (lambda _
5373 (invoke "python3" "setup.py" "install" (string-append "--prefix=" #$output)
5374 "--no-compile" "--single-version-externally-managed" "--root=/")
5375 (invoke "python" "-m" "compileall"
5376 "--invalidation-mode=unchecked-hash" #$output)))
5377 (replace 'check
5378 (lambda* (#:key tests? #:allow-other-keys)
5379 ;; Run the test suite following the instructions in
5380 ;; 'CONTRIBUTING.md'. Unfortunately this doesn't work, unless
5381 ;; you set PYTHONPATH or GUIX_PYTHONPATH, but this is done in
5382 ;; the codegen2 phase already.
5383 (when tests?
5384 (invoke "python3" "test/run_test.py" "--core"))))
5385 (add-after 'install2 'remove-test-executables
5386 (lambda* (#:key inputs outputs #:allow-other-keys)
5387 ;; Remove test executables, but keep other executables
5388 ;; such as 'torch_shm_manager' and and .so files such as
5389 ;; 'libtorch_global_deps.so'.
5390 (let ((python-site (site-packages inputs outputs)))
5391 (for-each delete-file
5392 (find-files python-site
5393 "(^test_cpp_rpc|_test)$")))))
5394 (add-after 'install2 'remove-caffe2-onnx-scripts
5395 (lambda _
5396 (let ((bin (string-append #$output "/bin")))
5397 ;; Remove 'convert-caffe2-to-onnx' and
5398 ;; 'convert-onnx-to-caffe2': they seem to be
5399 ;; deprecated and they cause a failure of the
5400 ;; 'sanity-check' phase:
5401 ;;
5402 ;; ImportError: cannot import name 'metanet_pb2' from
5403 ;; partially initialized module 'caffe2.proto' (most likely
5404 ;; due to a circular import)
5405 (for-each delete-file
5406 (find-files bin "^convert-.*caffe2"))
5407
5408 (substitute* (find-files #$output "^entry_points\\.txt$")
5409 (("^convert-.*" all)
5410 (string-append "# " all "\n")))))))))
5411 (native-inputs
5412 (list cmake-minimal
5413 doxygen
5414 ideep-pytorch
5415 ninja
5416 nlohmann-json
5417 pocketfft-cpp
5418 python-expecttest
5419 python-pytest-flakefinder
5420 python-pytest-rerunfailures
5421 python-pytest-shard
5422 python-pytest-xdist
5423 python-hypothesis
5424 python-setuptools
5425 python-types-dataclasses
5426 shaderc
5427 valgrind/pinned))
5428 (inputs
5429 (append
5430 (list brotli ; for cpp-httplib
5431 clog
5432 concurrentqueue
5433 cpp-httplib
5434 eigen
5435 flatbuffers
5436 fmt
5437 fp16
5438 fxdiv
5439 gemmlowp
5440 gloo
5441 googletest-1.12
5442 googlebenchmark
5443 libuv
5444 miniz-for-pytorch
5445 onednn
5446 openblas
5447 openmpi
5448 openssl ; for cpp-httplib
5449 pthreadpool
5450 protobuf
5451 pybind11-2
5452 ;; qnnpack
5453 qnnpack-pytorch
5454 rdma-core
5455 sleef
5456 tensorpipe
5457 vulkan-headers
5458 vulkan-loader
5459 vulkan-memory-allocator
5460 xnnpack
5461 zlib ; for cpp-httplib
5462 zstd)
5463 ;; nnpack requires AVX2 for x86_64-linux
5464 (if (equal? (or (%current-target-system)
5465 (%current-system))
5466 '("aarch64-linux"))
5467 (list nnpack)
5468 '())))
5469 (propagated-inputs
5470 (append
5471 (list cpuinfo
5472 onnx ;propagated for its Python modules
5473 onnx-optimizer
5474 python-astunparse
5475 python-click
5476 python-filelock
5477 python-fsspec
5478 python-future
5479 python-jinja2
5480 python-networkx
5481 python-numpy
5482 python-opt-einsum
5483 python-optree
5484 python-packaging
5485 python-psutil
5486 python-pyyaml
5487 python-requests
5488 python-sympy
5489 python-typing-extensions)))
5490 (home-page "https://pytorch.org/")
5491 (synopsis "Python library for tensor computation and deep neural networks")
5492 ;; TODO: Support other 64-bit systems.
5493 (supported-systems '("x86_64-linux" "aarch64-linux"))
5494 (description
5495 "PyTorch is a Python package that provides two high-level features:
5496
5497@itemize
5498@item tensor computation (like NumPy) with strong GPU acceleration;
5499@item deep neural networks (DNNs) built on a tape-based autograd system.
5500@end itemize
5501
5502You can reuse Python packages such as NumPy, SciPy, and Cython to extend
5503PyTorch when needed.
5504
5505Note: currently this package does not provide GPU support.")
5506 (license license:bsd-3)))
5507
5508(define-public python-torchaudio
5509 (package
5510 (name "python-torchaudio")
5511 (version %python-pytorch-version)
5512 (source
5513 (origin
5514 (method git-fetch)
5515 (uri (git-reference
5516 (url "https://github.com/pytorch/audio")
5517 (commit (string-append "v" version))))
5518 (file-name (git-file-name name version))
5519 (sha256
5520 (base32 "1j2h722cvvwa4g4vq8gw9x214ara6qimjmyvdm1x2x2pa4fj6nvg"))))
5521 (build-system pyproject-build-system)
5522 (arguments
5523 (list
5524 #:test-flags
5525 #~(list
5526 ;; XXX: Those packages require additional inputs.
5527 "--ignore=\
5528test/torchaudio_unittest/prototype/hifi_gan/hifi_gan_cpu_test.py"
5529 "--ignore=\
5530test/torchaudio_unittest/prototype/hifi_gan/hifi_gan_gpu_test.py"
5531 "--ignore=test/torchaudio_unittest/kaldi_io_test.py"
5532 "--ignore=test/torchaudio_unittest/test_load_save_torchcodec.py"
5533 "--ignore-glob=test/torchaudio_unittest/backend/dispatcher/ffmpeg"
5534 ;; Dataset tests require torchcodec (used by 'torchaudio.load').
5535 "--ignore-glob=test/torchaudio_unittest/datasets"
5536 ;; XXX: We don't really want to run those tests.
5537 "--ignore-glob=test/torchaudio_unittest/example"
5538 ;; XXX: Integration tests require additional data / models.
5539 "--ignore-glob=test/integration_tests"
5540 ;; XXX: Those tests are very costly.
5541 "--ignore-glob=test/torchaudio_unittest/functional"
5542 "--ignore-glob=test/torchaudio_unittest/models"
5543 "--ignore=test/torchaudio_unittest/models/models_test.py"
5544 "--ignore=test/torchaudio_unittest/transforms/autograd_cpu_test.py"
5545 "-k" (string-append
5546 "not test_torchscript_fails" ; requires BUILD_SOX=1
5547 ;; XXX: Unmatching harmless warning message.
5548 " and not test_unknown_subtype_warning"
5549 ;; Skip TorchScript consistency tests that fail with 2.9.0
5550 " and not test_FrequencyMasking"
5551 " and not test_TimeMasking"
5552 " and not test_deemphasis"
5553 " and not test_rnnt_loss"))
5554 #:phases
5555 #~(modify-phases %standard-phases
5556 (add-before 'build 'configure
5557 (lambda* (#:key inputs outputs #:allow-other-keys)
5558 (setenv "BUILD_SOX" "0")
5559 (setenv "USE_FFMPEG" "0")
5560 (substitute* "tools/setup_helpers/extension.py"
5561 (("^( *)\"-DCMAKE_VERBOSE_MAKEFILE=ON\"," all blank)
5562 (string-append
5563 blank "f\"-DCMAKE_INSTALL_RPATH="
5564 (site-packages inputs
5565 `(("out" .
5566 ,(assoc-ref inputs "python-pytorch"))))
5567 "/torch/lib;"
5568 (site-packages inputs outputs) "/torchaudio/lib\",\n"
5569 blank "\"-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON\",\n"
5570 all))))))))
5571 (native-inputs
5572 (list cmake
5573 ninja
5574 onednn
5575 python-expecttest
5576 python-parameterized
5577 python-pytest
5578 python-scipy
5579 python-setuptools
5580 python-wheel
5581 sox))
5582 (inputs (package-inputs python-pytorch))
5583 (propagated-inputs (list python-soundfile python-pytorch))
5584 (home-page "https://pytorch.org/audio")
5585 (synopsis
5586 "Data manipulation and transformation for audio signal processing")
5587 (description
5588 "This package provides a machine learning library of popular datasets,
5589model architectures, and common transformations to apply @code{python-pytorch}
5590in the audio domain.")
5591 (license license:bsd-2)))
5592
5593;; This package variant includes the dependencies requiring at least AVX2 or
5594;; AVX-512.
5595(define-public python-pytorch-avx
5596 (package/inherit python-pytorch
5597 (name "python-pytorch-avx")
5598 (inputs
5599 (modify-inputs inputs
5600 (append fbgemm nnpack)))
5601 (arguments
5602 (substitute-keyword-arguments arguments
5603 ((#:phases phases)
5604 #~(modify-phases #$phases
5605 (delete 'disable-avx-dependencies)))))
5606 (supported-systems '("x86_64-linux"))))
5607
5608(define %python-pytorch-for-r-torch-version "2.7.1")
5609
5610(define %python-pytorch-for-r-torch-src
5611 (origin
5612 (inherit %python-pytorch-src)
5613 (uri (git-reference
5614 (url "https://github.com/pytorch/pytorch")
5615 (commit (string-append "v" %python-pytorch-for-r-torch-version))))
5616 (file-name (git-file-name "python-pytorch"
5617 %python-pytorch-for-r-torch-version))
5618 (sha256
5619 (base32
5620 "0734kfm66hsqdzgs2s4wj5yagvifijbgb0c5wfmp3qcdrraa9x57"))
5621 (patches (search-patches
5622 "python-pytorch-for-r-torch-system-libraries.patch"
5623 "python-pytorch-runpath.patch"
5624 "python-pytorch-for-r-torch-without-kineto.patch"
5625 ;; Some autogeneration scripts depend on the
5626 ;; compile PyTorch library. Therefore, we create
5627 ;; dummy versions which are regenerated later.
5628 "python-pytorch-for-r-torch-fix-codegen.patch"))))
5629
5630;; Keep in sync with r-torch
5631(define-public python-pytorch-for-r-torch
5632 (package
5633 (inherit python-pytorch)
5634 (name "python-pytorch")
5635 (version %python-pytorch-for-r-torch-version)
5636 (source %python-pytorch-for-r-torch-src)
5637 (build-system pyproject-build-system)
5638 (inputs
5639 (modify-inputs inputs
5640 (replace "gloo" gloo-for-r-torch)))
5641 (arguments
5642 (substitute-keyword-arguments arguments
5643 ((#:phases phases)
5644 #~(modify-phases #$phases
5645 (replace 'use-system-libraries
5646 (lambda _
5647 (for-each
5648 (lambda (file)
5649 ;; Check whether the files exist for the
5650 ;; python-pytorch-for-r-torch package
5651 (when (file-exists? file)
5652 (substitute* file
5653 (("\"miniz\\.h\"") "<miniz/miniz.h>")
5654 (("<miniz\\.h>") "<miniz/miniz.h>"))))
5655 '("caffe2/serialize/crc.cc"
5656 "caffe2/serialize/inline_container.cc"
5657 "torch/csrc/inductor/aoti_package/model_package_loader.cpp"))
5658
5659 (substitute* "aten/src/ATen/native/vulkan/api/Allocator.h"
5660 (("<include/vk_mem_alloc.h>")
5661 "<vk_mem_alloc.h>"))
5662 ;; Fix missing <algorithm> header for std::for_each in Vulkan API
5663 (substitute* "aten/src/ATen/native/vulkan/api/QueryPool.cpp"
5664 (("#include <utility>" all)
5665 (string-append all "\n#include <algorithm>")))
5666 ;; For Vulkan
5667 (substitute* "CMakeLists.txt"
5668 (("append_cxx_flag.*-Werror=(return-type|range-loop-construct).*") ""))
5669 ;; In this variant functorch is installed directly under
5670 ;; site-packages/functorch, so use a direct rpath to
5671 ;; site-packages/torch/lib.
5672 (substitute* "functorch/CMakeLists.txt"
5673 (("set_target_properties\\(\\$\\{PROJECT_NAME\\} PROPERTIES INSTALL_RPATH \"\\$\\{_rpath_portable_origin\\}/\\.\\./torch/lib\"\\)")
5674 "set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH \"$ORIGIN/../torch/lib\")"))
5675 (substitute*
5676 (cons*
5677 "torch/csrc/Module.cpp"
5678 (map
5679 (lambda (name)
5680 (string-append
5681 "torch/utils/benchmark/utils/valgrind_wrapper/"
5682 name))
5683 '("compat_bindings.cpp" "timer_callgrind_template.cpp")))
5684 (("<callgrind.h>") "<valgrind/callgrind.h>"))
5685 (setenv "USE_VULKAN" "1")
5686 ;; Tell 'setup.py' to let 'CMakeLists.txt' know that we
5687 ;; want to use "system libraries" instead of the bundled
5688 ;; ones.
5689 (setenv "USE_SYSTEM_LIBS" "1")
5690 ;; For oneDNN
5691 (setenv "USE_MKLDNN" "1")
5692 ;; Only works with CUPTI
5693 (setenv "USE_KINETO" "0")
5694 ;; Prevent CMake error by disabling explicitely
5695 (setenv "USE_ITT" "0")
5696 ;; Disable on unsupported systems
5697 (if #$(not (member
5698 (or (%current-target-system)
5699 (%current-system))
5700 (package-transitive-supported-systems qnnpack)))
5701 (setenv "USE_QNNPACK" "0"))
5702 (substitute* '("requirements.txt" "setup.py")
5703 (("sympy>=1\\.13\\.3")
5704 "sympy>=1.13.1"))
5705 ;; Avoid ModuleNotFoundError while preserving setup.py flow.
5706 (substitute* "setup.py"
5707 (("from build_bundled import create_bundled")
5708 "create_bundled = lambda *args, **kwargs: None"))))
5709 (replace 'skip-nccl-call
5710 (lambda _
5711 ;; Comment-out `checkout_nccl()` invokation in build_pytorch().
5712 (substitute* "tools/build_pytorch_libs.py"
5713 (("^[[:blank:]]*checkout_nccl\\(\\)" all)
5714 (string-append "# " all "\n pass")))))))))))
5715
5716(define-public python-pytorch-geometric
5717 (package
5718 (name "python-pytorch-geometric")
5719 (version "2.7.0")
5720 (source (origin
5721 (method git-fetch)
5722 (uri (git-reference
5723 (url "https://github.com/pyg-team/pytorch_geometric/")
5724 (commit version)))
5725 (file-name (git-file-name name version))
5726 (sha256
5727 (base32
5728 "0w6gpw0wf9w6h317mbqcf3iidx9yqjba34348p44g80ihskb6ly6"))))
5729 (build-system pyproject-build-system)
5730 (arguments
5731 (list
5732 #:test-flags
5733 '(list ;; PyTorch 2.10 raises deprecation warnings during import.
5734 "-W" "ignore::DeprecationWarning"
5735 ;; Hangs with AttributeError: 'NoneType' object has no attribute 'rpc_async'
5736 "--ignore=test/distributed/test_rpc.py"
5737 ;; A message passing jinja template is missing
5738 "--ignore=test/nn/conv/test_message_passing.py"
5739 "--ignore=test/nn/test_sequential.py"
5740 "--ignore=test/nn/models/test_basic_gnn.py"
5741 ;; These all fail with a size mismatch error such as
5742 ;; RuntimeError: shape '[-1, 2, 1, 1]' is invalid for input of size 3
5743 "--ignore=test/explain/algorithm/test_captum_explainer.py"
5744 ;; Requires the nonfree MKL on CPU.
5745 "--ignore=test/nn/models/test_graph_unet.py"
5746 "-k" (string-append
5747 ;; Permissions error
5748 "not test_packaging"
5749 ;; Unknown multiprocessing failure
5750 " and not test_data_share_memory"
5751 ;; This can fail due to accuracy problems
5752 " and not test_gdc"
5753 ;; These refuse to be run on CPU and really want a GPU
5754 " and not test_add_random_walk_pe"
5755 " and not test_asap"
5756 " and not test_two_hop"
5757 ;; Failed when switched to [email protected]
5758 ;; typing module internals
5759 " and not test_type_repr"))
5760 #:phases
5761 '(modify-phases %standard-phases
5762 (add-after 'unpack 'delete-top-level-directories
5763 (lambda _
5764 ;; The presence of these directories confuses the pyproject build
5765 ;; system.
5766 (for-each delete-file-recursively
5767 '("docker" "graphgym")))))))
5768 (propagated-inputs
5769 (list onnx
5770 python-captum
5771 python-graphviz
5772 python-h5py
5773 python-jinja2
5774 python-matplotlib
5775 python-networkx
5776 python-numba
5777 python-numpy
5778 python-opt-einsum
5779 python-pandas
5780 python-protobuf
5781 python-psutil
5782 python-pyparsing
5783 python-pytorch-lightning
5784 python-rdflib
5785 python-requests
5786 python-scikit-image
5787 python-scikit-learn
5788 python-scipy
5789 python-statsmodels
5790 python-sympy
5791 python-tabulate
5792 python-torchmetrics
5793 python-tqdm
5794 python-xxhash))
5795 (native-inputs
5796 (list openssl python-flit-core python-pytest))
5797 (home-page "https://pyg.org")
5798 (synopsis "Graph Neural Network library for PyTorch")
5799 (description
5800 "PyG is a library built upon PyTorch to easily write and train Graph
5801Neural Networks for a wide range of applications related to structured data.")
5802 (license license:expat)))
5803
5804(define-public python-lightning-cloud
5805 (package
5806 (name "python-lightning-cloud")
5807 (version "0.6.0")
5808 (source (origin
5809 (method url-fetch)
5810 (uri (pypi-uri "lightning_cloud" version))
5811 (sha256
5812 (base32
5813 "1g3zwn8r33gkmx529mvyddbrx0wqwf6125qimj4xfchf53g0qkn4"))))
5814 (arguments (list #:tests? #f)) ; no tests in PyPI archive.
5815 (build-system pyproject-build-system)
5816 (propagated-inputs (list python-boto3
5817 python-click
5818 python-fastapi
5819 python-multipart
5820 python-protobuf
5821 python-pyjwt
5822 python-requests
5823 python-rich
5824 python-six
5825 python-urllib3
5826 python-uvicorn
5827 python-websocket-client))
5828 (native-inputs (list python-setuptools))
5829 (home-page "https://lightning.ai")
5830 (synopsis "Lightning Cloud command line client")
5831 (description "This package provides a command line interface for Lightning
5832AI services.")
5833 (license license:asl2.0)))
5834
5835(define-public python-lightning-utilities
5836 (package
5837 (name "python-lightning-utilities")
5838 (version "0.15.3")
5839 (source
5840 (origin
5841 (method git-fetch)
5842 (uri (git-reference
5843 (url "https://github.com/Lightning-AI/utilities")
5844 (commit (string-append "v" version))))
5845 (file-name (git-file-name name version))
5846 (sha256
5847 (base32 "0krdvabdi1lcix5jvjjrrqyh6ibjwabc0g724mpi32gsz6g7ppwg"))))
5848 (build-system pyproject-build-system)
5849 (arguments
5850 (list #:tests? #f)) ;XXX: cycles with python-pytorch-lightning
5851 (native-inputs
5852 (list python-setuptools))
5853 (propagated-inputs
5854 (list python-packaging
5855 python-typing-extensions))
5856 (home-page "https://github.com/Lightning-AI/utilities")
5857 (synopsis "PyTorch Lightning sample project")
5858 (description "This package provides common Python utilities and GitHub
5859Actions for the Lightning suite of libraries.")
5860 (license license:asl2.0)))
5861
5862(define-public python-captum
5863 (package
5864 (name "python-captum")
5865 ;; The latest commit provides compatability with NumPy 2.
5866 (properties '((commit . "4fade3af8dc398c1f96b193c969565aad23aedf5")
5867 (revision . "0")))
5868 (version (git-version "0.8.0"
5869 (assoc-ref properties 'revision)
5870 (assoc-ref properties 'commit)))
5871 (source (origin
5872 (method git-fetch)
5873 (uri (git-reference
5874 (url "https://github.com/pytorch/captum")
5875 (commit (assoc-ref properties 'commit))))
5876 (file-name (git-file-name name version))
5877 (sha256
5878 (base32
5879 "1v1di9kk2xinwwcll5q514fn9r6ivj3zzgg6l5h7dwlsn2vymsnd"))))
5880 (build-system pyproject-build-system)
5881 (arguments
5882 (list
5883 ;; tests: 17 failed, 1368 passed, 75 skipped, 3 deselected, 542 warnings
5884 #:test-flags
5885 #~(list "-k" (string-append
5886 ;; These two tests (out of more than 1000 tests) fail
5887 ;; because of accuracy problems.
5888 "not test_softmax_classification_batch_multi_target"
5889 " and not test_softmax_classification_batch_zero_baseline"
5890 ;; This test fails with PyTorch 2.7.0 due to stricter
5891 ;; torch.load weights_only behavior.
5892 " and not test_exp_sets_with_diffent_lengths")
5893 "tests")))
5894 (native-inputs
5895 (list python-flask
5896 python-pytest
5897 python-flask-compress
5898 python-parameterized
5899 python-scikit-learn
5900 python-setuptools))
5901 (propagated-inputs
5902 (list python-matplotlib
5903 python-numpy
5904 python-pytorch
5905 python-tqdm
5906 ;; [optional]
5907 python-openai))
5908 (home-page "https://captum.ai")
5909 (synopsis "Model interpretability for PyTorch")
5910 (description "Captum is a model interpretability and understanding library
5911for PyTorch. Captum contains general purpose implementations of integrated
5912gradients, saliency maps, smoothgrad, vargrad and others for PyTorch models.
5913It has quick integration for models built with domain-specific libraries such
5914as torchvision, torchtext, and others.")
5915 (license license:bsd-3)))
5916
5917(define-public python-readchar
5918 (package
5919 (name "python-readchar")
5920 (version "4.2.2")
5921 (source
5922 (origin
5923 (method git-fetch)
5924 (uri (git-reference
5925 (url "https://github.com/magmax/python-readchar/")
5926 (commit (string-append "v" version))))
5927 (file-name (git-file-name name version))
5928 (sha256
5929 (base32 "1m5knal63lg1pmhkkkcpvz1vq6k5rpar4yvq1rafc4q47m2cfaaq"))))
5930 (build-system pyproject-build-system)
5931 (native-inputs
5932 (list python-pytest python-setuptools))
5933 (home-page "https://github.com/magmax/python-readchar")
5934 (synopsis "Library to easily read single chars and key strokes")
5935 (description "This package provides a Python library to easily read single
5936characters and key strokes.")
5937 (license license:expat)))
5938
5939(define-public python-inquirer
5940 (package
5941 (name "python-inquirer")
5942 (version "3.4.1")
5943 ;; Pypi has no tests.
5944 (source (origin
5945 (method git-fetch)
5946 (uri (git-reference
5947 (url "https://github.com/magmax/python-inquirer")
5948 (commit (string-append "v" version))))
5949 (file-name (git-file-name name version))
5950 (sha256
5951 (base32
5952 "10ncdjz0z09m9piqxyk3yxqk1rd9icij46a9djqj7rwdj5sfclf5"))))
5953 (build-system pyproject-build-system)
5954 (propagated-inputs
5955 (list python-blessed python-editor python-readchar))
5956 (native-inputs
5957 (list python-poetry-core python-pexpect python-pytest))
5958 (home-page "https://github.com/magmax/python-inquirer")
5959 (synopsis "Collection of common interactive command line user interfaces")
5960 (description
5961 "Inquirer should ease the process of asking end user questions, parsing,
5962validating answers, managing hierarchical prompts and providing error
5963feedback.")
5964 (license license:expat)))
5965
5966(define-public python-pytorch-lightning
5967 (package
5968 (name "python-pytorch-lightning")
5969 (version "2.6.0")
5970 (source (origin
5971 (method git-fetch)
5972 (uri (git-reference
5973 (url "https://github.com/Lightning-AI/pytorch-lightning")
5974 (commit version)))
5975 (file-name (git-file-name name version))
5976 (sha256
5977 (base32
5978 "0fqzjs3k55n2sp1kz8wxf82687d1vq0yydv45qx2vl3kzgvl0qff"))))
5979 (build-system pyproject-build-system)
5980 (arguments
5981 (list
5982 #:test-flags
5983 ;; The tests train a model. They are much too expensive for our
5984 ;; purposes, so we only run the core tests.
5985 '(list "-m" "not cloud and not tpu"
5986 "tests/tests_pytorch/core"
5987 "-k"
5988 (string-append
5989 ;; Some multiprocessing complaint.
5990 "not test_result_reduce_ddp"
5991 ;; FutureWarning is raised.
5992 " and not test_result_collection_restoration"
5993 ;; These need tensorboard
5994 " and not test_property_logger"
5995 " and not test_property_loggers"))
5996 #:phases
5997 '(modify-phases %standard-phases
5998 (add-after 'unpack 'patch-version-detection
5999 (lambda _
6000 ;; We do have pytorch 2.4.0, but the version comparison fails.
6001 (substitute* "src/lightning/fabric/utilities/imports.py"
6002 (("_TORCH_GREATER_EQUAL_2_4 =.*")
6003 "_TORCH_GREATER_EQUAL_2_4 = True\n"))))
6004 (add-after 'patch-version-detection 'fix-leafspec-deprecation
6005 (lambda _
6006 ;; `LeafSpec' is deprecated starting with PyTorch 2.10.
6007 (substitute* "src/lightning/pytorch/utilities/_pytree.py"
6008 (("SUPPORTED_NODES, LeafSpec, PyTree, TreeSpec, _get_node_type, tree_unflatten")
6009 "SUPPORTED_NODES, PyTree, TreeSpec, _get_node_type, tree_unflatten, treespec_leaf")
6010 (("LeafSpec\\(\\)") "treespec_leaf()"))))
6011 (add-before 'build 'pre-build
6012 (lambda _ (setenv "PACKAGE_NAME" "lightning")))
6013 (add-after 'install 'pre-build-pytorch
6014 (lambda _
6015 ;; pyproject-build-system only tolerates unicycles.
6016 (for-each delete-file (find-files "dist" "\\.whl"))
6017 (setenv "PACKAGE_NAME" "pytorch")))
6018 (add-after 'pre-build-pytorch 'build-pytorch
6019 (assoc-ref %standard-phases 'build))
6020 (add-after 'build-pytorch 'install-pytorch
6021 (assoc-ref %standard-phases 'install))
6022 (add-before 'check 'pre-check
6023 (lambda _
6024 ;; We don't have Tensorboard
6025 (substitute* "tests/tests_pytorch/test_cli.py"
6026 ((" TensorBoardLogger\\(\".\"\\)") "")))))))
6027 (propagated-inputs
6028 (list python-arrow
6029 python-beautifulsoup4
6030 python-croniter
6031 python-dateutils
6032 python-deepdiff
6033 python-fastapi
6034 python-fsspec
6035 python-inquirer
6036 python-jsonargparse
6037 python-lightning-cloud
6038 python-lightning-utilities
6039 python-numpy
6040 python-packaging
6041 python-pytorch
6042 python-pyyaml
6043 python-torchmetrics
6044 python-torchvision
6045 python-tqdm
6046 python-traitlets
6047 python-typing-extensions))
6048 (native-inputs
6049 (list python-aiohttp
6050 python-cloudpickle
6051 python-flaky
6052 python-pympler
6053 python-pytest
6054 python-psutil
6055 python-requests-mock
6056 python-scikit-learn
6057 python-setuptools))
6058 (home-page "https://lightning.ai/")
6059 (synopsis "Deep learning framework to train, deploy, and ship AI products")
6060 (description
6061 "PyTorch Lightning is just organized PyTorch; Lightning disentangles
6062PyTorch code to decouple the science from the engineering.")
6063 (license license:asl2.0)))
6064
6065(define-public python-torchmetrics
6066 (package
6067 (name "python-torchmetrics")
6068 (version "1.9.0")
6069 (source (origin
6070 (method git-fetch)
6071 (uri (git-reference
6072 (url "https://github.com/Lightning-AI/torchmetrics")
6073 (commit (string-append "v" version))))
6074 (file-name (git-file-name name version))
6075 (sha256
6076 (base32
6077 "076x59493wym57lrvmlk8xsbfhgs4rlcw4gx3bxlv55ldd0ijllf"))))
6078 (build-system pyproject-build-system)
6079 (arguments
6080 (list
6081 ;; Tests require many additional dependencies
6082 #:tests? #f))
6083 (propagated-inputs
6084 (list python-numpy python-packaging python-pytorch
6085 python-typing-extensions
6086 python-lightning-utilities))
6087 (native-inputs
6088 (list python-cloudpickle
6089 python-fire
6090 python-mir-eval
6091 python-pandas
6092 python-psutil
6093 python-pytest
6094 python-pytest-doctestplus
6095 python-pytest-rerunfailures
6096 python-pytest-timeout
6097 python-requests
6098 python-scikit-image
6099 python-scikit-learn
6100 python-scipy
6101 python-types-protobuf
6102 python-types-setuptools))
6103 (home-page "https://github.com/Lightning-AI/torchmetrics")
6104 (synopsis "Machine learning metrics for PyTorch applications")
6105 (description "TorchMetrics is a collection of 100+ PyTorch metrics
6106implementations and an easy-to-use API to create custom metrics. It offers:
6107
6108@itemize
6109@item A standardized interface to increase reproducibility
6110@item Reduces boilerplate
6111@item Automatic accumulation over batches
6112@item Metrics optimized for distributed-training
6113@item Automatic synchronization between multiple devices
6114@end itemize
6115")
6116 (license license:asl2.0)))
6117
6118;; Keep this in sync with python-pytorch
6119(define-public python-torchvision
6120 (package
6121 (name "python-torchvision")
6122 (version "0.25.0")
6123 (source (origin
6124 (method git-fetch)
6125 (uri (git-reference
6126 (url "https://github.com/pytorch/vision")
6127 (commit (string-append "v" version))
6128 (recursive? #t)))
6129 (file-name (git-file-name name version))
6130 (sha256
6131 (base32
6132 "0bikvjiqgl659vjk1pw7hka95g55h5sgh3lmybwqfkzsqhfljjx2"))
6133 (modules '((guix build utils)))
6134 (snippet
6135 '(begin
6136 (delete-file-recursively "android")
6137 (delete-file-recursively "ios")))))
6138 (build-system pyproject-build-system)
6139 (arguments
6140 (list
6141 ;; The test suite is expensive and there is no easy way to subset it.
6142 #:tests? #f
6143 #:phases
6144 #~(modify-phases %standard-phases
6145 (add-after 'unpack 'setenv
6146 (lambda _
6147 (let ((jpegdir #$(this-package-input "libjpeg-turbo")))
6148 (setenv "TORCHVISION_INCLUDE"
6149 (string-append jpegdir "/include/"))
6150 (setenv "TORCHVISION_LIBRARY"
6151 (string-append jpegdir "/lib/"))))))))
6152 (inputs
6153 (list ffmpeg-6
6154 libpng
6155 libjpeg-turbo))
6156 (propagated-inputs
6157 (list python-numpy
6158 python-typing-extensions
6159 python-requests
6160 python-pillow
6161 python-pytorch))
6162 (native-inputs
6163 (list pybind11-2
6164 python-pytest
6165 python-setuptools
6166 python-wheel
6167 which))
6168 (home-page "https://pytorch.org/vision/stable/index.html")
6169 (synopsis "Datasets, transforms and models specific to computer vision")
6170 (description
6171 "The torchvision package consists of popular datasets, model architectures,
6172and common image transformations for computer vision.")
6173 (license license:bsd-3)))
6174
6175(define-public python-torchfile
6176 ;; Latest release is nine years old.
6177 (let ((commit "fbd434a5b5562c88b91a95e6476e11dbb7735436")
6178 (revision "0"))
6179 (package
6180 (name "python-torchfile")
6181 (version (git-version "0.1.0" revision commit))
6182 (source
6183 (origin
6184 (method git-fetch)
6185 (uri (git-reference
6186 (url "https://github.com/bshillingford/python-torchfile/")
6187 (commit commit)))
6188 (file-name (git-file-name name version))
6189 (sha256
6190 (base32 "1f03ks5n3i3cdh16wx5ysxsxh0ai9vpf0k5pdx759vf31f4niz36"))))
6191 (build-system pyproject-build-system)
6192 (arguments
6193 (list
6194 #:phases
6195 #~(modify-phases %standard-phases
6196 (replace 'check
6197 (lambda* (#:key tests? #:allow-other-keys)
6198 (when tests?
6199 (invoke "python3" "tests.py")))))))
6200 (propagated-inputs
6201 (list python-numpy python-setuptools))
6202 (home-page "https://github.com/bshillingford/python-torchfile")
6203 (synopsis "Torch7 binary serialized file parser")
6204 (description "This package enables you to deserialize Lua
6205torch-serialized objects from Python.")
6206 (license license:bsd-3))))
6207
6208(define-public python-geomloss
6209 (package
6210 (name "python-geomloss")
6211 (version "0.3.1")
6212 (source
6213 (origin
6214 (method git-fetch)
6215 (uri (git-reference
6216 (url "https://github.com/jeanfeydy/geomloss")
6217 (commit (string-append "v" version))))
6218 (file-name (git-file-name name version))
6219 (sha256
6220 (base32 "0sx851d54iagvfmdlpwh4559hms4gr2kabsirbd4ib2m7118p7jb"))))
6221 (build-system pyproject-build-system)
6222 ;; There are no automated tests.
6223 (arguments (list #:tests? #false))
6224 (propagated-inputs (list python-numpy python-pytorch))
6225 (native-inputs (list python-setuptools))
6226 (home-page "https://www.kernel-operations.io/geomloss/")
6227 (synopsis
6228 "Geometric loss functions between point clouds, images and volumes")
6229 (description
6230 "The GeomLoss library provides efficient GPU implementations for:
6231
6232@itemize
6233@item Kernel norms (also known as Maximum Mean Discrepancies).
6234@item Hausdorff divergences, which are positive definite generalizations of
6235the Chamfer-ICP loss and are analogous to log-likelihoods of Gaussian Mixture
6236Models.
6237@item Debiased Sinkhorn divergences, which are affordable yet positive and
6238definite approximations of Optimal Transport (Wasserstein) distances.
6239@end itemize")
6240 (license license:expat)))
6241
6242(define-public python-tokenizers
6243 (package
6244 (name "python-tokenizers")
6245 (version "0.22.2")
6246 (source
6247 (origin
6248 (method git-fetch)
6249 (uri (git-reference
6250 (url "https://github.com/huggingface/tokenizers/")
6251 (commit (string-append "v" version))))
6252 (file-name (git-file-name name version))
6253 (sha256
6254 (base32 "0mcivkmhdpqg872yvp77505apaylml808lbq2i3i5pln2rhgf1jw"))
6255 (modules '((guix build utils)
6256 (ice-9 ftw)))
6257 (snippet
6258 #~(begin ;; Only keeping bindings.
6259 (for-each (lambda (file)
6260 (unless (member file
6261 '("." ".." "bindings" "tokenizers"))
6262 (delete-file-recursively file)))
6263 (scandir "."))
6264 (delete-file-recursively "bindings/node")
6265 (delete-file "bindings/python/Cargo.lock")))))
6266 (build-system pyproject-build-system)
6267 (arguments
6268 (list
6269 #:imported-modules (append %cargo-build-system-modules
6270 %pyproject-build-system-modules)
6271 #:modules '(((guix build cargo-build-system) #:prefix cargo:)
6272 (guix build pyproject-build-system)
6273 (guix build utils))
6274 #:test-flags
6275 #~(list
6276 "--ignore=benches"
6277 ;; This test requires the python-datasets package.
6278 "--ignore=tests/documentation/test_tutorial_train_from_iterators.py"
6279 ;; XXX: Tests below fail because they require a network connection.
6280 ;; "-m" "not network" is respected from version 0.23 onwards
6281 ;; and makes the flags below unecessary.
6282 "-k" (string-join
6283 (list "not TestEncoding"
6284 "TestBPE"
6285 "TestWordLevel"
6286 "TestByteLevelProcessing"
6287 "TestAsyncTokenizer"
6288 "TestUnigram"
6289 "TestPipeline"
6290 "TestCharBPETokenizer"
6291 "TestSerialization"
6292 "TestByteLevelBPE"
6293 "TestBertWordPieceTokenizer"
6294 "TestQuicktour"
6295 "test_encode_formats"
6296 "test_encode_add_special_tokens"
6297 "test_decode_stream_fallback"
6298 "test_decode_skip_special_tokens"
6299 "test_from_pretrained"
6300 "test_from_pretrained_revision"
6301 "test_encode_special_tokens"
6302 "test_instantiate"
6303 "test_splitting")
6304 " and not "))
6305 #:phases
6306 #~(modify-phases %standard-phases
6307 (add-after 'unpack 'prepare-cargo-build-system
6308 (lambda args
6309 (for-each (lambda (phase)
6310 (format #t "Running cargo phase: ~a~%" phase)
6311 (apply (assoc-ref cargo:%standard-phases phase)
6312 #:cargo-target #$(cargo-triplet)
6313 args))
6314 '(prepare-rust-crates
6315 unpack-rust-crates
6316 configure
6317 check-for-pregenerated-files
6318 patch-cargo-checksums))))
6319 (add-after 'prepare-cargo-build-system 'chdir
6320 (lambda _
6321 (chdir "bindings/python"))))))
6322 (native-inputs
6323 (append (list python-httpx
6324 python-huggingface-hub
6325 python-numpy
6326 python-pytest
6327 python-pytest-asyncio
6328 python-pytest-timeout
6329 python-requests
6330 python-tqdm)
6331 (list maturin
6332 nss-certs-for-test
6333 pkg-config
6334 rust
6335 `(,rust "cargo"))
6336 (or (and=> (%current-target-system)
6337 (compose list make-rust-sysroot))
6338 '())))
6339 (inputs
6340 (cons oniguruma (cargo-inputs 'tokenizers-python)))
6341 (home-page "https://huggingface.co/docs/tokenizers")
6342 (synopsis "Implementation of various popular tokenizers")
6343 (description
6344 "This package provides an implementation of today’s most used tokenizers,
6345with a focus on performance and versatility.")
6346 (license license:asl2.0)))
6347
6348(define-public python-transformers
6349 (package
6350 (name "python-transformers")
6351 (version "4.57.6")
6352 (source
6353 (origin
6354 (method url-fetch)
6355 (uri (pypi-uri "transformers" version))
6356 (sha256
6357 (base32 "1lw90svznnmbp48acf33fvr6wbjp5d4ybdr12llhmp79xhk43r2m"))))
6358 (build-system pyproject-build-system)
6359 (arguments
6360 ;; Missing inputs.
6361 (list #:test-flags
6362 '(list "--ignore=tests/test_modeling_tf_common.py"
6363 "--ignore=tests/test_modeling_common.py" ; ImportError
6364 "--ignore=tests/test_processing_common.py" ; ImportError
6365 "--ignore=tests/test_configuration_common.py"
6366 "--ignore=tests/test_pipeline_mixin.py"
6367 "--ignore=tests/test_sequence_feature_extraction_common.py"
6368 "--ignore=tests/test_tokenization_mistral_common.py"
6369 ;; Requires python-accelerate
6370 "--ignore=tests/test_training_args.py"
6371 ;; Requires network access
6372 "--ignore=tests/test_executorch.py")))
6373 ;; The imported package contains ~60 more inputs, but they don't seem
6374 ;; necessary to build a minimal version of the package.
6375 (propagated-inputs
6376 (list python-filelock
6377 python-huggingface-hub
6378 python-numpy
6379 python-packaging
6380 python-pytorch
6381 python-pyyaml
6382 python-regex
6383 python-requests
6384 python-safetensors
6385 python-tokenizers
6386 python-tqdm))
6387 (native-inputs
6388 (list python-parameterized
6389 python-pytest
6390 python-pytest-asyncio
6391 python-setuptools))
6392 (home-page "https://github.com/huggingface/transformers")
6393 (synopsis "Machine Learning for PyTorch and TensorFlow")
6394 (description
6395 "This package provides easy download of thousands of pretrained models to
6396perform tasks on different modalities such as text, vision, and audio.
6397
6398These models can be applied on:
6399@itemize
6400@item Text, for tasks like text classification, information extraction,
6401question answering, summarization, translation, and text generation, in over
6402100 languages.
6403@item Images, for tasks like image classification, object detection, and
6404segmentation.
6405@item Audio, for tasks like speech recognition and audio classification.
6406@end itemize
6407
6408Transformer models can also perform tasks on several modalities combined, such
6409as table question answering, optical character recognition, information
6410extraction from scanned documents, video classification, and visual question
6411answering.
6412
6413This package provides APIs to quickly download and use those pretrained models
6414on a given text, fine-tune them on your own datasets and then share them with
6415the community. At the same time, each Python module defining an architecture
6416is fully standalone and can be modified to enable quick research experiments.
6417
6418Transformers is backed by the three most popular deep learning libraries —
6419Jax, PyTorch and TensorFlow — with a seamless integration between them.")
6420 (license license:asl2.0)))
6421
6422(define-public ctranslate2
6423 (package
6424 (name "ctranslate2")
6425 (version "4.8.0")
6426 (source
6427 (origin
6428 (method git-fetch)
6429 (uri (git-reference
6430 (url "https://github.com/OpenNMT/CTranslate2")
6431 (commit (string-append "v" version))))
6432 (file-name (git-file-name "CTranslate2" version))
6433 (sha256 (base32 "0lpykbp9jvkds2dy3lfyn699d0kvz9kzqzfzg4vh5cgn99d7k4g2"))
6434 (patches (search-patches "ctranslate2-local-build.patch"))))
6435 (build-system cmake-build-system)
6436 (arguments
6437 (list
6438 ;; XXX: mkl and openblas seem incompatible.
6439 #:configure-flags #~(list "-DBUILD_TESTS=ON"
6440 "-DWITH_ACCELERATE=OFF"
6441 "-DWITH_RUY=OFF"
6442 "-DWITH_DNNL=ON"
6443 "-DWITH_CUDA=OFF"
6444 "-DWITH_CUDNN=OFF"
6445 "-DWITH_MKL=OFF"
6446 "-DWITH_OPENBLAS=ON")
6447 #:modules '((guix build cmake-build-system)
6448 ((guix build gnu-build-system) #:prefix gnu:)
6449 (guix build utils))
6450 #:phases
6451 #~(modify-phases %standard-phases
6452 (replace 'check
6453 (lambda* (#:rest args)
6454 (apply (assoc-ref gnu:%standard-phases 'check)
6455 #:test-target "ctranslate2_test" args))))))
6456 (native-inputs (list libomp-13
6457 cxxopts
6458 spdlog
6459 googletest
6460 cpu-features
6461 onednn
6462 openblas))
6463 (home-page "https://opennmt.net/CTranslate2/")
6464 (synopsis "Fast inference engine for Transformer models")
6465 (description "CTranslate2 is a C++ and Python library for efficient
6466inference with Transformer models.
6467
6468The project implements a custom runtime that applies many performance
6469optimization techniques such as weights quantization, layers fusion, batch
6470reordering, etc., to accelerate and reduce the memory usage of Transformer
6471models on CPU and GPU.")
6472 (license license:expat)))
6473
6474(define-public python-ctranslate2
6475 (package/inherit ctranslate2
6476 (name "python-ctranslate2")
6477 (build-system pyproject-build-system)
6478 (arguments
6479 (list
6480 ;; XXX: tests require the eole python project.
6481 #:tests? #f
6482 #:phases
6483 #~(modify-phases %standard-phases
6484 (add-before 'build 'cd-to-build-dir
6485 (lambda _
6486 (chdir "python"))))))
6487 (native-inputs (list ctranslate2
6488 python-setuptools
6489 python-wheel
6490 pybind11
6491 python-pyyaml
6492 python-numpy))))
6493
6494(define-public python-xx-sent-ud-sm
6495 ;; For Argos Translate CLI tool
6496 (hidden-package
6497 (package
6498 (name "python-xx-sent-ud-sm")
6499 (version "3.8.0")
6500 (source
6501 (origin
6502 (method url-fetch)
6503 (uri (string-append "https://github.com/explosion/spacy-models"
6504 "/releases/download/xx_sent_ud_sm-3.8.0"
6505 "/xx_sent_ud_sm-" version ".tar.gz"))
6506 (sha256
6507 (base32 "1pwyl23nvmmkpvq5wgafdqq0mlnq14l2svh9m6gi6w0skv7dd5fq"))))
6508 (build-system pyproject-build-system)
6509 (arguments '(#:tests? #f)) ;no test
6510 (native-inputs (list python-setuptools))
6511 (propagated-inputs (list python-spacy))
6512 (home-page "https://spacy.io/models/xx#xx_sent_ud_sm")
6513 (synopsis "Small multi-language sentence boundary model for spaCy")
6514 (description "@code{xx_sent_ud_sm} is a spaCy model optimized for CPU.
6515It includes a sentence boundary component of a relatively small size.")
6516 (license license:cc-by-sa3.0))))
6517
6518(define-public python-argostranslate
6519 (package
6520 (name "python-argostranslate")
6521 (version "1.10.0")
6522 (source
6523 (origin
6524 (method git-fetch)
6525 (uri (git-reference
6526 (url "https://github.com/argosopentech/argos-translate")
6527 (commit (string-append "v" version))))
6528 (file-name (git-file-name name version))
6529 (sha256
6530 (base32 "18fhqabdyh66ymri9xi9xc3q619f5bd3yb9izwhvwyladx65xcfn"))))
6531 (arguments
6532 (list
6533 #:phases
6534 #~(modify-phases %standard-phases
6535 (add-after 'unpack 'disable-spacy-download
6536 (lambda _
6537 (substitute* "argostranslate/networking.py"
6538 ((".*spacy_download.*") ""))))
6539 (add-before 'build 'set-home-env
6540 (lambda _
6541 (setenv "HOME" "/tmp"))))))
6542 (build-system pyproject-build-system)
6543 (native-inputs (list python-pytest python-setuptools))
6544 (propagated-inputs (list python-ctranslate2
6545 python-packaging
6546 python-sacremoses
6547 python-sentencepiece
6548 python-spacy
6549 python-stanza
6550 python-xx-sent-ud-sm))
6551 (home-page "https://www.argosopentech.com")
6552 (synopsis "Offline translation library and CLI tool")
6553 (description
6554 "Argos Translate uses OpenNMT for translations and can be used
6555as either a Python library, command-line, or GUI application.
6556It supports installing language model packages which are ZIP archives
6557with a @code{.argosmodel} extension. This package provides
6558the Python library and the command-line program.")
6559 (license license:expat)))
6560
6561(define-public argos-translate-gui
6562 ;; The Git repository is not tagged.
6563 (let ((commit "06aafde3faf1709080471c94914382a566f6f775")
6564 (revision "0"))
6565 (package
6566 (name "argos-translate-gui")
6567 (version (git-version "1.6.5" revision commit))
6568 (source
6569 (origin
6570 (method git-fetch)
6571 (uri (git-reference
6572 (url "https://github.com/argosopentech/argos-translate-gui")
6573 (commit commit)))
6574 (file-name (git-file-name name version))
6575 (sha256
6576 (base32 "0g251fgwwbk96f8n11c8gzidqgfkrkwpldxk9zq0kkhm729b9yyw"))))
6577 (build-system pyproject-build-system)
6578 (arguments '(#:tests? #f)) ;no test
6579 (native-inputs (list python-setuptools))
6580 (inputs (list python-argostranslate python-pyqt))
6581 (home-page "https://www.argosopentech.com")
6582 (synopsis "Graphical user interface for Argos Translate")
6583 (description
6584 "Argos Translate uses OpenNMT for translations and can be used
6585as either a Python library, command-line, or GUI application.
6586It supports installing language model packages which are ZIP archives
6587with a @code{.argosmodel} extension. This package provides
6588a Qt interface for Argos Translate.")
6589 (license license:expat))))
6590
6591(define-public python-argos-translate-files
6592 (package
6593 (name "python-argos-translate-files")
6594 (version "1.4.3")
6595 (source
6596 (origin
6597 (method git-fetch)
6598 (uri (git-reference
6599 (url "https://github.com/LibreTranslate/argos-translate-files")
6600 (commit (string-append "v" version))))
6601 (file-name (git-file-name name version))
6602 (sha256
6603 (base32 "1vz5v2gnd5wxwq6cjnhrvhflndl55c7ffy21w05m8sy3ll8iaiij"))))
6604 (build-system pyproject-build-system)
6605 (arguments (list #:phases #~(modify-phases %standard-phases
6606 (add-after 'unpack 'unpin-dependencies
6607 (lambda _
6608 (substitute* "requirements.txt"
6609 (("argos-translate-lt.*")
6610 "argostranslate\n"))))
6611 (add-before 'build 'set-home-env
6612 (lambda _
6613 (setenv "HOME" "/tmp"))))))
6614 (propagated-inputs (list python-argostranslate
6615 python-beautifulsoup4
6616 python-lxml
6617 python-pymupdf
6618 python-pysrt))
6619 (native-inputs (list python-pytest python-setuptools))
6620 (home-page "https://github.com/LibreTranslate/argos-translate-files")
6621 (synopsis "Translate files with Argos Translate")
6622 (description "This package provides a Python library
6623for translating plain- and rich-text documents with Argos Translate.")
6624 (license license:agpl3)))
6625
6626(define-public libretranslate
6627 (package
6628 (name "libretranslate")
6629 (version "1.9.6")
6630 (source
6631 (origin
6632 (method git-fetch)
6633 (uri (git-reference
6634 (url "https://github.com/LibreTranslate/LibreTranslate")
6635 (commit (string-append "v" version))))
6636 (file-name (git-file-name name version))
6637 (sha256 (base32 "0gyhahlyz06nr7h8nb7nrw866z44kw6kaijczk6jk8wn3p1xp200"))
6638 (patches (search-patches "libretranslate-use-flasgger.patch"))))
6639 (build-system pyproject-build-system)
6640 (arguments
6641 (list
6642 #:tests? #f ;all tests depend on Argos models
6643 #:phases
6644 #~(modify-phases %standard-phases
6645 (add-after 'unpack 'unpin-dependencies
6646 (lambda _
6647 (substitute* "pyproject.toml"
6648 ;; Unpin numpy for transitive dependencies.
6649 (("^ \"numpy .+") "")
6650 ;; Unpin dependencies.
6651 (("^( \"[[:alnum:]-]+) ==.+((;.+)?\",)" all left right)
6652 (string-append left right))
6653 (("argos-translate-lt") "argostranslate"))))
6654 (add-before 'build 'set-home-env
6655 (lambda _
6656 (setenv "HOME" "/tmp"))))))
6657 (inputs (list python-apscheduler
6658 python-argos-translate-files
6659 python-argostranslate
6660 python-expiringdict
6661 python-flasgger
6662 python-flask
6663 python-flask-babel
6664 python-flask-limiter
6665 python-itsdangerous
6666 python-langdetect
6667 python-lexilang
6668 python-minisbd
6669 python-numpy
6670 python-packaging
6671 python-polib
6672 python-prometheus-client
6673 python-redis
6674 python-requests
6675 python-waitress
6676 python-werkzeug))
6677 (native-inputs (list python-hatchling))
6678 (home-page "https://docs.libretranslate.com")
6679 (synopsis "Machine translation API and web interface")
6680 (description
6681 "LibreTranslate is a machine translation API and web interface,
6682powered by the Argos Translate library.")
6683 (license license:agpl3)))
6684
6685(define-public python-hmmlearn
6686 (package
6687 (name "python-hmmlearn")
6688 (version "0.3.3")
6689 (source
6690 (origin
6691 (method git-fetch)
6692 (uri (git-reference
6693 (url "https://github.com/hmmlearn/hmmlearn")
6694 (commit version)))
6695 (file-name (git-file-name name version))
6696 (sha256
6697 (base32 "1d1gcw2xb1i7zvkcz2vmrk4c2iqsfy71pgrc0r5p65r51w9p97n1"))))
6698 (build-system pyproject-build-system)
6699 (arguments
6700 (list
6701 #:test-flags
6702 #~(list "--pyargs" "hmmlearn")
6703 #:phases
6704 #~(modify-phases %standard-phases
6705 (add-after 'unpack 'set-core-count
6706 (lambda _
6707 ;; "Could not find the number of physical cores", so we tell it
6708 ;; how many cores to use.
6709 (setenv "LOKY_MAX_CPU_COUNT" "1"))))))
6710 (native-inputs
6711 (list pybind11
6712 python-pytest
6713 python-setuptools
6714 python-setuptools-scm
6715 util-linux)) ;for lscpu
6716 (propagated-inputs
6717 (list python-numpy
6718 python-scikit-learn
6719 python-scipy))
6720 (home-page "https://github.com/hmmlearn/hmmlearn")
6721 (synopsis "Hidden Markov Models with scikit-learn like API")
6722 (description
6723 "Hmmlearn is a set of algorithms for unsupervised learning and inference
6724of Hidden Markov Models.")
6725 (license license:bsd-3)))
6726
6727(define-public llm-proxy
6728 (package
6729 (name "llm-proxy")
6730 (version "0.23.0")
6731 (source
6732 (origin
6733 (method git-fetch)
6734 (uri (git-reference
6735 (url "https://codeberg.org/jbousquie/llm-proxy")
6736 (commit (string-append "v" version))))
6737 (file-name (git-file-name name version))
6738 (sha256
6739 (base32 "125lfhx28fs8s3fzhcqbs87b7crswn9x0br3dnv6qnbybrg0bacd"))))
6740 (build-system cargo-build-system)
6741 (arguments (list #:install-source? #f))
6742 (inputs (cargo-inputs 'llm-proxy))
6743 (home-page "https://jbousquie.codeberg.page/llm-proxy/")
6744 (synopsis "Network proxy for LLM API vendors")
6745 (native-inputs (list nss-certs-for-test))
6746 (description
6747 "This package provides a local HTTP proxy written in Rust. It sits
6748between agentic clients and the Albert API (Etalab).")
6749 (license license:etalab2.0)))
6750
6751;; Keep this in sync with the r-torch package.
6752(define-public liblantern
6753 (package
6754 (name "liblantern")
6755 (version "0.16.3")
6756 (source
6757 (origin
6758 (method git-fetch)
6759 (uri (git-reference
6760 (url "https://github.com/mlverse/torch")
6761 (commit (string-append "v" version))))
6762 (file-name (git-file-name name version))
6763 (sha256
6764 (base32 "13gdrj9aklqgfx10jyylr3jh2ilk8j27fzgv708yv9jn2ckmfdhn"))))
6765 (build-system cmake-build-system)
6766 (arguments
6767 (list
6768 #:tests? #false ;no test target
6769 #:phases
6770 (let ((python-version (version-major+minor (package-version python))))
6771 #~(modify-phases %standard-phases
6772 (add-after 'unpack 'chdir
6773 (lambda _ (chdir "src/lantern")))
6774 (add-after 'chdir 'do-not-download-binaries
6775 (lambda* (#:key inputs #:allow-other-keys)
6776 (substitute* "CMakeLists.txt"
6777 (("find_package\\(Torch.*") "set(TORCH_CXX_FLAGS \"-ltorch\")\n")
6778 (("retrieve_lib\\(.*") ""))
6779 (let ((site-packages (string-append "/lib/python"
6780 #$python-version
6781 "/site-packages")))
6782 (setenv "LIBRARY_PATH"
6783 (string-append
6784 (search-input-directory
6785 inputs (string-append site-packages "/torch/lib"))
6786 ":" (or (getenv "LIBRARY_PATH") "")))
6787 (setenv "CPLUS_INCLUDE_PATH"
6788 (string-append
6789 (search-input-directory
6790 inputs (string-append
6791 site-packages "/torch/include/torch/csrc/api/include/"))
6792 ":"
6793 (search-input-directory
6794 inputs (string-append site-packages "/torch/include/"))
6795 ":"
6796 (or (getenv "CPLUS_INCLUDE_PATH") "")))
6797 (setenv "C_INCLUDE_PATH"
6798 (string-append
6799 (search-input-directory
6800 inputs (string-append site-packages "/torch/include/"))
6801 ":"
6802 (or (getenv "C_INCLUDE_PATH") ""))))))
6803 (replace 'install
6804 (lambda _
6805 (install-file
6806 "../build/liblantern.so"
6807 (string-append #$output "/lib"))
6808 (copy-recursively
6809 "../lantern/include"
6810 (string-append #$output "/include"))))))))
6811 (inputs (list python-pytorch-for-r-torch))
6812 (home-page "https://github.com/mlverse/torch/")
6813 (synopsis "C API to libtorch")
6814 (description
6815 "Lantern provides a C API to the libtorch machine learning library.")
6816 (license license:expat)))
6817
6818(define-public python-lap
6819 (package
6820 (name "python-lap")
6821 (version "0.5.12")
6822 (source (origin
6823 (method url-fetch)
6824 (uri (pypi-uri "lap" version))
6825 (sha256
6826 (base32
6827 "1za4mf5nd7vzwd24sy2mfxrk8mnwq7d8rv6h96yh8v5flx7422sp"))))
6828 (build-system pyproject-build-system)
6829 (arguments
6830 (list
6831 #:test-flags #~(list "-v" #$output)
6832 #:phases
6833 #~(modify-phases %standard-phases
6834 (add-after 'check 'check-cleanup
6835 (lambda* (#:key tests? #:allow-other-keys)
6836 (when tests?
6837 (for-each
6838 delete-file-recursively
6839 (find-files #$output
6840 (lambda (file stat)
6841 (or (member (basename file)
6842 '("tests" ".pytest_cache"))))
6843 #:directories? #t))))))))
6844 (propagated-inputs
6845 (list python-numpy))
6846 (native-inputs
6847 (list python-cython python-pytest python-setuptools python-wheel))
6848 (home-page "https://github.com/gatagat/lap")
6849 (synopsis "Linear Assignment Problem solver (LAPJV/LAPMOD)")
6850 (description "Lap is a linear assignment problem solver using Jonker-Volgenant
6851algorithm for dense (LAPJV) or sparse (LAPMOD) matrices.")
6852 (license license:bsd-2)))
6853
6854(define-public python-visdom
6855 (package
6856 (name "python-visdom")
6857 (version "0.2.4")
6858 (source
6859 (origin
6860 (method url-fetch)
6861 (uri (pypi-uri "visdom" version))
6862 (sha256
6863 (base32 "0x05faxh45bh1zz8afjhzjy49jrqv4dkhaw1ainhajl1r39i3ac4"))))
6864 (build-system pyproject-build-system)
6865 (arguments (list #:tests? #f)) ;tests require launching the server
6866 (native-inputs
6867 (list python-setuptools))
6868 (propagated-inputs
6869 (list python-jsonpatch
6870 python-networkx
6871 python-numpy
6872 python-pillow
6873 python-requests
6874 python-scipy
6875 python-six
6876 python-tornado
6877 python-websocket-client))
6878 (home-page "https://github.com/fossasia/visdom")
6879 (synopsis "Visualizations of live, rich data for Torch and Numpy")
6880 (description
6881 "This package provides a tool for visualizing live, rich data for Torch
6882and Numpy.")
6883 (license license:asl2.0)))
6884
6885(define-public python-pyro-api
6886 (package
6887 (name "python-pyro-api")
6888 (version "0.1.2")
6889 (source
6890 (origin
6891 (method git-fetch)
6892 (uri (git-reference
6893 (url "https://github.com/pyro-ppl/pyro-api")
6894 (commit version)))
6895 (file-name (git-file-name name version))
6896 (sha256
6897 (base32 "17x7niagx43cajqq67dxmssr7q94db6axyg154y7vqdxzp25hf7g"))))
6898 (build-system pyproject-build-system)
6899 (arguments '(#:tests? #false)) ;requires pyro
6900 (native-inputs
6901 (list python-ipython
6902 python-pytest
6903 python-setuptools
6904 python-sphinx
6905 python-sphinx-rtd-theme
6906 python-wheel))
6907 (home-page "https://github.com/pyro-ppl/pyro-api")
6908 (synopsis "Generic API for dispatch to Pyro backends")
6909 (description "This package provides a generic API for dispatch to Pyro backends.")
6910 (license license:asl2.0)))
6911
6912(define-public python-pyro-ppl
6913 (package
6914 (name "python-pyro-ppl")
6915 (version "1.9.1")
6916 ;; The sources on pypi don't include tests.
6917 (source
6918 (origin
6919 (method git-fetch)
6920 (uri (git-reference
6921 (url "https://github.com/pyro-ppl/pyro")
6922 (commit version)))
6923 (file-name (git-file-name name version))
6924 (sha256
6925 (base32 "0q87d0frgzn1ljnpbyxmj582yfn6zy3m960m3ab826h4rpzybxhf"))))
6926 (build-system pyproject-build-system)
6927 (arguments
6928 ;; Tests take too long.
6929 ;; XXX: Maybe select the most important test modules.
6930 (list #:tests? #f))
6931 (propagated-inputs
6932 (list python-numpy
6933 python-opt-einsum
6934 python-pyro-api
6935 python-pytorch
6936 python-tqdm))
6937 (native-inputs (list python-setuptools python-wheel))
6938 (home-page "https://pyro.ai")
6939 (synopsis "Python library for probabilistic modeling and inference")
6940 (description
6941 "This package provides a Python library for probabilistic modeling and
6942inference.")
6943 (license license:asl2.0)))
6944
6945(define-public python-linear-operator
6946 (package
6947 (name "python-linear-operator")
6948 (version "0.6.1")
6949 (source
6950 (origin
6951 (method git-fetch)
6952 (uri (git-reference
6953 (url "https://github.com/cornellius-gp/linear_operator/")
6954 (commit (string-append "v" version))))
6955 (file-name (git-file-name name version))
6956 (sha256
6957 (base32
6958 "1pfk4mdkvm75lyyb7zmq9pxclhica7fkk4cyvkpz8jncgimvh5qs"))))
6959 (build-system pyproject-build-system)
6960 (propagated-inputs (list python-jaxtyping
6961 python-mpmath
6962 python-pytorch
6963 python-scipy))
6964 (native-inputs (list python-pytest
6965 python-setuptools
6966 python-setuptools-scm
6967 python-typeguard))
6968 (home-page "https://github.com/cornellius-gp/linear_operator/")
6969 (synopsis "Linear operator implementation")
6970 (description "LinearOperator is a PyTorch package for abstracting away the
6971linear algebra routines needed for structured matrices (or operators).")
6972 (license license:expat)))
6973
6974(define-public python-gpytorch
6975 (package
6976 (name "python-gpytorch")
6977 (version "1.15.2")
6978 (source (origin
6979 (method url-fetch)
6980 (uri (pypi-uri "gpytorch" version))
6981 (sha256
6982 (base32
6983 "0qakfyw9akxbcvjz2rzn5vmy7ln6lsq5yp5jfbvqa6w57zlja1iq"))))
6984 (build-system pyproject-build-system)
6985 (arguments
6986 (list #:test-flags
6987 #~(list "-k" (string-append
6988 ;; test_deprecated_methods fails with an AssertionError.
6989 "not test_deprecated_methods"
6990 ;; This test is flaky: Expects gradients of 0 exactly,
6991 ;; can get negligible ones (e-10 to e-16).
6992 " and not test_optimization_optimal_error")
6993 ;; Ignore lenghty tests of little relevance.
6994 "--ignore=test/examples/")))
6995 (propagated-inputs (list python-jaxtyping
6996 python-linear-operator
6997 python-mpmath
6998 python-scikit-learn
6999 python-scipy))
7000 (native-inputs (list python-nbval
7001 python-pytest
7002 python-setuptools
7003 python-setuptools-scm))
7004 (home-page "https://gpytorch.ai")
7005 (synopsis "Implementation of Gaussian Processes in PyTorch")
7006 (description
7007 "GPyTorch is a Gaussian process library implemented using PyTorch.")
7008 (license license:expat)))
7009
7010(define-public python-botorch
7011 (package
7012 (name "python-botorch")
7013 (version "0.17.2")
7014 (source (origin
7015 (method git-fetch) ;no tests in PyPI
7016 (uri (git-reference
7017 (url "https://github.com/meta-pytorch/botorch")
7018 (commit (string-append "v" version))))
7019 (file-name (git-file-name name version))
7020 (sha256
7021 (base32
7022 "1flb6fv2m6l8bbmbq9n7lgf1fd45r9xx2rw08qanm1c00dv12s99"))))
7023 (build-system pyproject-build-system)
7024 (arguments
7025 ;; 7 failed, 1502 passed, 1 skipped, 1 deselected, 807 warnings
7026 (list #:test-flags #~(list "-k"
7027 (string-append
7028 "not test_all_cases_covered"
7029 " and not test_input_constructors"
7030 " and not test_gen"
7031 " and not test_mock"
7032 " and not test_evaluation"
7033 ;; SciPy<1.13: gen.py doesn't import
7034 ;; fmin_l_bfgs_b_batched; mock patch fails.
7035 " and not test_emsemble_map_saas"
7036 " and not test_negative_fixed_features")
7037 ;; Requires optional 'pfns' dependency.
7038 "--ignore=test_community/")
7039 #:phases
7040 #~(modify-phases %standard-phases
7041 (add-after 'unpack 'fix-hypervolume-initial-hvs
7042 (lambda _
7043 ;; PyTorch 2.10 rejects passing a torch.Size plus extra args to `view'.
7044 (substitute* "botorch/utils/multi_objective/hypervolume.py"
7045 (("self\\._batch_sample_shape, *\\*obj\\.shape\\[-2:\\]")
7046 "self._batch_sample_shape")))))))
7047 (propagated-inputs (list python-gpytorch
7048 python-linear-operator
7049 python-multipledispatch
7050 python-pyre-extensions
7051 python-pyro-ppl
7052 python-pytorch
7053 python-scipy
7054 python-threadpoolctl
7055 python-typing-extensions))
7056 (native-inputs (list python-pytest
7057 python-setuptools
7058 python-setuptools-scm))
7059 (home-page "https://botorch.org")
7060 (synopsis "Bayesian Optimization in PyTorch")
7061 (description
7062 "BoTorch is a library for Bayesian Optimization built on PyTorch.")
7063 (license license:expat)))
7064
7065(define-public vosk-api
7066 (let* ((openfst openfst-for-vosk)
7067 (kaldi kaldi-for-vosk))
7068 (package
7069 (name "vosk-api")
7070 (version "0.3.50")
7071 (source
7072 (origin
7073 (method git-fetch)
7074 (uri (git-reference
7075 (url "https://github.com/alphacep/vosk-api")
7076 (commit (string-append "v" version))))
7077 (file-name (git-file-name name version))
7078 (sha256
7079 (base32 "0rm7c1n9iv4y9q6a860rqiy2bdawxjhbfd993lms1ly86vwyai8k"))))
7080 (build-system gnu-build-system)
7081 (arguments
7082 (list
7083 #:tests? #f
7084 #:phases
7085 #~(modify-phases %standard-phases
7086 (add-after 'unpack 'chdir
7087 (lambda _ (chdir "src")))
7088 (replace 'configure
7089 (lambda _
7090 (let* ((openfst #$(this-package-input "openfst"))
7091 (openblas #$(this-package-input "openblas"))
7092 (kaldi #$(this-package-input "kaldi")))
7093 (substitute* "./Makefile"
7094 (("USE_SHARED\\?=0")
7095 "USE_SHARED?=1")
7096 (("-DFST_NO_DYNAMIC_LINKING")
7097 "")
7098 (("-lopenblas -llapack -lblas -lf2c")
7099 (string-append
7100 "-L" openblas "/lib " "-lopenblas "))
7101 (("-lfst -lfstngram")
7102 (string-append
7103 "-L" openfst "/lib " "-lfst -lfstngram "))
7104 (("\\$\\(HOME\\)\\/travis\\/kaldi")
7105 (string-append kaldi "/include"))
7106 (("\\$\\(KALDI_ROOT\\)\\/tools\\/openfst")
7107 openfst)
7108 (("\\$\\(KALDI_ROOT\\)\\/tools\\/OpenBLAS\\/install")
7109 openblas)
7110 (("\\$\\(KALDI_ROOT\\)\\/libs")
7111 (string-append kaldi "/lib"))))))
7112 (replace 'install
7113 (lambda _
7114 (let* ((lib (string-append #$output "/lib"))
7115 (src (string-append #$output "/src")))
7116 (mkdir-p lib)
7117 (mkdir-p src)
7118 (install-file "libvosk.so" lib)
7119 (for-each
7120 (lambda (x) (install-file x src))
7121 (find-files "." "\\.h$"))))))))
7122 (inputs (list kaldi openfst openblas))
7123 (home-page "https://alphacephei.com/vosk/")
7124 (synopsis "Speech recognition toolkit based on @code{kaldi}")
7125 (description "This package provides a speech recognition toolkit based
7126on @code{kaldi}. It supports more than 20 languages and dialects - English,
7127Indian English, German, French, Spanish, Portuguese, Chinese, Russian,
7128Turkish, Vietnamese, Italian, Dutch, Catalan, Arabic, Greek, Farsi, Filipino,
7129Ukrainian, Kazakh, Swedish, Japanese, Esperanto, Hindi, Czech, Polish. The
7130program works offline, even on lightweight devices. Portable per-language
7131models are about 50Mb each, and there are much bigger and precise models
7132available.
7133
7134Vosk API provides a streaming API allowing to use it @emph{on-the-fly} and
7135bindings for different programming languages. It allows quick reconfiguration
7136of vocabulary for better accuracy, and supports speaker identification beside
7137simple speech recognition.")
7138 (license license:asl2.0))))
7139
7140(define-public python-vosk
7141 (package
7142 (inherit vosk-api)
7143 (name "python-vosk")
7144 (build-system pyproject-build-system)
7145 (propagated-inputs
7146 (list python-cffi python-requests python-tqdm python-srt python-websockets))
7147 (inputs (list vosk-api))
7148 (native-inputs
7149 (list python-setuptools python-wheel))
7150 (arguments
7151 (list
7152 #:tests? #f ;; TODO There are tests but not run through Makefile.
7153 #:phases
7154 #~(modify-phases %standard-phases
7155 (add-after 'unpack 'config
7156 (lambda _
7157 (chdir "python")
7158 (setenv "VOSK_SOURCE" #$vosk-api)))
7159 (add-before 'build 'from-abi-to-api
7160 (lambda* (#:key inputs #:allow-other-keys)
7161 (substitute* "vosk_builder.py"
7162 (("ffibuilder\\.set_source\\(\"vosk.vosk_cffi\", None\\)")
7163 (string-append
7164 "ffibuilder.set_source(\"vosk.vosk_cffi\", "
7165 "r\"\"\"\n#include<vosk_api.h>\n#include<Python.h>\"\"\",\n\t"
7166 "library_dirs=["
7167 "'" #$vosk-api "/lib'"
7168 "],\n\t"
7169 "libraries=['vosk', 'python"
7170 (python-version
7171 (dirname (dirname (search-input-file inputs "bin/python"))))
7172 "'],\n\t"
7173 "include_dirs=["
7174 "'" #$vosk-api "/src'" "])")))
7175 (substitute* "vosk/__init__.py"
7176 (("_c = open_dll\\(\\)")
7177 "")
7178 (("_ffi")
7179 "ffi")
7180 (("from \\.vosk_cffi import ffi as ffi")
7181 "from .vosk_cffi import ffi, lib")
7182 (("_c\\.")
7183 "lib.")))))))))
7184
7185(define-public nerd-dictation
7186 (let* ((commit "03ce043a6d569a5bb9a715be6a8e45d8ba0930fd")
7187 (revision "2"))
7188 (package
7189 (name "nerd-dictation")
7190 (version (git-version "0" revision commit))
7191 (source
7192 (origin
7193 (method git-fetch)
7194 (uri (git-reference
7195 (url "https://github.com/ideasman42/nerd-dictation")
7196 (commit commit)))
7197 (file-name (git-file-name name version))
7198 (sha256
7199 (base32 "0ksnlpy2jcldxamq7bsbcgxgafcmgxkbjccd4fwmmn0y814kkz9k"))))
7200 (build-system pyproject-build-system)
7201 (arguments
7202 (list
7203 #:test-backend #~'custom
7204 #:test-flags #~(list "../../tests/from_words_to_digits.py")
7205 #:phases
7206 #~(modify-phases %standard-phases
7207 (add-after 'unpack 'chdir
7208 (lambda _
7209 (chdir "package/python"))))))
7210 (native-inputs (list python-setuptools))
7211 (propagated-inputs (list python-vosk))
7212 (home-page "https://github.com/ideasman42/nerd-dictation")
7213 (synopsis "Offline speech-to-text for desktop Linux")
7214 (description
7215 "This package provides simple access speech to text for using in
7216Linux without being tied to a desktop environment, using the @code{vosk-api}.
7217The user configuration lets you manipulate text using Python string
7218operations. It has zero overhead, as this relies on manual activation and
7219there are no background processes. Dictation is accessed manually with
7220@code{nerd-dictation begin} and @code{nerd-dictation end} commands.")
7221 (license license:gpl2+))))
7222
7223(define (nerd-dictation-gexp input-name output-name bash nerd-dictation)
7224 (with-imported-modules '((guix build utils))
7225 #~(begin
7226 (use-modules (guix build utils))
7227
7228 (let* ((exe (string-append #$output "/bin/nerd-dictation"))
7229 (nerd-dictation-exe
7230 #$(file-append nerd-dictation "/bin/nerd-dictation")))
7231 (mkdir-p (dirname exe))
7232 (call-with-output-file exe
7233 (lambda (port)
7234 (format port "#!~a
7235if [ \"$1\" = begin ]
7236 then
7237 exec ~a $@ --input=~a --simulate-input-tool=~a
7238 else
7239 exec ~a $@
7240fi"
7241 #$(file-append bash "/bin/bash")
7242 nerd-dictation-exe
7243 #$input-name
7244 #$output-name
7245 nerd-dictation-exe)))
7246 (chmod exe #o555)))))
7247
7248(define-public nerd-dictation/xdotool
7249 (package
7250 (inherit nerd-dictation)
7251 (name "nerd-dictation-xdotool")
7252 (build-system trivial-build-system)
7253 (arguments
7254 (list #:builder
7255 (nerd-dictation-gexp "PAREC" "XDOTOOL"
7256 (this-package-input "bash-minimal")
7257 (this-package-input "nerd-dictation"))))
7258 (inputs (list bash-minimal nerd-dictation))
7259 (propagated-inputs (list pulseaudio xdotool))))
7260
7261(define-public nerd-dictation/sox-xdotool
7262 (package
7263 (inherit nerd-dictation/xdotool)
7264 (name "nerd-dictation-sox-xdotool")
7265 (arguments
7266 (list #:builder
7267 (nerd-dictation-gexp "SOX" "XDOTOOL"
7268 (this-package-input "bash-minimal")
7269 (this-package-input "nerd-dictation"))))
7270 (propagated-inputs (list sox xdotool))))
7271
7272(define-public nerd-dictation/sox-ydotool
7273 (package
7274 (inherit nerd-dictation/xdotool)
7275 (name "nerd-dictation-sox-ydotool")
7276 (arguments
7277 (list #:builder
7278 (nerd-dictation-gexp "SOX" "YDOTOOL"
7279 (this-package-input "bash-minimal")
7280 (this-package-input "nerd-dictation"))))
7281 (propagated-inputs (list sox ydotool))))
7282
7283(define-public nerd-dictation/sox-wtype
7284 (package
7285 (inherit nerd-dictation/xdotool)
7286 (name "nerd-dictation-sox-wtype")
7287 (arguments
7288 (list #:builder
7289 (nerd-dictation-gexp "SOX" "WTYPE"
7290 (this-package-input "bash-minimal")
7291 (this-package-input "nerd-dictation"))))
7292 (propagated-inputs (list sox wtype))))
7293
7294(define-public python-brian2
7295 (package
7296 (name "python-brian2")
7297 (version "2.10.1")
7298 (source (origin
7299 (method url-fetch)
7300 (uri (pypi-uri "brian2" version))
7301 (sha256
7302 (base32
7303 "0kqvw716q26liifjds807nxz17xbzrqwhvyp34j3d4i115xivln1"))))
7304 (build-system pyproject-build-system)
7305 (arguments
7306 (list
7307 ;; tests: 104 passed, 2 skipped, 16 warnings
7308 #:test-flags
7309 ;; Tests hang during collection with higher number of threads.
7310 #~(list "--numprocesses" (number->string (min 8 (parallel-job-count)))
7311 ;; XXX: The complete test suite is massive, run a simple test
7312 ;; that uses the main simulation elements and force code
7313 ;; generation to use Cython.
7314 "tests/test_synapses.py")
7315 #:phases
7316 #~(modify-phases %standard-phases
7317 (add-after 'unpack 'relax-requirements
7318 (lambda _
7319 (substitute* "pyproject.toml"
7320 ;; 'cython>=0.29.21,<3.1.4',
7321 ((">=0.29.21,<3.1.4") ""))))
7322 (add-before 'check 'pre-check
7323 (lambda _
7324 (setenv "HOME" "/tmp")
7325 (copy-recursively "brian2/tests" "tests")
7326 (delete-file-recursively "brian2"))))))
7327 (native-inputs
7328 (list python-pytest
7329 python-pytest-timeout
7330 python-pytest-xdist
7331 python-setuptools-scm))
7332 (propagated-inputs
7333 (list python-cython
7334 python-jinja2
7335 python-numpy
7336 python-packaging
7337 python-pyparsing
7338 python-setuptools
7339 python-sympy))
7340 (home-page "https://briansimulator.org/")
7341 (synopsis "Clock-driven simulator for spiking neural networks")
7342 (description
7343 "Brian is a simulator for spiking neural networks written in Python. It
7344is therefore designed to be easy to learn and use, highly flexible and
7345easily extensible.")
7346 (license license:cecill)))
7347
7348(define-public python-brian2tools
7349 (package
7350 (name "python-brian2tools")
7351 (version "0.3")
7352 (source (origin
7353 (method url-fetch)
7354 (uri (pypi-uri "brian2tools" version))
7355 (sha256
7356 (base32
7357 "0fn028mfy3qlzjkadd0wr5d7rcplijd5jphln414xifvvsb9jcc2"))))
7358 (build-system pyproject-build-system)
7359 ;; Both pypi tarball and git repo lack test files.
7360 (arguments (list #:tests? #f))
7361 (propagated-inputs (list python-brian2
7362 python-libneuroml
7363 python-markdown-strings
7364 python-matplotlib
7365 python-pylems
7366 python-tables))
7367 (native-inputs (list python-setuptools python-setuptools-scm))
7368 (home-page "https://github.com/brian-team/brian2tools")
7369 (synopsis "Tools for the Brian 2 simulator")
7370 (description "Visualization and NeuroML import/export tools for the
7371Brian 2 simulator.")
7372 (license license:cecill)))
7373
7374(define-public mnn
7375 (package
7376 (name "mnn")
7377 (version "3.5.0")
7378 (source
7379 (origin
7380 (method git-fetch)
7381 (uri (git-reference
7382 (url "https://github.com/alibaba/MNN/")
7383 (commit version)))
7384 (snippet
7385 #~(begin
7386 (use-modules (guix build utils))
7387 ;; Remove failing tests.
7388 (delete-file-recursively "test/expr/ModuleTest.cpp")
7389 (delete-file-recursively "test/op/ConvInt8Test.cpp")
7390 ;; Remove external libraries. Almost all of them are
7391 ;; available in Guix.
7392 (with-directory-excursion "3rd_party"
7393 (for-each delete-file-recursively
7394 '(;;"OpenCLHeaders"; for now does not build if in tree copy removed
7395 ;; "flatbuffers" ; for now does not build if in tree copy removed
7396 "protobuf"
7397 "rapidjson")))))
7398 (file-name (git-file-name name version))
7399 (sha256
7400 (base32 "1jllq0zik55kznnks0kjqkilk362msgbz65qc3az5hvcrz34m8j7"))))
7401 (build-system cmake-build-system)
7402 (native-inputs (list googletest pkg-config python-minimal-wrapper))
7403 (inputs (list ;; flatbuffers ;requires 1.10.2
7404 fp16
7405 glew
7406 glslang
7407 glu
7408 mesa
7409 mesa-headers
7410 mesa-opencl
7411 opencl-headers
7412 opencl-clhpp
7413 opencl-icd-loader
7414 opencv
7415 protobuf
7416 pthreadpool
7417 rapidjson ;requires 1.1.0
7418 shaderc
7419 vulkan-headers
7420 vulkan-loader))
7421 (arguments
7422 (list
7423 #:phases
7424 #~(modify-phases %standard-phases
7425 (replace 'check
7426 (lambda* (#:key tests? #:allow-other-keys)
7427 (when tests?
7428 (invoke "./run_test.out")))))
7429 #:configure-flags
7430 #~(list "-DMNN_USE_SYSTEM_LIB=ON"
7431 "-DMNN_OPENMP=ON"
7432 ;; "-DMNN_OPENGL=ON" ; TO DO
7433 "-DMNN_OPENCL=ON"
7434 "-DMNN_VULKAN=ON"
7435 "-DMNN_SUPPORT_BF16=ON"
7436 "-DMNN_BUILD_TEST=ON"
7437 "-DMNN_BUILD_AUDIO=ON"
7438 "-DMNN_BUILD_OPENCV=ON"
7439 "-DMNN_BUILD_PROTOBUFFER=OFF"
7440 "-DMNN_IMGCODECS=ON"
7441 ;; "-DMNN_AUDIO_TEST=ON"
7442 ;; tests trying to fetch googletest and cannot build
7443 ;; "-DMNN_OPENCV_TEST=ON"
7444 ;; TO DO: remove the fetch in cmake and use system googletest
7445 "-DMNN_OPENCV_BENCH=ON"
7446 "-DMNN_BUILD_QUANTOOLS=ON"
7447 "-DMNN_EVALUATION=ON"
7448 "-DMNN_BUILD_BENCHMARK=ON"
7449 "-DMNN_BUILD_TOOLS=ON"
7450 "-DMNN_BUILD_CONVERTER=ON"
7451 "-DMNN_USE_SSE=ON"
7452 "-DMNN_AVX512=ON"))) ;TO DO: add Pytorch support
7453 (home-page "http://www.mnn.zone/")
7454 (synopsis "Fast, lightweight deep learning framework")
7455 (description
7456 "MNN is a deep learning framework. It supports inference and
7457training of deep learning models for inference and training on-device.")
7458 (license license:asl2.0)))
7459
7460;; This package needs to be in sync with llama-cpp version in use to avoid
7461;; incompatibilities.
7462(define-public python-gguf
7463 (package
7464 (inherit llama-cpp)
7465 (name "python-gguf")
7466 (version "0.19.0") ;from gguf-py/pyproject.toml
7467 (build-system pyproject-build-system)
7468 (arguments
7469 (list
7470 #:phases
7471 #~(modify-phases %standard-phases
7472 (add-after 'unpack 'chdir
7473 (lambda _
7474 (chdir "gguf-py"))))))
7475 (inputs '())
7476 (propagated-inputs (list python-numpy python-pyyaml python-pyside-6
7477 python-sentencepiece python-tqdm))
7478 (native-inputs (list python-poetry-core python-pytest))
7479 (properties '())
7480 (home-page "https://ggml.ai")
7481 (synopsis "Read and write ML models in GGUF for GGML")
7482 (description "A Python library for reading and writing GGUF & GGML format
7483ML models.")
7484 (license license:expat)))
7485
7486(define-public python-gymnasium
7487 (package
7488 (name "python-gymnasium")
7489 (version "0.29.1")
7490 (source
7491 (origin
7492 (method url-fetch)
7493 (uri (pypi-uri "gymnasium" version))
7494 (sha256
7495 (base32 "1cab4wsnlsxn2z90qmymv8ppmsq8yq2amiqwid3r0xfbxx92flqs"))))
7496 (build-system pyproject-build-system)
7497 (arguments
7498 (list
7499 #:phases
7500 #~(modify-phases %standard-phases
7501 (add-after 'unpack 'create-tests-module
7502 (lambda _
7503 (with-output-to-file "tests/__init__.py"
7504 (lambda _ (display ""))))))))
7505 (propagated-inputs (list python-cloudpickle python-farama-notifications
7506 python-numpy python-typing-extensions))
7507 (native-inputs
7508 (list python-pytest python-scipy python-setuptools python-wheel))
7509 (home-page "https://gymnasium.farama.org/")
7510 (synopsis
7511 "Standard API for reinforcement learning and a set of reference environments")
7512 (description
7513 "This package provides a standard API for reinforcement learning and a
7514diverse set of reference environments (formerly Gym).")
7515 (license license:expat)))
7516
7517;; This will build dlib in the process of building python-dlib--and that
7518;; seems to be intended by upstream. Well, at least it probably optimizes
7519;; better that way.
7520(define-public python-dlib
7521 (package
7522 (inherit dlib)
7523 (name "python-dlib")
7524 (build-system pyproject-build-system)
7525 (arguments
7526 (list
7527 #:phases
7528 #~(modify-phases %standard-phases
7529 (add-after 'unpack 'subst
7530 (lambda _
7531 (substitute* "tools/python/CMakeLists.txt"
7532 (("\
7533add_subdirectory[(][.][.]/[.][.]/dlib/external/pybind11 pybind11_build[)]")
7534 "find_package(pybind11 CONFIG)")))))))
7535 (native-inputs
7536 (list cmake-minimal
7537 perl
7538 pkg-config
7539 pybind11-2
7540 python-pytest
7541 python-setuptools))))
7542
7543;; Version 0.16 breaks miopen
7544(define-public frugally-deep
7545 (package
7546 (name "frugally-deep")
7547 (version "0.15.31")
7548 (source (origin
7549 (method git-fetch)
7550 (uri (git-reference
7551 (url "https://github.com/Dobiasd/frugally-deep")
7552 (commit (string-append "v" version))))
7553 (file-name (git-file-name name version))
7554 (sha256
7555 (base32
7556 "0gzkv03kz9p94a9apmds77npvxhmqyahhah4bq5yz3v9pvw6kx10"))))
7557 (build-system cmake-build-system)
7558 ;; Tests require tensorflow
7559 (arguments (list #:tests? #f))
7560 (native-inputs (list eigen functionalplus nlohmann-json))
7561 (home-page "https://github.com/Dobiasd/frugally-deep")
7562 (synopsis "Header-only library for using Keras (TensorFlow) models
7563in C++")
7564 (description "@code{frugally-deep} is a header-only C++ library for
7565inference of Keras machine learning models on a single CPU core.")
7566 (license license:expat)))