(define-module (machinelearning) #:use-module ((guix licenses) :prefix license:) #:use-module (gnu packages base) #:use-module (gnu packages bash) #:use-module (gnu packages check) #:use-module (gnu packages wxwidgets) #:use-module (gnu packages commencement) #:use-module (gnu packages crates-io) #:use-module (gnu packages golang) #:use-module (gnu packages golang-build) #:use-module (gnu packages golang-check) #:use-module (gnu packages golang-maths) #:use-module (gnu packages golang-compression) #:use-module (gnu packages golang-crypto) #:use-module (gnu packages gtk) #:use-module (gnu packages prometheus) #:use-module (gnu packages golang-web) #:use-module (gnu packages golang-xyz) #:use-module (gnu packages image) #:use-module (gnu packages llvm) #:use-module (gnu packages machine-learning) #:use-module (gnu packages maths) #:use-module (gnu packages opencl) #:use-module (gnu packages pkg-config) #:use-module (gnu packages protobuf) #:use-module (gnu packages python) #:use-module (gnu packages python-build) #:use-module (gnu packages version-control) #:use-module (gnu packages python-check) #:use-module (gnu packages python-crypto) #:use-module (gnu packages python-web) #:use-module (gnu packages python-xyz) #:use-module (gnu packages curl) #:use-module (gnu packages rust) #:use-module (gnu packages rust-apps) #:use-module (gnu packages vulkan) #:use-module (gnu packages tls) #:use-module (gnu packages) #:use-module (guix build utils) #:use-module (guix build-system cargo) #:use-module (guix build-system cmake) #:use-module (guix build-system gnu) #:use-module (guix build-system go) #:use-module (guix build-system pyproject) #:use-module (guix build-system python) #:use-module (guix download) #:use-module (guix gexp) #:use-module (guix git-download) #:use-module (guix packages) #:use-module (guix utils) ) (define-public poetry-plugin-export (package (name "poetry-plugin-export") (version "1.7.1") (source (origin (method url-fetch) (uri (pypi-uri "poetry_plugin_export" version)) (sha256 (base32 "0bp2640l7v9digjccj0wz086s1xa4hdbrcvdpa84544a46vcyqng")))) (build-system pyproject-build-system) (propagated-inputs (list python-poetry-core-1.9.0)) (home-page "https://python-poetry.org/") (synopsis "Poetry plugin to export the dependencies to various formats") (description "Poetry plugin to export the dependencies to various formats") (license license:expat))) (define-public python-poetry-core-1.9.0 (package (inherit python-poetry-core) (name "python-poetry-core") (version "1.9.0") )) (define-public poetry-1.8.2 (package (inherit poetry) (name "poetry") (version "1.8.2") )) (define-public poetry-1.3 (package (inherit poetry) (name "poetry") (version "1.3") )) (define-public python-installer (package (name "python-installer") (version "0.7.0") (source (origin (method url-fetch) (uri (pypi-uri "installer" version)) (sha256 (base32 "0cdnqh3a3amw8k4s1pzfjh0hpvzw4pczgl702s1b16r82qqkwvd2")))) (build-system pyproject-build-system) (inputs (list python-flit-core)) (home-page "") (synopsis "A library for installing Python wheels.") (description "This package provides a library for installing Python wheels.") (license #f))) (define-public ggml (package (name "ggml") (version "589fed13a77d7e54435c2182384955706b60b841") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/ggerganov/ggml") (recursive? #t) (commit version))) (file-name (git-file-name name version)) (sha256 (base32 "1qzydmiqsdxhj7gmaxbzllhhnb7rw49ykkj03jm044spk9nnn56s")))) (build-system cmake-build-system) (inputs (list openblas)) (arguments '( #:tests? #f ;#:cmake "--config Release" #:configure-flags (list "-DGGML_OPENBLAS=ON -DGGML_BUILD_TESTS=OFF -DGGML_BUILD_EXAMPLES=OFF --config Release") )) (home-page "https://github.com/ggerganov/ggml/") (synopsis "Tensor library for machine learning") (description "Tensor library for machine learning in pure C/C++") (license license:expat))) (define-public ggml-vulkan (package (inherit ggml) (name "ggml-vulkan") (build-system cmake-build-system) (inputs (list shaderc vulkan-headers vulkan-loader openlibm glibc)) (arguments '( #:tests? #f ;#:cmake "--config Release" #:configure-flags (list "-DGGML_VULKAN=ON -DGGML_BUILD_TESTS=OFF -DGGML_BUILD_EXAMPLES=OFF --config Release") )) (home-page "https://github.com/ggerganov/ggml/") (synopsis "Tensor library for machine learning") (description "Tensor library for machine learning in pure C/C++") (license license:expat))) (define-public mlimgsynth (package (name "mlimgsynth") (version "fd351102a0c6719fe4437cb1bb834a87735861a1") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/aagdev/mlimgsynth") (recursive? #t) (commit version))) (file-name (git-file-name name version)) (sha256 (base32 "1gbppz9r0mjdis6gcvpkx3f4v0px7zz05k0cxkjq9s4v63xzr1p3")))) (build-system gnu-build-system) (inputs (list openblas ggml-vulkan libpng ijg-libjpeg)) (arguments '( #:tests? #f #:make-flags (let* ((ggml-dir (assoc-ref %build-inputs "ggml-vulkan"))) (list (string-append "CC=gcc") (string-append "GGML_INCLUDE_PATH=" ggml-dir "/include") (string-append "GGML_LIB_PATH=" ggml-dir "/lib"))) #:phases (modify-phases %standard-phases (delete 'check) (delete 'configure) (replace 'install (lambda* (#:key outputs #:allow-other-keys) (let ((out (assoc-ref outputs "out"))) (install-file "mlimgsynth" (string-append out "/bin"))))) ) ) ) (home-page "https://github.com/aagdev/mlimgsynth") (synopsis " Image synthesis using machine learning") (description "Generate images using Stable Diffusion (SD) models. This program is completely written in C and uses the GGML library. It is largely based in stable-diffusion.cpp, but with a focus in more concise and clear code.") (license license:expat))) (define-public stable-diffusion-cpp (package (name "stable-diffusion-cpp") (version "5eb15ef4d022bef4a391de4f5f6556e81fbb5024") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/leejet/stable-diffusion.cpp.git") (recursive? #t) (commit version))) (file-name (git-file-name name version)) (sha256 (base32 "0q6nmp1dqrlw56b9z887fdnim54vwpn3sw0l057ikmf4ffwdjs8v")))) (build-system cmake-build-system) (inputs (list openblas)) (arguments '( #:tests? #f ;#:cmake "--config Release" ;#:configure-flags (list "-DSD_CUBLAS=ON -DGGML_OPENBLAS=ON --config Release") #:configure-flags (list "-DGGML_OPENBLAS=ON -DSD_FLASH_ATTN=ON --config Release") ) ) (home-page "https://github.com/leejet/stable-diffusion.cpp") (synopsis "Inference of Stable Diffusion in pure C/C++") (description "Inference of Stable Diffusion in pure C/C++") (license license:expat))) (define-public stable-diffusion-cpp-vulkan (package (inherit stable-diffusion-cpp) (name "stable-diffusion-cpp-vulkan") (arguments `( #:tests? #f #:configure-flags (list "-DSD_VULKAN=ON --config Release") #:phases (modify-phases %standard-phases (add-after 'install 'rename-binary (lambda* (#:key outputs #:allow-other-keys) (let ((bin (string-append (assoc-ref outputs "out") "/bin/sd"))) (when (file-exists? bin) (rename-file bin (string-append (dirname bin) "/sd-vulkan"))))))))) (inputs (list vulkan-headers vulkan-loader shaderc libomp)))) (define-public exiv2-staticlibs (package (inherit exiv2) (arguments `(#:test-target "tests" #:configure-flags (list "-DEXIV2_BUILD_UNIT_TESTS=ON" ;; darktable needs BMFF to support ;; CR3 files. "-DEXIV2_ENABLE_BMFF=ON") #:phases (modify-phases %standard-phases (add-after 'unpack 'patch-gcc-reference (lambda _ ;; _GLIBCXX_ASSERTIONS brings reference to GCC. (substitute* "cmake/compilerFlags.cmake" (("add_compile_options[(]-Wp,-D_GLIBCXX_ASSERTIONS[)]") "")))) ,@(if (or (target-ppc64le?) (target-aarch64?) (target-riscv64?)) '((add-after 'unpack 'adjust-tests (lambda _ ;; Adjust test on ppc64 and aarch64, where no exception ;; is raised and thus the return value is different. See ;; and ;; . (substitute* "tests/bugfixes/github/test_CVE_2018_12265.py" (("\\$uncaught_exception \\$addition_overflow_message\n") "") (("retval = \\[1\\]") "retval = [0]"))))) '())))) )) (define-public stable-diffusion-cpp-gui-wx (package (name "stable-diffusion-cpp-gui-wx") (version "6f604f836961002fbce72a205c1e6cc6d6a531e9") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/fszontagh/sd.cpp.gui.wx") (recursive? #t) (commit version))) (file-name (git-file-name name version)) (sha256 (base32 "035zqhjnwdb07ag4chj9zijl70wk81kinqwlnvs9ixb2fzl1z374")))) (build-system cmake-build-system) (arguments '( #:tests? #f #:configure-flags (list "-DSD_AVX=ON" "-DWXWIDGETS_VERSION=3.2.5" (string-append "-DWXWIDGETS_EXTRA_PATH=" (assoc-ref %build-inputs "wxwidgets")) ) #:substitutable? #f ) ) (native-inputs (list pkg-config)) (inputs (list openblas openssl curl exiv2-staticlibs wxwidgets gtk+ pangomm git stable-diffusion-cpp)) (synopsis "cross-platform GUI for Stable Diffusion C++") (description "A cross-platform GUI for Stable Diffusion C++, built using wxWidgets.") (home-page "https://stable-diffusion.fsociety.hu") (license license:expat) )) (define-public bark-cpp (package (name "bark-cpp") (version "03d70997620ab4d1130be68ef2ab3c763ba09576") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/PABannier/bark.cpp.git") (recursive? #t) (commit version))) (file-name (git-file-name name version)) (sha256 (base32 "02s3nwpbq87r3l11bm2psc9lnra650rf87659kwx41p6kzsl536m")))) (build-system cmake-build-system) (inputs (list openblas)) (arguments '( #:tests? #f #:configure-flags (list "-DGGML_OPENBLAS=ON --config Release") #:phases (modify-phases %standard-phases (add-after 'install 'install-server (lambda _ (with-directory-excursion (string-append #$output "/bin") (symlink "server" "bark-server") ) )) ;(add-after 'install 'install-main ; (lambda _ ; (with-directory-excursion (string-append #$output "/bin") ; (symlink "main" "bark") ; ) ; )) ; ) )) (home-page "https://github.com/PABannier/bark.cpp") (synopsis "Real-time realistic multilingual text-to-speech generation to the community.") (description "With bark.cpp, our goal is to bring real-time realistic multilingual text-to-speech generation to the community.") (license license:expat))) (define-public clip-cpp (package (name "clip-cpp") (version "348b283cb6c2fc2bde450cc08a05a789dbe109e4") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/monatis/clip.cpp") (recursive? #t) (commit version))) (file-name (git-file-name name version)) (sha256 (base32 "0xyjnzk8wgx77ip6k9969ljckxmaf165ypbh013hsrvgcrq9knrs")))) (build-system cmake-build-system) ;(inputs (list openblas)) (arguments (list #:tests? #f ;#:configure-flags #~(list "-DCLIP_BUILD_IMAGE_SEARCH=ON -DCLIP_OPENBLAS=ON") #:configure-flags #~(list "-DCLIP_OPENBLAS=ON") #:modules '((ice-9 textual-ports) (guix build utils) ((guix build python-build-system) #:prefix python:) (guix build cmake-build-system)) #:imported-modules `(,@%cmake-build-system-modules (guix build python-build-system)) #:phases #~(modify-phases %standard-phases (add-before 'install 'install-python-scripts (lambda _ (let ((bin (string-append #$output "/bin/"))) (define (make-script script) (let ((suffix (if (string-suffix? ".py" script) "" ".py"))) (call-with-input-file (string-append "../source/models/" script suffix) (lambda (input) (call-with-output-file (string-append bin script) (lambda (output) (format output "#!~a/bin/python3\n~a" #$(this-package-input "python") (get-string-all input)))))) (chmod (string-append bin script) #o555))) (mkdir-p bin) (make-script "convert_hf_to_gguf") ))) (add-after 'install-python-scripts 'wrap-python-scripts (assoc-ref python:%standard-phases 'wrap)) (replace 'install (lambda _ (copy-file "bin/main" (string-append #$output "/bin/clip")) (copy-file "bin/zsl" (string-append #$output "/bin/clip-zsl")) (copy-file "bin/extract" (string-append #$output "/bin/clip-extract")) ))))) (inputs `( ("python", python) ("openblas", openblas) ; ("ursearch" ; ,(origin ; (method git-fetch) ; (uri (git-reference ; (url "https://github.com/unum-cloud/usearch") ; (recursive? #t) ; (commit "v2.11.4"))) ; (sha256 ; (base32 "0l4gm6z5dal3146izqs7x82yf3sh4bsfwa9rkmnm2m4yc2snfbhp")) ; ) ; ))) ) ) ; (native-inputs (list git-minimal)) (home-page "https://github.com/leejet/stable-diffusion.cpp") (synopsis "Inference of Stable Diffusion in pure C/C++") (description "Inference of Stable Diffusion in pure C/C++") (license license:expat))) (define-public clblast (package (name "clblast") (version "1.6.3") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/CNugteren/CLBlast.git") (commit version) )) (file-name (git-file-name name version)) (sha256 (base32 "1zp8rfkscnh4l9x71kp39hsg5zxfhkkf88886mv40hw0a1hafdvz")) )) (build-system cmake-build-system) (arguments (list #:phases #~(modify-phases %standard-phases (delete 'check) ) )) (inputs (list opencl-clhpp opencl-icd-loader)) (home-page "https://cnugteren.github.io/clblast") (synopsis "Tuned OpenCL BLAS") (description "CLBlast is a lightweight, performant and tunable OpenCL BLAS library written in C++11. It is designed to leverage the full performance potential of a wide variety of OpenCL devices from different vendors, including desktop and laptop GPUs, embedded GPUs, and other accelerators. CLBlast implements BLAS routines: basic linear algebra subprograms operating on vectors and matrices. See the CLBlast website for performance reports on some devices.") (license license:asl2.0))) (define-public kobold-cpp (package (name "kobold-cpp") (version "1.76") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/LostRuins/koboldcpp.git") (commit (string-append "v" version)) )) (file-name (git-file-name name version)) (sha256 (base32 "155207vyxl2gh156gf0zs6ylkixrgr563cdfzkapcdhzj9lpsdfk")) )) (build-system gnu-build-system) (arguments (list #:make-flags #~(list "LLAMA_OPENBLAS=1" "LLAMA_CLBLAST=1" "LLAMA_VULKAN=1" (string-append "CC=" #$(cc-for-target)) ) #:modules '((ice-9 textual-ports) (guix build utils) ((guix build python-build-system) #:prefix python:) (guix build gnu-build-system)) #:imported-modules `(,@%default-gnu-imported-modules (guix build python-build-system)) #:phases #~(modify-phases %standard-phases ;(add-after 'unpack 'disable-unrunable-tests ; ;; test-eval-callback downloads ML model from network, cannot ; ;; run in Guix build environment ; (lambda _ ; (substitute* '("examples/eval-callback/CMakeLists.txt") ; (("add_test") "#add_test")) ; (substitute* '("examples/eval-callback/CMakeLists.txt") ; (("set_property") "#set_property")))) (add-after 'build 'install-python-scripts (lambda _ (let ((bin (string-append #$output "/bin/"))) (define (make-script script) (let ((suffix (if (string-suffix? ".py" script) "" ".py"))) (call-with-input-file (string-append script suffix) (lambda (input) (call-with-output-file (string-append bin script) (lambda (output) (format output "#!~a/bin/python3\n~a" #$(this-package-input "python") (get-string-all input)))))) (chmod (string-append bin script) #o555))) (make-script "koboldcpp.py") ;(make-script "convert-hf-to-gguf") ;(make-script "convert-llama-ggml-to-gguf") ;(make-script "convert-hf-to-gguf-update.py") ))) (add-after 'build 'install-compiled (lambda _ (mkdir-p (string-append #$output "/lib")) (mkdir-p (string-append #$output "/bin")) (for-each (lambda (f) (install-file f (string-append #$output "/lib"))) (find-files "." "\\.so$")) (for-each (lambda (f) (install-file f (string-append #$output "/bin"))) (find-files "." "\\.py$")))) ;(add-after 'install-compiled 'wrap-python-scripts ; ;(assoc-ref python:%standard-phases 'wrap) ; (add-after 'wrap-python-scripts 'wrap-for-local-libs ; (lambda _ ; (wrap-program (string-append #$output "/bin/koboldcpp.py") ; '("PATH" ":" suffix (string-append #$output "/lib/"))) ; ) ; ) (delete 'configure) (delete 'check) (delete 'install) ;Only running "make" is necssary for install. ))) (inputs (list python)) (native-inputs (list pkg-config gcc-toolchain)) (propagated-inputs (list python-numpy python-pytorch python-sentencepiece openblas clblast opencl-clhpp opencl-icd-loader vulkan-headers vulkan-loader python-gguf python-customtkinter findutils)) (properties '((tunable? . #true))) ;use AVX512, FMA, etc. when available (home-page "https://github.com/lostruins/koboldcpp") (synopsis " A simple one-file way to run various GGML and GGUF models with a KoboldAI UI.") (description "KoboldCpp is an easy-to-use AI text-generation software for GGML and GGUF models, inspired by the original KoboldAI. It's a single self-contained distributable from Concedo, that builds off llama.cpp, and adds a versatile KoboldAI API endpoint, additional format support, Stable Diffusion image generation, speech-to-text, backward compatibility, as well as a fancy UI with persistent stories, editing tools, save formats, memory, world info, author's note, characters, scenarios and everything KoboldAI and KoboldAI Lite have to offer.") (license license:agpl3))) (define-public python-gguf (package (name "python-gguf") (version "0.9.1") (source (origin (method url-fetch) (uri (pypi-uri "gguf" version)) (sha256 (base32 "0fyk7x6b2a7xjmf3q7zb61ik1yrk80xm7xx9yr2wa6avw63hkrzm")))) (build-system pyproject-build-system) (arguments '( #:phases (modify-phases %standard-phases (delete 'check) ;#TODO: see why this is broke (delete 'sanity-check) ;TODO: Fix broken sanity-check ))) (native-inputs (list poetry)) (propagated-inputs (list python-numpy python-tqdm)) (home-page "https://ggml.ai") (synopsis "Read and write ML models in GGUF for GGML") (description "Read and write ML models in GGUF for GGML.") (license #f))) (define-public python-darkdetect (package (name "python-darkdetect") (version "0.8.0") (source (origin (method url-fetch) (uri (pypi-uri "darkdetect" version)) (sha256 (base32 "1cgqgpz36dfn7hsqc29ha9pmxmzdjlwdq9aclkgbagi6f08qwhmm")))) (build-system pyproject-build-system) (arguments '( #:phases (modify-phases %standard-phases (delete 'check) ;#TODO: see why this is broke (delete 'sanity-check) ;TODO: Fix broken sanity-check ))) (home-page "") (synopsis "Detect OS Dark Mode from Python") (description "Detect OS Dark Mode from Python.") (license #f))) (define-public python-customtkinter (package (name "python-customtkinter") (version "5.2.2") (source (origin (method url-fetch) (uri (pypi-uri "customtkinter" version)) (sha256 (base32 "01yjv09r3cbdk09vamh7cdc5iqn2nj0bl383wqp9h74nzaxb73gx")))) (build-system pyproject-build-system) (arguments '( #:phases (modify-phases %standard-phases (delete 'check) ;#TODO: see why this is broke (delete 'sanity-check) ;TODO: Fix broken sanity-check ))) (propagated-inputs (list python-darkdetect python-packaging python-typing-extensions)) (home-page "https://customtkinter.tomschimansky.com") (synopsis "Create modern looking GUIs with Python") (description "Create modern looking GUIs with Python.") (license #f))) (define-public python-rubbrband (package (name "python-rubbrband") (version "0.2.19") (source (origin (method url-fetch) (uri (pypi-uri "rubbrband" version)) (sha256 (base32 "1sv7y2wvnmb0mabdbzwg0q6cf9mjkrik68dnbl3qa0slf8z7biy7")))) (build-system pyproject-build-system) (propagated-inputs (list python-pillow python-requests)) (home-page "https://github.com/rubbrband/rubbrband") (synopsis "") (description #f) (license #f)))