summaryrefslogtreecommitdiff
path: root/epistemia/packages/machine-learning.scm
blob: b3e121b9719dd00ec9f7f94d840640b2e31fbd9b (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
(define-module (epistemia packages machine-learning)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix utils)
  #:use-module (guix git-download)
  #:use-module (guix gexp)
  #: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 "b8931"))
    (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 "1bjhkmgj83z5br70j4pgz1sa1jvbc4rmxm7kca2yr4f6wxk47sgx"))))
      (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\""
		      "-DGPU_TARGETS=gfx1100")))
	 ((#:phases phases)
	  #~(modify-phases #$phases
	      ;; the test-chat test got two new extra lines that need to be removed
	      (add-after 'fix-tests 'fix-tests-new
		(lambda _
		  (substitute* "tests/CMakeLists.txt"
		    (("target_include_directories\\(test-chat PRIVATE.*")
		     "")
		    (("target_link_libraries\\(test-chat PRIVATE.*")
		     ""))))))))
      (inputs
       (modify-inputs (package-inputs llama-cpp)
	 (replace "ggml" ggml-rocm))))))

(define-public ggml-rocm
  (package
    (inherit (@@ (gnu packages machine-learning) ggml))
    (name "ggml-rocm")
    (version "0.10.0")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
              (url "https://github.com/ggml-org/ggml")
              (commit (string-append "v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32 "0pp3zsv5rckb4rr6ddd3d1qmpmg7ifzx46v932i5dndfaa8bp2yr"))))
    (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")
				"-DGPU_TARGETS=gfx1100"
				"-DGGML_HIP=ON"
				"-DGGML_HIP_ROCWMMA_FATTN=OFF"
				"-DGGML_CUDA_FA_ALL_QUANTS=ON")))))
    (inputs
     (modify-inputs (package-inputs (@@ (gnu packages machine-learning) ggml))
       (append clang-rocm
	       lld-rocm
	       rocm-cmake
	       rocm-device-libs
	       rocm-hipcc
	       rocm-hip-runtime
	       rocr-runtime
	       hipblas
	       hipblas-common
	       rocblas)))))