Files
nixpkgs/pkgs/development/python-modules/llama-cpp-python/default.nix
whispers d0b6ee2a9e python3Packages.llama-cpp-python: unpin gcc13 for cuda
this appears to no longer be necessary, as
`pkgsCuda.python3Packages.llama-cpp-python` builds fine. this helps
reduce proliferation of old compiler versions.
2026-08-12 00:04:17 -04:00

143 lines
3.2 KiB
Nix
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
lib,
stdenv,
buildPythonPackage,
fetchFromGitHub,
# nativeBuildInputs
cmake,
ninja,
autoAddDriverRunpath,
# build-system
pathspec,
pyproject-metadata,
scikit-build-core,
# dependencies
diskcache,
jinja2,
numpy,
typing-extensions,
# tests
scipy,
huggingface-hub,
# passthru
gitUpdater,
pytestCheckHook,
llama-cpp-python,
config,
cudaSupport ? config.cudaSupport,
cudaPackages ? { },
}:
buildPythonPackage rec {
pname = "llama-cpp-python";
version = "0.3.23";
pyproject = true;
src = fetchFromGitHub {
owner = "abetlen";
repo = "llama-cpp-python";
tag = "v${version}";
hash = "sha256-LqSgohfTv02RNZGMjKG0Pq2vHuIX+446uI2Q3KRmnzI=";
fetchSubmodules = true;
};
dontUseCmakeConfigure = true;
cmakeFlags = [
# Set GGML_NATIVE=off. Otherwise, cmake attempts to build with
# -march=native* which is either a no-op (if cc-wrapper is able to ignore
# it), or an attempt to build a non-reproducible binary.
#
# This issue was spotted when cmake rules appended feature modifiers to
# -mcpu, breaking linux build as follows:
#
# cc1: error: unknown value native+nodotprod+noi8mm+nosve for -mcpu
(lib.cmakeBool "GGML_NATIVE" false)
]
++ lib.optionals cudaSupport [
(lib.cmakeBool "GGML_CUDA" true)
(lib.cmakeFeature "CUDAToolkit_ROOT" "${lib.getDev cudaPackages.cuda_nvcc}")
(lib.cmakeFeature "CMAKE_CUDA_COMPILER" "${lib.getExe cudaPackages.cuda_nvcc}")
];
enableParallelBuilding = true;
nativeBuildInputs = [
cmake
ninja
]
++ lib.optionals cudaSupport [
autoAddDriverRunpath
];
build-system = [
pathspec
pyproject-metadata
scikit-build-core
];
buildInputs = lib.optionals cudaSupport (
with cudaPackages;
[
cuda_cudart # cuda_runtime.h
cccl # <thrust/*>
libcublas # cublas_v2.h
]
);
dependencies = [
diskcache
jinja2
numpy
typing-extensions
];
nativeCheckInputs = [
pytestCheckHook
scipy
huggingface-hub
];
disabledTests = [
# tries to download model from huggingface-hub
"test_real_model"
"test_real_llama"
];
pythonImportsCheck = lib.optionals (!cudaSupport) [
# `libllama.so` is loaded at import time, and failing when cudaSupport is enabled as the cuda
# driver is missing in the sandbox:
# RuntimeError: Failed to load shared library '/nix/store/...-python3.13-llama-cpp-python-0.3.16/lib/python3.13/site-packages/llama_cpp/lib/libllama.so':
# libcuda.so.1: cannot open shared object file: No such file or directory
"llama_cpp"
];
passthru = {
updateScript = gitUpdater {
rev-prefix = "v";
allowedVersions = "^[.0-9]+$";
};
tests = lib.optionalAttrs stdenv.hostPlatform.isLinux {
withCuda = llama-cpp-python.override {
cudaSupport = true;
};
};
};
meta = {
description = "Python bindings for llama.cpp";
homepage = "https://github.com/abetlen/llama-cpp-python";
changelog = "https://github.com/abetlen/llama-cpp-python/blob/v${version}/CHANGELOG.md";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [
booxter
kirillrdy
];
};
}