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-07-21 10:26:34 +00:00
|
|
|
inherit (pkgs.stdenv) isAarch32 isAarch64 isDarwin;
|
2023-07-19 07:01:55 +00:00
|
|
|
osSpecific = with pkgs; [ openmpi ] ++
|
|
|
|
(
|
|
|
|
if isAarch64 && isDarwin then
|
|
|
|
with pkgs.darwin.apple_sdk_11_0.frameworks; [
|
|
|
|
Accelerate
|
|
|
|
MetalKit
|
|
|
|
MetalPerformanceShaders
|
|
|
|
MetalPerformanceShadersGraph
|
|
|
|
]
|
|
|
|
else if isAarch32 && isDarwin then
|
|
|
|
with pkgs.darwin.apple_sdk.frameworks; [
|
|
|
|
Accelerate
|
|
|
|
CoreGraphics
|
|
|
|
CoreVideo
|
|
|
|
]
|
|
|
|
else
|
|
|
|
with pkgs; [ openblas ]
|
|
|
|
);
|
2023-06-24 11:07:08 +00:00
|
|
|
pkgs = import nixpkgs { inherit system; };
|
2023-07-21 10:26:34 +00:00
|
|
|
nativeBuildInputs = with pkgs; [ cmake pkgconfig ];
|
2023-06-24 11:07:08 +00:00
|
|
|
llama-python =
|
2023-07-21 10:26:34 +00:00
|
|
|
pkgs.python3.withPackages (ps: with ps; [ numpy sentencepiece ]);
|
2023-06-24 11:07:08 +00:00
|
|
|
in {
|
2023-03-17 22:03:48 +00:00
|
|
|
packages.default = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "llama.cpp";
|
|
|
|
src = ./.;
|
2023-07-19 07:01:55 +00:00
|
|
|
postPatch = ''
|
2023-06-24 11:07:08 +00:00
|
|
|
substituteInPlace ./ggml-metal.m \
|
|
|
|
--replace '[bundle pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/bin/ggml-metal.metal\";"
|
2023-07-21 10:26:34 +00:00
|
|
|
substituteInPlace ./*.py --replace '/usr/bin/env python' '${llama-python}/bin/python'
|
2023-07-19 07:01:55 +00:00
|
|
|
'';
|
2023-07-21 10:26:34 +00:00
|
|
|
nativeBuildInputs = nativeBuildInputs;
|
2023-06-07 04:15:31 +00:00
|
|
|
buildInputs = osSpecific;
|
2023-07-19 07:01:55 +00:00
|
|
|
cmakeFlags = [ "-DLLAMA_BUILD_SERVER=ON" "-DLLAMA_MPI=ON" "-DBUILD_SHARED_LIBS=ON" "-DCMAKE_SKIP_BUILD_RPATH=ON" ]
|
|
|
|
++ (if isAarch64 && isDarwin then [
|
|
|
|
"-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
|
|
|
|
"-DLLAMA_METAL=ON"
|
|
|
|
] else [
|
|
|
|
"-DLLAMA_BLAS=ON"
|
|
|
|
"-DLLAMA_BLAS_VENDOR=OpenBLAS"
|
2023-06-07 04:15:31 +00:00
|
|
|
]);
|
2023-07-21 10:26:34 +00:00
|
|
|
postInstall = ''
|
2023-04-13 13:49:05 +00:00
|
|
|
mv $out/bin/main $out/bin/llama
|
2023-06-07 04:15:31 +00:00
|
|
|
mv $out/bin/server $out/bin/llama-server
|
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 {
|
2023-07-21 10:26:34 +00:00
|
|
|
packages = nativeBuildInputs ++ osSpecific;
|
2023-03-17 22:03:48 +00:00
|
|
|
};
|
2023-06-24 11:07:08 +00:00
|
|
|
});
|
2023-03-17 22:03:48 +00:00
|
|
|
}
|