-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllama-cpp.nix
78 lines (72 loc) · 2.48 KB
/
llama-cpp.nix
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
{ writeShellScriptBin
, llama-cpp
, model-pkgs
}:
let
inherit (builtins) attrNames filter foldl';
# llama-cpp commands, modes, and models to generate packages for
cmds = [ "cli" "server" ];
modes = [ "cpu" "cuda" ];
llama-cpp-supported-models =
# TODO:
# Put variables in `models` object to indicate what each model can run on
# and use that info here to generate the right list.
# For now all models in this repo are for llama-cpp so grab all of them
(filter
(s: s != "override" && s != "overrideDerivation")
(attrNames model-pkgs)
)
++ [ null ] # this generates a package without an embedded model that can be passed models at runtime
;
# package set with all combinations of llama-cpp commands, modes, and models
packages =
foldl'
(acc: cmd: acc //
(foldl'
(acc: mode: acc //
(foldl'
(acc: model: acc // (
let
overrides = if mode == "cuda" then { cudaSupport = true; } else { };
args = if model != null then "--model ${model-pkgs.${model}}" else "";
binFile =
if cmd == "cli" then
"llama"
else if cmd == "server" then
"llama-server"
else
throw "Unknown llama-cpp command: ${cmd}";
bin = "${llama-cpp.override overrides}/bin/${binFile}";
name =
if model != null then
"llama-cpp__${cmd}__${mode}__${model}" else
"llama-cpp__${cmd}__${mode}";
in
{
"${name}" = writeShellScriptBin "nix-run-llama-cpp" ''
#!/usr/bin/env bash
if ldd ${bin} | grep stubs > /dev/null 2>&1; then
# binary links to libcuda stub library, replace with local library installed with driver
# TODO: be smarter about finding / validating local libcuda
LD_PRELOAD=/lib/x86_64-linux-gnu/libcuda.so.1 ${bin} ${args} $@
else
# libcuda should be good to go
${bin} ${args} $@
fi
'';
}
))
{ }
llama-cpp-supported-models
)
)
{ }
modes
)
)
{ }
cmds;
in
{
inherit packages;
}