flake.nix 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. {
  2. inputs = {
  3. nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  4. flake-utils.url = "github:numtide/flake-utils";
  5. };
  6. outputs = { self, nixpkgs, flake-utils }:
  7. flake-utils.lib.eachDefaultSystem (system:
  8. let
  9. pkgs = import nixpkgs {
  10. inherit system;
  11. };
  12. llama-python = pkgs.python310.withPackages (ps: with ps; [
  13. torch
  14. numpy
  15. sentencepiece
  16. ]);
  17. in
  18. {
  19. packages.default = pkgs.stdenv.mkDerivation {
  20. name = "llama.cpp";
  21. src = ./.;
  22. nativeBuildInputs = with pkgs; [ cmake ];
  23. buildInputs = with pkgs; lib.optionals stdenv.isDarwin [
  24. darwin.apple_sdk.frameworks.Accelerate
  25. ];
  26. cmakeFlags = with pkgs; lib.optionals (system == "aarch64-darwin") [
  27. "-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
  28. ];
  29. installPhase = ''
  30. mkdir -p $out/bin
  31. mv bin/main $out/bin/llama
  32. mv bin/quantize $out/bin/quantize
  33. mv bin/embedding $out/bin/embedding
  34. mv bin/perplexity $out/bin/perplexity
  35. echo "#!${llama-python}/bin/python" > $out/bin/convert-pth-to-ggml
  36. cat ${./convert-pth-to-ggml.py} >> $out/bin/convert-pth-to-ggml
  37. chmod +x $out/bin/convert-pth-to-ggml
  38. '';
  39. meta.mainProgram = "llama";
  40. };
  41. devShells.default = pkgs.mkShell {
  42. packages = with pkgs; [
  43. cmake
  44. llama-python
  45. ] ++ lib.optionals stdenv.isDarwin [
  46. darwin.apple_sdk.frameworks.Accelerate
  47. ];
  48. };
  49. }
  50. );
  51. }