Skip to content

Commit

Permalink
python312Packages.llama-cpp-python: enable for Darwin (#374698)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 authored Jan 28, 2025
2 parents 1f3fb1c + 8887951 commit ef8ec64
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions pkgs/development/python-modules/llama-cpp-python/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
lib,
stdenv,
gcc13Stdenv,
buildPythonPackage,
fetchFromGitHub,
fetchpatch2,

# nativeBuildInputs
cmake,
Expand Down Expand Up @@ -33,6 +35,9 @@
cudaPackages ? { },

}:
let
stdenvTarget = if cudaSupport then gcc13Stdenv else stdenv;
in
buildPythonPackage rec {
pname = "llama-cpp-python";
version = "0.3.6";
Expand All @@ -47,6 +52,16 @@ buildPythonPackage rec {
};
# src = /home/gaetan/llama-cpp-python;

patches = [
# fix segfault when running tests due to missing default Metal devices
(fetchpatch2 {
url = "https://github.com/ggerganov/llama.cpp/commit/acd38efee316f3a5ed2e6afcbc5814807c347053.patch?full_index=1";
stripLen = 1;
extraPrefix = "vendor/llama.cpp/";
hash = "sha256-71+Lpg9z5KPlaQTX9D85KS2LXFWLQNJJ18TJyyq3/pU=";
})
];

dontUseCmakeConfigure = true;
SKBUILD_CMAKE_ARGS = lib.strings.concatStringsSep ";" (
lib.optionals cudaSupport [
Expand Down Expand Up @@ -76,6 +91,8 @@ buildPythonPackage rec {
]
);

stdenv = stdenvTarget;

dependencies = [
diskcache
jinja2
Expand All @@ -99,7 +116,11 @@ buildPythonPackage rec {

passthru = {
updateScript = gitUpdater { rev-prefix = "v"; };
tests.llama-cpp-python = llama-cpp-python.override { cudaSupport = true; };
tests = lib.optionalAttrs stdenvTarget.hostPlatform.isLinux {
withCuda = llama-cpp-python.override {
cudaSupport = true;
};
};
};

meta = {
Expand All @@ -109,12 +130,6 @@ buildPythonPackage rec {
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ kirillrdy ];
badPlatforms = [
# Segfaults during tests:
# tests/test_llama.py .Fatal Python error: Segmentation fault
# Current thread 0x00000001f3decf40 (most recent call first):
# File "/private/tmp/nix-build-python3.12-llama-cpp-python-0.3.2.drv-0/source/llama_cpp/_internals.py", line 51 in __init__
lib.systems.inspect.patterns.isDarwin

# cc1: error: unknown value ‘native+nodotprod+noi8mm+nosve’ for ‘-mcpu’
"aarch64-linux"
];
Expand Down

0 comments on commit ef8ec64

Please sign in to comment.