summaryrefslogtreecommitdiff
path: root/Biz/Bild/Deps/llama-cpp.nix
blob: 85bd778558c4c71d9778b043aea8f91992bb5e24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{ stdenv
, pkgs
, sources
, python3
, cmake
, pkgconfig
, openmpi
, cudaPackages
}:
let
  llama-python = python3.withPackages (ps: with ps; [ numpy sentencepiece ]);
in stdenv.mkDerivation {
  name = "llama.cpp";
  version = sources.llama-cpp.rev;

  src = sources.llama-cpp;

  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'
  '';

  nativeBuildInputs = [ cmake pkgconfig ];
  buildInputs = [ openmpi cudaPackages.cudatoolkit ];

  cmakeFlags = [
    "-DLLAMA_BUILD_SERVER=ON"
    "-DLLAMA_MPI=ON"
    "-DBUILD_SHARED_LIBS=ON"
    "-DCMAKE_SKIP_BUILD_RPATH=ON"
    "-DLLAMA_CUBLAS=ON"
  ];

  postInstall = ''
    mv $out/bin/main $out/bin/llama
    mv $out/bin/server $out/bin/llama-server
  '';

  meta.mainProgram = "llama";
}