projects/guix·blob java-team · refs

7525 lines · 301.7 KiB

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