LLaMA.cpp

  • Done
  • quality assurance status badge
Details
3 participants
  • Nicolas Goaziou
  • Bruno Victal
  • Nicolas Graves
Owner
unassigned
Submitted by
Nicolas Graves
Severity
normal
N
N
Nicolas Graves wrote on 25 Mar 2023 16:05
(address . guix-patches@gnu.org)
875yaoc1nj.fsf@ngraves.fr
Here are 3 patches introducing the LLaMA CPP implementation. Since
weights are available as torrent download, this makes the whole model
usable with a local config.

Basic information for preparing the model are available in the
README.

--
Best regards,
Nicolas Graves
N
N
Nicolas Graves wrote on 25 Mar 2023 16:32
[PATCH 1/3] gnu: Add sentencepiece.
(address . 62443@debbugs.gnu.org)(address . ngraves@ngraves.fr)
20230325153220.26027-1-ngraves@ngraves.fr
* gnu/packages/machine-learning.scm (sentencepiece): New variable.
---
gnu/packages/machine-learning.scm | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)

Toggle diff (40 lines)
diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index 37d4ef78ad..f6996af77b 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -583,6 +583,33 @@ (define openfst-for-vosk
'("--enable-shared" "--enable-far" "--enable-ngram-fsts"
"--enable-lookahead-fsts" "--with-pic" "--disable-bin")))))
+(define-public sentencepiece
+ (package
+ (name "sentencepiece")
+ (version "0.1.97")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/google/sentencepiece")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "1kzfkp2pk0vabyw3wmkh16h11chzq63mzc20ddhsag5fp6s91ajg"))))
+ (build-system cmake-build-system)
+ (arguments '(#:tests? #f))
+ (native-inputs (list gperftools))
+ (home-page "https://github.com/google/sentencepiece")
+ (synopsis "Unsupervised tokenizer for Neural Network-based text generation")
+ (description "SentencePiece is an unsupervised text tokenizer and
+detokenizer mainly for Neural Network-based text generation systems where the
+vocabulary size is predetermined prior to the neural model training.
+SentencePiece implements subword units (e.g., byte-pair-encoding
+(BPE) and unigram language model) with the extension of direct training from
+raw sentences. SentencePiece allows us to make a purely end-to-end system
+that does not depend on language-specific pre/postprocessing.")
+ (license license:asl2.0)))
+
(define-public shogun
(package
(name "shogun")
--
2.39.2
N
N
Nicolas Graves wrote on 25 Mar 2023 16:32
[PATCH 2/3] gnu: Add python-sentencepiece.
(address . 62443@debbugs.gnu.org)(address . ngraves@ngraves.fr)
20230325153220.26027-2-ngraves@ngraves.fr
* gnu/packages/machine-learning.scm (python-sentencepiece): New variable.
---
gnu/packages/machine-learning.scm | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

Toggle diff (32 lines)
diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index f6996af77b..df1989d316 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -610,6 +610,25 @@ (define-public sentencepiece
that does not depend on language-specific pre/postprocessing.")
(license license:asl2.0)))
+(define-public python-sentencepiece
+ (package
+ (name "python-sentencepiece")
+ (version "0.1.97")
+ (source
+ (origin
+ (method url-fetch)
+ (uri (pypi-uri "sentencepiece" version))
+ (sha256
+ (base32 "0v0z9ryl66432zajp099bcbnwkkldzlpjvgnjv9bq2vi19g300f9"))))
+ (build-system python-build-system)
+ (propagated-inputs (list sentencepiece))
+ (native-inputs (list pkg-config))
+ (home-page "https://github.com/google/sentencepiece")
+ (synopsis "SentencePiece python wrapper")
+ (description "This package provides a python wrapper for the SentencePiece
+unsupervised text tokenizer.")
+ (license license:asl2.0)))
+
(define-public shogun
(package
(name "shogun")
--
2.39.2
N
N
Nicolas Graves wrote on 25 Mar 2023 16:32
[PATCH 3/3] gnu: Add llama-cpp.
(address . 62443@debbugs.gnu.org)(address . ngraves@ngraves.fr)
20230325153220.26027-3-ngraves@ngraves.fr
* gnu/packages/machine-learning.scm (llama-cpp): New variable.
---
gnu/packages/machine-learning.scm | 64 +++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)

Toggle diff (77 lines)
diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index df1989d316..6c78b14fc6 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -400,6 +400,70 @@ (define-public guile-aiscm
(define-public guile-aiscm-next
(deprecated-package "guile-aiscm-next" guile-aiscm))
+(define-public llama-cpp
+ (let ((commit "3cd8dde0d1357b7f11bdd25c45d5bf5e97e284a0")
+ (revision "0"))
+ (package
+ (name "llama-cpp")
+ (version (git-version "0.0.0" revision commit))
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/ggerganov/llama.cpp")
+ (commit (string-append "master-" (string-take commit 7)))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "0i7c92cxqs31xklrn688978kk29agivgxjgvsb45wzm65gc6hm5c"))))
+ (build-system cmake-build-system)
+ (arguments
+ (list
+ #: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/" 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-pth-to-ggml")
+ (make-script "convert-gptq-to-ggml")
+ (make-script "quantize.py")
+ (substitute* (string-append bin "quantize.py")
+ (("os\\.getcwd\\(\\), quantize_script_binary")
+ (string-append "\"" bin "\", quantize_script_binary"))))))
+ (add-after 'install-python-scripts 'wrap-python-scripts
+ (assoc-ref python:%standard-phases 'wrap))
+ (replace 'install
+ (lambda _
+ (let ((bin (string-append #$output "/bin/")))
+ (install-file "bin/quantize" bin)
+ (copy-file "bin/main" (string-append bin "llama"))))))))
+ (propagated-inputs
+ (list python-pytorch python-sentencepiece python-numpy))
+ (inputs (list python))
+ (home-page "https://github.com/ggerganov/llama.cpp")
+ (synopsis "Port of Facebook's LLaMA model in C/C++")
+ (description "This package provides a port to Facebook's LLaMA collection
+of foundation language models. It requires models parameters to be downloaded
+independently to be able to run a LLaMA model.")
+ (license license:expat))))
+
(define-public mcl
(package
(name "mcl")
--
2.39.2
B
B
Bruno Victal wrote on 31 Mar 2023 01:00
control-msg
(name . control)(address . control@debbugs.gnu.org)
74912071-f536-c8bc-4711-db295b4da0e6@makinata.eu
# done with 5c131aff691fa1cb0fafe71b5f2795902ae056a7
close 55819

# control fail?
close 45449

# no longer relevant
close 33078

# tags
tags 62551 patch
tags 62503 patch
tags 62461 patch
tags 62443 patch
tags 62428 patch
tags 61226 patch
tags 59893 patch
tags 59852 patch
tags 49451 patch
tags 49207 patch
tags 44258 patch


quit
N
N
Nicolas Goaziou wrote on 8 Apr 2023 14:07
Re: [bug#62443] LLaMA.cpp
(name . Nicolas Graves via Guix-patches via)(address . guix-patches@gnu.org)
87v8i6lgqt.fsf@nicolasgoaziou.fr
Hello,

Nicolas Graves via Guix-patches via <guix-patches@gnu.org> writes:

Toggle quote (4 lines)
> Here are 3 patches introducing the LLaMA CPP implementation. Since
> weights are available as torrent download, this makes the whole model
> usable with a local config.

Applied. Thank you.

Regards,
--
Nicolas Goaziou
?