summaryrefslogtreecommitdiff
path: root/epistemia/packages/machine-learning.scm
blob: 7bbb9e4827e0abd5d8cae867ba1f1925a0afe8d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(define-module (epistemia packages machine-learning)
  #:use-module (guix packages)
  #:use-module (guix build-system go)
  #:use-module (guix download)
  #:use-module (guix utils)
  #:use-module (guix git-download)
  #:use-module (guix gexp)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (gnu packages base)
  #:use-module (gnu packages golang-check)
  #:use-module (gnu packages golang-web)
  #:use-module (gnu packages golang-xyz)
  #:use-module (gnu packages llvm)
  #:use-module (gnu packages machine-learning)
  #:use-module (gnu packages rocm)
  #:use-module (gnu packages rocm-libs))

(define-public llama-cpp-rocm
  (let ((tag "b9491"))
    (package
      (inherit llama-cpp)
      (name "llama-cpp-rocm")
      (version (string-append "0.0.0-" tag))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
		(url "https://github.com/ggml-org/llama.cpp")
		(commit tag)))
         (file-name (git-file-name name tag))
         (sha256
          (base32 "096rpq10ranq9yn8sk4s10myb0b7qzmq3crvv1w7mqwk1nmg0vxq"))))
      (arguments
       (substitute-keyword-arguments (package-arguments llama-cpp)
	 ((#:configure-flags flags #~'())
	  #~(append #$flags
		    '(;; CMAKE_HIP_FLAGS is to workaround regression in ROCm 7.2
		      "-DCMAKE_HIP_FLAGS=\"-mllvm --amdgpu-unroll-threshold-local=600\""
		      #$(string-append "-DGPU_TARGETS=" (current-amd-gpu-targets-string))
		      ;; temporarily disable webui building until I figure out how to add second source for hf bucket
		      "-DLLAMA_USE_PREBUILT_UI=OFF" "-DLLAMA_BUILD_UI=OFF")))
	 ((#:phases phases)
	  #~(modify-phases #$phases
	      ;; mtp added test that also needs internet for downloading its model
	      (add-after 'fix-tests 'fix-tests-new
		(lambda _
		  (substitute* "tests/CMakeLists.txt"
		    (("llama_build_and_test\\(test-state-restore-fragmented\\.cpp .*")
		     "")
		    (("set_tests_properties\\(test-state-restore-fragmented PROPERTIES.*")
		     ""))
		  (substitute* "tests/CMakeLists.txt"
		    (("llama_build_and_test\\(test-recurrent-state-rollback\\.cpp .*")
		     "")
		    (("set_tests_properties\\(test-recurrent-state-rollback PROPERTIES.*")
		     ""))
		  (substitute* "tests/CMakeLists.txt"
		    (("llama_build_and_test\\(test-save-load-state\\.cpp .*")
		     "")
		    (("set_tests_properties\\(test-save-load-state PROPERTIES.*")
		     ""))))
	      (delete 'fix-python-shebang)))))
      (inputs
       (modify-inputs (package-inputs llama-cpp)
	 (replace "ggml" ggml-rocm))))))

(define-public ggml-rocm
  (package
    (inherit ggml)
    (name "ggml-rocm")
;;    (version "0.13.1")
    (version "9ca88e98e6d9e84cf77959931130d38c5b56c19b")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
              ;; (url "https://github.com/ggml-org/ggml")
	      (url "https://git.vineetk.net/ggml")
              ;; (commit (string-append "v" version))
	      (commit version)))
       (file-name (git-file-name name version))
       (sha256
        (base32 "0llmlnkcg8zrdj6v2wpl018iw6j0sp1fsg2if3w3zd91hv66jq5r"))))
    (arguments
     (substitute-keyword-arguments (package-arguments (@@ (gnu packages machine-learning) ggml))
       ((#:configure-flags flags #~'())
	#~(append #$flags (list (string-append "-DCMAKE_HIP_COMPILER_ROCM_ROOT=" #$rocm-hip-runtime)
				(string-append "-DCMAKE_HIP_FLAGS=--rocm-path=" #$rocm-hip-runtime
					       " --rocm-device-lib-path=" #$rocm-device-libs "/amdgcn/bitcode")
				#$(string-append "-DGPU_TARGETS=" (current-amd-gpu-targets-string))
				"-DGGML_CPU=ON"
				"-DGGML_HIP=ON"
				"-DGGML_HIP_ROCWMMA_FATTN=OFF"
				"-DGGML_CUDA_FA_ALL_QUANTS=ON"
				;; for stable-diffusion.cpp
				"-DGGML_CPU_ALL_VARIANTS=ON"
				"-DGGML_MAX_NAME=128")))))
    (inputs
     (modify-inputs (package-inputs ggml)
       (append clang-rocm
	       lld-rocm
	       rocm-cmake
	       rocm-device-libs
	       rocm-hipcc
	       rocm-hip-runtime
	       rocr-runtime
	       hipblas
	       hipblas-common
	       rocblas)))))