-
Notifications
You must be signed in to change notification settings - Fork 12.4k
flake.nix: add missing meta, including maintainers #4633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cbf07e7
flake.nix: rewrite
philiptaron 76f348a
flake.nix: use finalPackage instead of passing it manually
SomeoneSerge b28426a
fixup! flake.nix: rewrite
SomeoneSerge d73272f
flake.nix: unclutter darwin support
SomeoneSerge fea0239
flake.nix: pass most darwin frameworks unconditionally
SomeoneSerge 34f2477
*.nix: nixfmt
SomeoneSerge 0925e7e
flake.nix: add maintainers
SomeoneSerge 0e61407
nix: move meta down to follow Nixpkgs style more closely
SomeoneSerge 5dfe9ba
nix: add missing meta attributes
SomeoneSerge 12115d6
nix: clarify the interpretation of meta.maintainers
SomeoneSerge 42c7bbe
nix: clarify the meaning of "broken" and "badPlatforms"
SomeoneSerge d98f4ab
nix: passthru: expose the use* flags for inspection
SomeoneSerge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ package, binaries }: | ||
|
||
let | ||
default = builtins.elemAt binaries 0; | ||
mkApp = name: { | ||
${name} = { | ||
type = "app"; | ||
program = "${package}/bin/${name}"; | ||
}; | ||
}; | ||
result = builtins.foldl' (acc: name: (mkApp name) // acc) { } binaries; | ||
in | ||
|
||
result // { default = result.${default}; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ concatMapAttrs, packages }: | ||
|
||
concatMapAttrs | ||
(name: package: { | ||
${name} = package.passthru.shell; | ||
${name + "-extra"} = package.passthru.shell-extra; | ||
}) | ||
packages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
final: prev: | ||
|
||
{ | ||
llama-cpp = final.callPackage ./package.nix { }; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
{ | ||
lib, | ||
config, | ||
stdenv, | ||
mkShell, | ||
cmake, | ||
ninja, | ||
pkg-config, | ||
git, | ||
python3, | ||
mpi, | ||
openblas, # TODO: Use the generic `blas` so users could switch betwen alternative implementations | ||
cudaPackages, | ||
darwin, | ||
rocmPackages, | ||
clblast, | ||
useBlas ? builtins.all (x: !x) [ | ||
useCuda | ||
useMetalKit | ||
useOpenCL | ||
useRocm | ||
], | ||
useCuda ? config.cudaSupport, | ||
useMetalKit ? stdenv.isAarch64 && stdenv.isDarwin && !useOpenCL, | ||
useOpenCL ? false, | ||
useRocm ? config.rocmSupport, | ||
}@inputs: | ||
|
||
let | ||
inherit (lib) | ||
cmakeBool | ||
cmakeFeature | ||
optionals | ||
versionOlder | ||
; | ||
|
||
# It's necessary to consistently use backendStdenv when building with CUDA support, | ||
# otherwise we get libstdc++ errors downstream. | ||
stdenv = throw "Use effectiveStdenv instead"; | ||
effectiveStdenv = if useCuda then cudaPackages.backendStdenv else inputs.stdenv; | ||
|
||
# Give a little description difference between the flavors. | ||
descriptionSuffix = | ||
if useOpenCL then | ||
" (OpenCL accelerated)" | ||
else if useCuda then | ||
" (CUDA accelerated)" | ||
else if useRocm then | ||
" (ROCm accelerated)" | ||
else if useMetalKit then | ||
" (MetalKit accelerated)" | ||
else | ||
""; | ||
|
||
# TODO: package the Python in this repository in a Nix-like way. | ||
# It'd be nice to migrate to buildPythonPackage, as well as ensure this repo | ||
# is PEP 517-compatible, and ensure the correct .dist-info is generated. | ||
# https://peps.python.org/pep-0517/ | ||
llama-python = python3.withPackages ( | ||
ps: [ | ||
ps.numpy | ||
ps.sentencepiece | ||
] | ||
); | ||
|
||
# TODO(Green-Sky): find a better way to opt-into the heavy ml python runtime | ||
llama-python-extra = python3.withPackages ( | ||
ps: [ | ||
ps.numpy | ||
ps.sentencepiece | ||
ps.torchWithoutCuda | ||
ps.transformers | ||
] | ||
); | ||
|
||
# apple_sdk is supposed to choose sane defaults, no need to handle isAarch64 | ||
# separately | ||
darwinBuildInputs = | ||
with darwin.apple_sdk.frameworks; | ||
[ | ||
Accelerate | ||
CoreVideo | ||
CoreGraphics | ||
] | ||
++ optionals useMetalKit [ MetalKit ]; | ||
|
||
cudaBuildInputs = with cudaPackages; [ | ||
cuda_cccl.dev # <nv/target> | ||
cuda_cudart | ||
libcublas | ||
]; | ||
|
||
rocmBuildInputs = with rocmPackages; [ | ||
clr | ||
hipblas | ||
rocblas | ||
]; | ||
in | ||
|
||
effectiveStdenv.mkDerivation ( | ||
finalAttrs: { | ||
name = "llama.cpp"; | ||
src = ../../.; | ||
|
||
postPatch = '' | ||
substituteInPlace ./ggml-metal.m \ | ||
--replace '[bundle pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/bin/ggml-metal.metal\";" | ||
|
||
# TODO: Package up each Python script or service appropriately. | ||
# If we were to migrate to buildPythonPackage and prepare the `pyproject.toml`, | ||
# we could make those *.py into setuptools' entrypoints | ||
substituteInPlace ./*.py --replace "/usr/bin/env python" "${llama-python}/bin/python" | ||
''; | ||
|
||
nativeBuildInputs = [ | ||
cmake | ||
ninja | ||
pkg-config | ||
git | ||
] ++ optionals useCuda [ cudaPackages.cuda_nvcc ]; | ||
|
||
buildInputs = | ||
[ mpi ] | ||
++ optionals useOpenCL [ clblast ] | ||
++ optionals useCuda cudaBuildInputs | ||
++ optionals useRocm rocmBuildInputs | ||
++ optionals effectiveStdenv.isDarwin darwinBuildInputs; | ||
|
||
cmakeFlags = | ||
[ | ||
(cmakeBool "LLAMA_NATIVE" true) | ||
(cmakeBool "LLAMA_BUILD_SERVER" true) | ||
(cmakeBool "BUILD_SHARED_LIBS" true) | ||
(cmakeBool "CMAKE_SKIP_BUILD_RPATH" true) | ||
(cmakeBool "LLAMA_METAL" useMetalKit) | ||
(cmakeBool "LLAMA_BLAS" useBlas) | ||
] | ||
++ optionals useOpenCL [ (cmakeBool "LLAMA_CLBLAST" true) ] | ||
++ optionals useCuda [ (cmakeBool "LLAMA_CUBLAS" true) ] | ||
++ optionals useRocm [ | ||
(cmakeBool "LLAMA_HIPBLAS" true) | ||
(cmakeFeature "CMAKE_C_COMPILER" "hipcc") | ||
(cmakeFeature "CMAKE_CXX_COMPILER" "hipcc") | ||
|
||
# Build all targets supported by rocBLAS. When updating search for TARGET_LIST_ROCM | ||
# in https://github.com/ROCmSoftwarePlatform/rocBLAS/blob/develop/CMakeLists.txt | ||
# and select the line that matches the current nixpkgs version of rocBLAS. | ||
# Should likely use `rocmPackages.clr.gpuTargets`. | ||
"-DAMDGPU_TARGETS=gfx803;gfx900;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack+;gfx90a:xnack-;gfx940;gfx941;gfx942;gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102" | ||
] | ||
++ optionals useMetalKit [ (lib.cmakeFeature "CMAKE_C_FLAGS" "-D__ARM_FEATURE_DOTPROD=1") ] | ||
++ optionals useBlas [ (lib.cmakeFeature "LLAMA_BLAS_VENDOR" "OpenBLAS") ]; | ||
|
||
# TODO(SomeoneSerge): It's better to add proper install targets at the CMake level, | ||
# if they haven't been added yet. | ||
postInstall = '' | ||
mv $out/bin/main $out/bin/llama | ||
mv $out/bin/server $out/bin/llama-server | ||
mkdir -p $out/include | ||
cp $src/llama.h $out/include/ | ||
''; | ||
|
||
# Define the shells here, but don't add in the inputsFrom to avoid recursion. | ||
passthru = { | ||
shell = mkShell { | ||
name = "default${descriptionSuffix}"; | ||
description = "contains numpy and sentencepiece"; | ||
buildInputs = [ llama-python ]; | ||
inputsFrom = [ finalAttrs.finalPackage ]; | ||
}; | ||
|
||
shell-extra = mkShell { | ||
name = "extra${descriptionSuffix}"; | ||
description = "contains numpy, sentencepiece, torchWithoutCuda, and transformers"; | ||
buildInputs = [ llama-python-extra ]; | ||
inputsFrom = [ finalAttrs.finalPackage ]; | ||
}; | ||
}; | ||
|
||
meta = { | ||
broken = (useCuda && effectiveStdenv.isDarwin) || (useMetalKit && !effectiveStdenv.isDarwin); | ||
description = "Inference of LLaMA model in pure C/C++${descriptionSuffix}"; | ||
homepage = "https://github.com/ggerganov/llama.cpp/"; | ||
license = lib.licenses.mit; | ||
|
||
# Accommodates `nix run` and `lib.getExe` | ||
mainProgram = "llama"; | ||
|
||
# These people might respond, on the best effort basis, if you ping them | ||
# in case of Nix-specific regressions or for reviewing Nix-specific PRs. | ||
# Consider adding yourself to this list if you want to ensure this flake | ||
# stays maintained and you're willing to invest your time. Do not add | ||
# other people without their consent. Consider removing people after | ||
# they've been unreachable for long periods of time. | ||
|
||
# Note that lib.maintainers is defined in Nixpkgs, but you may just add | ||
# an attrset following the same format as in | ||
# https://github.com/NixOS/nixpkgs/blob/f36a80e54da29775c78d7eff0e628c2b4e34d1d7/maintainers/maintainer-list.nix | ||
maintainers = with lib.maintainers; [ | ||
philiptaron | ||
SomeoneSerge | ||
]; | ||
|
||
platforms = lib.platforms.unix; | ||
}; | ||
} | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philiptaron please confirm you approve adding yourself into the list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do indeed.