2024-06-05 15:53:02 +00:00
{
lib ,
fetchFromGitHub ,
stdenv ,
makeWrapper ,
gitUpdater ,
python311Packages ,
tk ,
darwin ,
koboldLiteSupport ? true ,
config ,
cudaPackages ? { } ,
openblasSupport ? ! stdenv . isDarwin ,
openblas ,
cublasSupport ? config . cudaSupport ,
clblastSupport ? stdenv . isLinux ,
clblast ,
ocl-icd ,
vulkanSupport ? true ,
vulkan-loader ,
metalSupport ? stdenv . isDarwin && stdenv . isAarch64 ,
# You can find list of x86_64 options here: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
# For ARM here: https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
# If you set "march" to "native", specify "mtune" as well; otherwise, it will be set to "generic". (credit to: https://lemire.me/blog/2018/07/25/it-is-more-complicated-than-i-thought-mtune-march-in-gcc/)
# For example, if you have an AMD Ryzen CPU, you will set "march" to "x86-64" and "mtune" to "znver2"
march ? " " ,
mtune ? " " ,
} :
let
makeBool = option : bool : ( if bool then " ${ option } = 1 " else " " ) ;
effectiveStdenv = if cublasSupport then cudaPackages . backendStdenv else stdenv ;
in
effectiveStdenv . mkDerivation ( finalAttrs : {
pname = " k o b o l d c p p " ;
2024-07-01 15:47:52 +00:00
version = " 1 . 6 8 " ;
2024-06-05 15:53:02 +00:00
src = fetchFromGitHub {
owner = " L o s t R u i n s " ;
repo = " k o b o l d c p p " ;
rev = " r e f s / t a g s / v ${ finalAttrs . version } " ;
2024-07-01 15:47:52 +00:00
sha256 = " s h a 2 5 6 - z q R l Q 8 H g T 4 f m G H D 6 u x x a 2 d u Z r x 9 V h x d + g m 1 X Q 7 w 9 a y 0 = " ;
2024-06-05 15:53:02 +00:00
} ;
enableParallelBuilding = true ;
nativeBuildInputs = [
makeWrapper
python311Packages . wrapPython
] ;
pythonInputs = builtins . attrValues { inherit ( python311Packages ) tkinter customtkinter packaging ; } ;
buildInputs =
[ tk ]
++ finalAttrs . pythonInputs
++ lib . optionals effectiveStdenv . isDarwin [
darwin . apple_sdk_11_0 . frameworks . Accelerate
darwin . apple_sdk_11_0 . frameworks . CoreVideo
darwin . apple_sdk_11_0 . frameworks . CoreGraphics
darwin . apple_sdk_11_0 . frameworks . CoreServices
]
++ lib . optionals metalSupport [
darwin . apple_sdk_11_0 . frameworks . MetalKit
darwin . apple_sdk_11_0 . frameworks . Foundation
darwin . apple_sdk_11_0 . frameworks . MetalPerformanceShaders
]
++ lib . optionals openblasSupport [ openblas ]
++ lib . optionals cublasSupport [
cudaPackages . libcublas
cudaPackages . cuda_nvcc
cudaPackages . cuda_cudart
cudaPackages . cuda_cccl
]
++ lib . optionals clblastSupport [
clblast
ocl-icd
]
++ lib . optionals vulkanSupport [ vulkan-loader ] ;
pythonPath = finalAttrs . pythonInputs ;
darwinLdFlags = lib . optionals stdenv . isDarwin [
" - F ${ darwin . apple_sdk_11_0 . frameworks . CoreServices } / L i b r a r y / F r a m e w o r k s "
" - F ${ darwin . apple_sdk_11_0 . frameworks . Accelerate } / L i b r a r y / F r a m e w o r k s "
" - f r a m e w o r k C o r e S e r v i c e s "
" - f r a m e w o r k A c c e l e r a t e "
] ;
metalLdFlags = lib . optionals metalSupport [
" - F ${ darwin . apple_sdk_11_0 . frameworks . Foundation } / L i b r a r y / F r a m e w o r k s "
" - F ${ darwin . apple_sdk_11_0 . frameworks . Metal } / L i b r a r y / F r a m e w o r k s "
" - f r a m e w o r k F o u n d a t i o n "
" - f r a m e w o r k M e t a l "
] ;
env . NIX_LDFLAGS = lib . concatStringsSep " " ( finalAttrs . darwinLdFlags ++ finalAttrs . metalLdFlags ) ;
env . NIX_CFLAGS_COMPILE =
lib . optionalString ( march != " " ) " - m a r c h = ${ march } " + lib . optionalString ( mtune != " " ) " - m t u n e = ${ mtune } " ;
makeFlags = [
( makeBool " L L A M A _ O P E N B L A S " openblasSupport )
( makeBool " L L A M A _ C U B L A S " cublasSupport )
( makeBool " L L A M A _ C L B L A S T " clblastSupport )
( makeBool " L L A M A _ V U L K A N " vulkanSupport )
( makeBool " L L A M A _ M E T A L " metalSupport )
] ;
installPhase = ''
runHook preInstall
mkdir - p " $ o u t / b i n "
install - Dm755 koboldcpp . py " $ o u t / b i n / k o b o l d c p p . u n w r a p p e d "
cp * . so " $ o u t / b i n "
cp * . embd " $ o u t / b i n "
$ { lib . optionalString ( ! koboldLiteSupport ) ''
rm " $ o u t / b i n / k c p p _ d o c s . e m b d "
rm " $ o u t / b i n / k l i t e . e m b d "
'' }
runHook postInstall
'' ;
postFixup = ''
wrapPythonProgramsIn " $ o u t / b i n " " $ p y t h o n P a t h "
makeWrapper " $ o u t / b i n / k o b o l d c p p . u n w r a p p e d " " $ o u t / b i n / k o b o l d c p p " \
- - prefix PATH $ { lib . makeBinPath [ tk ] }
'' ;
passthru . updateScript = gitUpdater { rev-prefix = " v " ; } ;
meta = {
2024-06-20 14:57:18 +00:00
description = " W a y t o r u n v a r i o u s G G M L a n d G G U F m o d e l s " ;
2024-06-05 15:53:02 +00:00
license = lib . licenses . agpl3Only ;
maintainers = with lib . maintainers ; [
maxstrid
donteatoreo
] ;
mainProgram = " k o b o l d c p p " ;
platforms = lib . platforms . unix ;
} ;
} )