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-23 11:57:02 +00:00
|
|
|
buildInputs = with pkgs; [ openmpi ];
|
|
|
|
osSpecific = with pkgs; buildInputs ++
|
2023-07-19 07:01:55 +00:00
|
|
|
(
|
|
|
|
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-07-23 11:57:02 +00:00
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace ./ggml-metal.m \
|
|
|
|
--replace '[bundle pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/bin/ggml-metal.metal\";"
|
|
|
|
substituteInPlace ./*.py --replace '/usr/bin/env python' '${llama-python}/bin/python'
|
|
|
|
'';
|
|
|
|
postInstall = ''
|
|
|
|
mv $out/bin/main $out/bin/llama
|
|
|
|
mv $out/bin/server $out/bin/llama-server
|
|
|
|
'';
|
|
|
|
cmakeFlags = [ "-DLLAMA_BUILD_SERVER=ON" "-DLLAMA_MPI=ON" "-DBUILD_SHARED_LIBS=ON" "-DCMAKE_SKIP_BUILD_RPATH=ON" ];
|
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-23 11:57:02 +00:00
|
|
|
postPatch = postPatch;
|
2023-07-21 10:26:34 +00:00
|
|
|
nativeBuildInputs = nativeBuildInputs;
|
2023-06-07 04:15:31 +00:00
|
|
|
buildInputs = osSpecific;
|
2023-07-23 11:57:02 +00:00
|
|
|
cmakeFlags = cmakeFlags
|
2023-07-19 07:01:55 +00:00
|
|
|
++ (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-23 11:57:02 +00:00
|
|
|
postInstall = postInstall;
|
|
|
|
meta.mainProgram = "llama";
|
|
|
|
};
|
|
|
|
packages.opencl = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "llama.cpp";
|
|
|
|
src = ./.;
|
|
|
|
postPatch = postPatch;
|
|
|
|
nativeBuildInputs = nativeBuildInputs;
|
|
|
|
buildInputs = with pkgs; buildInputs ++ [ clblast ];
|
|
|
|
cmakeFlags = cmakeFlags ++ [
|
|
|
|
"-DLLAMA_CLBLAST=ON"
|
|
|
|
];
|
|
|
|
postInstall = postInstall;
|
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
|
|
|
}
|