projects/guix·blob ruby-team · refs

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