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
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
};
|
|
|
|
llama-python = pkgs.python310.withPackages (ps: with ps; [
|
|
|
|
torch
|
|
|
|
numpy
|
|
|
|
sentencepiece
|
|
|
|
]);
|
|
|
|
in
|
|
|
|
{
|
|
|
|
packages.default = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "llama.cpp";
|
|
|
|
src = ./.;
|
|
|
|
nativeBuildInputs = with pkgs; [ cmake ];
|
|
|
|
buildInputs = with pkgs; lib.optionals stdenv.isDarwin [
|
|
|
|
darwin.apple_sdk.frameworks.Accelerate
|
|
|
|
];
|
|
|
|
cmakeFlags = with pkgs; lib.optionals (system == "aarch64-darwin") [
|
|
|
|
"-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
|
|
|
|
];
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
2023-03-22 05:37:02 +00:00
|
|
|
mv bin/main $out/bin/llama
|
|
|
|
mv bin/quantize $out/bin/quantize
|
2023-04-08 10:04:23 +00:00
|
|
|
mv bin/embedding $out/bin/embedding
|
|
|
|
mv bin/perplexity $out/bin/perplexity
|
|
|
|
|
2023-03-17 22:03:48 +00:00
|
|
|
echo "#!${llama-python}/bin/python" > $out/bin/convert-pth-to-ggml
|
|
|
|
cat ${./convert-pth-to-ggml.py} >> $out/bin/convert-pth-to-ggml
|
|
|
|
chmod +x $out/bin/convert-pth-to-ggml
|
|
|
|
'';
|
2023-03-20 21:44:30 +00:00
|
|
|
meta.mainProgram = "llama";
|
2023-03-17 22:03:48 +00:00
|
|
|
};
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
|
|
packages = with pkgs; [
|
|
|
|
cmake
|
|
|
|
llama-python
|
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
darwin.apple_sdk.frameworks.Accelerate
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|