2023-03-17 23:03:48 +01: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 06:15:31 +02: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 23:03:48 +01: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 06:15:31 +02:00
|
|
|
postPatch =
|
|
|
|
if isM1 then ''
|
|
|
|
substituteInPlace ./ggml-metal.m \
|
|
|
|
--replace '[[NSBundle mainBundle] pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/ggml-metal.metal\";"
|
|
|
|
'' else "";
|
2023-03-17 23:03:48 +01:00
|
|
|
nativeBuildInputs = with pkgs; [ cmake ];
|
2023-06-07 06:15:31 +02:00
|
|
|
buildInputs = osSpecific;
|
|
|
|
cmakeFlags = [ "-DLLAMA_BUILD_SERVER=ON" ] ++ (optionals isM1 [
|
2023-03-17 23:03:48 +01:00
|
|
|
"-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
|
2023-06-07 06:15:31 +02:00
|
|
|
"-DLLAMA_METAL=ON"
|
|
|
|
]);
|
2023-03-17 23:03:48 +01:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
2023-04-13 15:49:05 +02:00
|
|
|
mv bin/* $out/bin/
|
|
|
|
mv $out/bin/main $out/bin/llama
|
2023-06-07 06:15:31 +02:00
|
|
|
mv $out/bin/server $out/bin/llama-server
|
2023-04-08 12:04:23 +02:00
|
|
|
|
2023-04-25 23:19:57 +02: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 23:03:48 +01:00
|
|
|
'';
|
2023-03-20 22:44:30 +01:00
|
|
|
meta.mainProgram = "llama";
|
2023-03-17 23:03:48 +01:00
|
|
|
};
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
|
|
packages = with pkgs; [
|
|
|
|
cmake
|
|
|
|
llama-python
|
2023-06-07 06:15:31 +02:00
|
|
|
] ++ osSpecific;
|
2023-03-17 23:03:48 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|