feat(packages): add llama-cpp b9645 for Strix Halo (ROCm + Vulkan)
Pin upstream llama.cpp b9645 and build it against the nixpkgs-latest input (the flake's pinned nixpkgs only carries the pre-tools/ui b8983). ROCm deps come from rocmPackages.gfx1151, so clr/rocBLAS/hipBLAS are built for gfx1151 only; clr's own build is arch-independent, so its store path stays substitutable. Vulkan on, CPU variants with znver5 / AVX-512, web UI and npm toolchain dropped. Ported from nixos-config's llm-engine.nix with two fixes: npmConfigHook hard-fails when npmDeps is null, so nodejs and the hook are stripped from nativeBuildInputs, and CMAKE_HIP_FLAGS is appended to cmakeFlagsArray because the cmake hook word-splits plain cmakeFlags. Verified on the Radeon 8060S (gfx1151): llama-bench loads both ROCm and Vulkan backends and completes pp16/tg8 runs.
This commit is contained in:
17
packages/llama-cpp/default.nix
Normal file
17
packages/llama-cpp/default.nix
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
pkgs,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
# llama.cpp b9645 is newer than the flake's pinned nixpkgs (llama-cpp b8983,
|
||||
# pre-tools/ui) and needs its UI/ROCm layout, so build against the
|
||||
# nixpkgs-latest input — same pattern as mcp-gateway/kubernetes-mcp-server.
|
||||
let
|
||||
latestPkgs = inputs.nixpkgs-latest.legacyPackages.${pkgs.stdenv.hostPlatform.system};
|
||||
in
|
||||
latestPkgs.callPackage ./package.nix {
|
||||
# Strix Halo: build the ROCm dependencies (clr, rocBLAS, hipBLAS) for gfx1151
|
||||
# only instead of every supported arch. clr's own build is arch-independent,
|
||||
# so its store path is unchanged and stays substitutable.
|
||||
rocmPackages = latestPkgs.rocmPackages.gfx1151;
|
||||
}
|
||||
117
packages/llama-cpp/package.nix
Normal file
117
packages/llama-cpp/package.nix
Normal file
@@ -0,0 +1,117 @@
|
||||
{
|
||||
lib,
|
||||
# Build skeleton: nixpkgs' own llama-cpp derivation (b-tag layout, cmake/npm
|
||||
# plumbing), retargeted at the pinned tag below.
|
||||
llama-cpp,
|
||||
fetchFromGitHub,
|
||||
rocmPackages,
|
||||
# nixpkgs-latest's nodejs/npm hooks: referenced only to strip them from
|
||||
# nativeBuildInputs (the npm/web UI build is disabled below).
|
||||
nodejs_latest,
|
||||
npmHooks,
|
||||
# Strix Halo (Radeon 8060S). clr/rocBLAS/hipBLAS come prefixed for this arch
|
||||
# by the scoped rocmPackages in ./default.nix.
|
||||
rocmGpuTargets ? [ "gfx1151" ],
|
||||
}:
|
||||
|
||||
let
|
||||
# Upstream release tag. Bump with:
|
||||
# nix flake prefetch github:ggml-org/llama.cpp/b<NNNN>
|
||||
# then update buildNumber and the src hash.
|
||||
buildNumber = "9645";
|
||||
|
||||
# HIP flags from the llm-engine.nix bring-up config. The -I paths for
|
||||
# hipBLASLt/rocWMMA are dropped because this tag's HIP backend links
|
||||
# hipBLAS/rocBLAS only; GGML_HIPBLASLT and GGML_CUDA_ENABLE_UNIFIED_MEMORY
|
||||
# are also unused by b9645 (cmake warns and ignores them).
|
||||
hipFlags = lib.concatStringsSep " " [
|
||||
"-mllvm"
|
||||
"-amdgpu-early-inline-all=true"
|
||||
"-mllvm"
|
||||
"-amdgpu-function-calls=false"
|
||||
"-mprefer-vector-width=512"
|
||||
"-famd-opt"
|
||||
"-mllvm"
|
||||
"-inline-threshold=600"
|
||||
"-mllvm"
|
||||
"-unroll-threshold=150"
|
||||
];
|
||||
in
|
||||
(llama-cpp.override {
|
||||
inherit rocmPackages rocmGpuTargets;
|
||||
rocmSupport = true;
|
||||
vulkanSupport = true;
|
||||
cudaSupport = false;
|
||||
}).overrideAttrs
|
||||
(old: {
|
||||
version = buildNumber;
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "ggml-org";
|
||||
repo = "llama.cpp";
|
||||
tag = "b${buildNumber}";
|
||||
# Tarball hash (this tag has no submodules).
|
||||
hash = "sha256-ntRwfI2/yVqi3QjQfO0ZajMFSD8r/6XPiuy0X2BhwVk=";
|
||||
};
|
||||
|
||||
# The embedded web UI is disabled via cmakeFlags, so none of the npm
|
||||
# machinery is needed: no dependency tree, and npmConfigHook hard-fails
|
||||
# when npmDeps is null, so it (and nodejs) must come off the inputs.
|
||||
npmDeps = null;
|
||||
npmRoot = null;
|
||||
npmDepsHash = null;
|
||||
nativeBuildInputs = builtins.filter (x: x != nodejs_latest && x != npmHooks.npmConfigHook) (
|
||||
old.nativeBuildInputs or [ ]
|
||||
);
|
||||
|
||||
# The release tarball has no .git; upstream wants the build id in COMMIT.
|
||||
postPatch = ''
|
||||
echo ${buildNumber} > COMMIT
|
||||
'';
|
||||
|
||||
# Replaces the base derivation's npm build step. CMAKE_HIP_FLAGS holds
|
||||
# several space-separated flags, so it must be appended as an array element:
|
||||
# plain cmakeFlags scalars are word-split by the cmake hook.
|
||||
preConfigure = ''
|
||||
prependToVar cmakeFlags "-DLLAMA_BUILD_COMMIT:STRING=$(cat COMMIT)"
|
||||
cmakeFlagsArray+=("-DCMAKE_HIP_FLAGS=${hipFlags}")
|
||||
'';
|
||||
|
||||
cmakeFlags =
|
||||
builtins.filter (f: !(builtins.isString f && builtins.match ".*LLAMA_BUILD_NUMBER.*" f != null)) (
|
||||
old.cmakeFlags or [ ]
|
||||
)
|
||||
++ [
|
||||
"-DCMAKE_C_FLAGS=-march=znver5"
|
||||
"-DCMAKE_CXX_FLAGS=-march=znver5"
|
||||
"-DGGML_CPU=ON"
|
||||
"-DGGML_AVX=ON"
|
||||
"-DGGML_AVX_VNNI=ON"
|
||||
"-DGGML_AVX2=ON"
|
||||
"-DGGML_BMI2=ON"
|
||||
"-DGGML_AVX512=ON"
|
||||
"-DGGML_AVX512_VNNI=ON"
|
||||
"-DGGML_AVX512_VBMI=ON"
|
||||
"-DGGML_AVX512_BF16=ON"
|
||||
"-DGGML_FMA=ON"
|
||||
"-DGGML_F16C=ON"
|
||||
"-DHIP_PLATFORM=amd"
|
||||
"-DGGML_CUDA_FORCE_CUBLAS=OFF"
|
||||
"-DGGML_HIPBLASLT=ON"
|
||||
"-DGGML_HIP_NO_VMM=ON"
|
||||
"-DGGML_HIP_GRAPHS=ON"
|
||||
"-DGGML_CUDA_ENABLE_UNIFIED_MEMORY=ON"
|
||||
"-DGGML_HIP_ROCWMMA_FATTN=OFF"
|
||||
"-DGGML_HIP_MMQ_MFMA=ON"
|
||||
"-DGGML_CUDA_FA_ALL_QUANTS=ON"
|
||||
"-DCMAKE_BUILD_TYPE=Release"
|
||||
"-DLLAMA_BUILD_NUMBER:STRING=${buildNumber}"
|
||||
(lib.cmakeBool "LLAMA_BUILD_UI" false)
|
||||
(lib.cmakeBool "LLAMA_USE_PREBUILT_UI" false)
|
||||
];
|
||||
|
||||
# The base's update script tracks nixpkgs' llama-cpp attr, not this pin.
|
||||
passthru = builtins.removeAttrs (old.passthru or { }) [ "updateScript" ] // {
|
||||
category = "AI Inference";
|
||||
};
|
||||
})
|
||||
Reference in New Issue
Block a user