Skip to content

Commit a292747

Browse files
niklaskorzprusnak
andauthored
Nix flake (#40)
* Nix flake * Nix: only add Accelerate framework on macOS * Nix: development shel, direnv and compatibility * Nix: use python packages supplied by withPackages * Nix: remove channel compatibility * Nix: fix ARM neon dotproduct on macOS --------- Co-authored-by: Pavol Rusnak <[email protected]>
1 parent c9f670a commit a292747

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ models/*
1818

1919
/main
2020
/quantize
21+
/result
2122

2223
arm_neon.h
2324
compile_commands.json
25+
26+
.envrc
27+
.direnv/

flake.lock

+43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
4+
flake-utils.url = "github:numtide/flake-utils";
5+
};
6+
outputs = { self, nixpkgs, flake-utils }:
7+
flake-utils.lib.eachDefaultSystem (system:
8+
let
9+
pkgs = import nixpkgs {
10+
inherit system;
11+
};
12+
llama-python = pkgs.python310.withPackages (ps: with ps; [
13+
torch
14+
numpy
15+
sentencepiece
16+
]);
17+
in
18+
{
19+
packages.default = pkgs.stdenv.mkDerivation {
20+
name = "llama.cpp";
21+
src = ./.;
22+
nativeBuildInputs = with pkgs; [ cmake ];
23+
buildInputs = with pkgs; lib.optionals stdenv.isDarwin [
24+
darwin.apple_sdk.frameworks.Accelerate
25+
];
26+
cmakeFlags = with pkgs; lib.optionals (system == "aarch64-darwin") [
27+
"-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
28+
];
29+
installPhase = ''
30+
mkdir -p $out/bin
31+
mv llama $out/bin/llama
32+
mv quantize $out/bin/quantize
33+
echo "#!${llama-python}/bin/python" > $out/bin/convert-pth-to-ggml
34+
cat ${./convert-pth-to-ggml.py} >> $out/bin/convert-pth-to-ggml
35+
chmod +x $out/bin/convert-pth-to-ggml
36+
'';
37+
};
38+
devShells.default = pkgs.mkShell {
39+
packages = with pkgs; [
40+
cmake
41+
llama-python
42+
] ++ lib.optionals stdenv.isDarwin [
43+
darwin.apple_sdk.frameworks.Accelerate
44+
];
45+
};
46+
}
47+
);
48+
}

0 commit comments

Comments
 (0)