2023-03-17 22:03:48 +00:00
|
|
|
{
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils }:
|
|
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
|
|
let
|
2023-06-07 04:15:31 +00:00
|
|
|
inherit (pkgs.stdenv) isAarch64 isDarwin;
|
|
|
|
inherit (pkgs.lib) optionals;
|
|
|
|
isM1 = isAarch64 && isDarwin;
|
|
|
|
osSpecific =
|
|
|
|
if isM1 then with pkgs.darwin.apple_sdk_11_0.frameworks; [ Accelerate MetalKit MetalPerformanceShaders MetalPerformanceShadersGraph ]
|
|
|
|
else if isDarwin then with pkgs.darwin.apple_sdk.frameworks; [ Accelerate CoreGraphics CoreVideo ]
|
|
|
|
else [ ];
|
2023-03-17 22:03:48 +00:00
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
};
|
|
|
|
llama-python = pkgs.python310.withPackages (ps: with ps; [
|
|
|
|
numpy
|
|
|
|
sentencepiece
|
|
|
|
]);
|
|
|
|
in
|
|
|
|
{
|
|
|
|
packages.default = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "llama.cpp";
|
|
|
|
src = ./.;
|
2023-06-07 04:15:31 +00:00
|
|
|
postPatch =
|
|
|
|
if isM1 then ''
|
|
|
|
substituteInPlace ./ggml-metal.m \
|
2023-06-10 14:47:34 +00:00
|
|
|
--replace '[bundle pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/ggml-metal.metal\";"
|
2023-06-07 04:15:31 +00:00
|
|
|
'' else "";
|
2023-03-17 22:03:48 +00:00
|
|
|
nativeBuildInputs = with pkgs; [ cmake ];
|
2023-06-07 04:15:31 +00:00
|
|
|
buildInputs = osSpecific;
|
|
|
|
cmakeFlags = [ "-DLLAMA_BUILD_SERVER=ON" ] ++ (optionals isM1 [
|
2023-03-17 22:03:48 +00:00
|
|
|
"-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
|
2023-06-07 04:15:31 +00:00
|
|
|
"-DLLAMA_METAL=ON"
|
|
|
|
]);
|
2023-03-17 22:03:48 +00:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
2023-04-13 13:49:05 +00:00
|
|
|
mv bin/* $out/bin/
|
|
|
|
mv $out/bin/main $out/bin/llama
|
2023-06-07 04:15:31 +00:00
|
|
|
mv $out/bin/server $out/bin/llama-server
|
2023-04-08 10:04:23 +00:00
|
|
|
|
2023-04-25 21:19:57 +00:00
|
|
|
echo "#!${llama-python}/bin/python" > $out/bin/convert.py
|
|
|
|
cat ${./convert.py} >> $out/bin/convert.py
|
|
|
|
chmod +x $out/bin/convert.py
|
2023-03-17 22:03:48 +00:00
|
|
|
'';
|
2023-03-20 21:44:30 +00:00
|
|
|
meta.mainProgram = "llama";
|
2023-03-17 22:03:48 +00:00
|
|
|
};
|
2023-06-17 12:13:05 +00:00
|
|
|
apps.llama-server = {
|
|
|
|
type = "app";
|
|
|
|
program = "${self.packages.${system}.default}/bin/llama-server";
|
|
|
|
};
|
|
|
|
apps.llama-embedding = {
|
|
|
|
type = "app";
|
|
|
|
program = "${self.packages.${system}.default}/bin/embedding";
|
|
|
|
};
|
|
|
|
apps.llama = {
|
|
|
|
type = "app";
|
|
|
|
program = "${self.packages.${system}.default}/bin/llama";
|
|
|
|
};
|
|
|
|
apps.default = self.apps.${system}.llama;
|
2023-03-17 22:03:48 +00:00
|
|
|
devShells.default = pkgs.mkShell {
|
|
|
|
packages = with pkgs; [
|
|
|
|
cmake
|
|
|
|
llama-python
|
2023-06-07 04:15:31 +00:00
|
|
|
] ++ osSpecific;
|
2023-03-17 22:03:48 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|