Skip to content

Commit 9c1ba55

Browse files
authored
build(nix): Package gguf-py (#5664)
* style: format with nixfmt/rfc101-style * build(nix): Package gguf-py * build(nix): Refactor to new scope for gguf-py * build(nix): Exclude gguf-py from devShells * build(nix): Refactor gguf-py derivation to take in exact deps * build(nix): Enable pytestCheckHook and pythonImportsCheck for gguf-py * build(python): Package python scripts with pyproject.toml * chore: Cleanup * dev(nix): Break up python/C devShells * build(python): Relax pytorch version constraint Nix has an older version * chore: Move cmake to nativeBuildInputs for devShell * fmt: Reconcile formatting with rebase * style: nix fmt * cleanup: Remove unncessary __init__.py * chore: Suggestions from review - Filter out non-source files from llama-scripts flake derivation - Clean up unused closure - Remove scripts devShell * revert: Bad changes * dev: Simplify devShells, restore the -extra devShell * build(nix): Add pyyaml for gguf-py * chore: Remove some unused bindings * dev: Add tiktoken to -extra devShells
1 parent c6d4cb4 commit 9c1ba55

9 files changed

+346
-257
lines changed

.devops/nix/devshells.nix

+46-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
1+
{ inputs, ... }:
2+
13
{
24
perSystem =
3-
{ config, lib, ... }:
5+
{
6+
config,
7+
lib,
8+
system,
9+
...
10+
}:
411
{
512
devShells =
6-
lib.concatMapAttrs
7-
(name: package: {
8-
${name} = package.passthru.shell;
9-
${name + "-extra"} = package.passthru.shell-extra;
10-
})
11-
config.packages;
13+
let
14+
pkgs = import inputs.nixpkgs { inherit system; };
15+
stdenv = pkgs.stdenv;
16+
scripts = config.packages.python-scripts;
17+
in
18+
lib.pipe (config.packages) [
19+
(lib.concatMapAttrs (
20+
name: package: {
21+
${name} = pkgs.mkShell {
22+
name = "${name}";
23+
inputsFrom = [ package ];
24+
shellHook = ''
25+
echo "Entering ${name} devShell"
26+
'';
27+
};
28+
"${name}-extra" =
29+
if (name == "python-scripts") then
30+
null
31+
else
32+
pkgs.mkShell {
33+
name = "${name}-extra";
34+
inputsFrom = [
35+
package
36+
scripts
37+
];
38+
# Extra packages that *may* be used by some scripts
39+
packages = [
40+
pkgs.python3Packages.tiktoken
41+
];
42+
shellHook = ''
43+
echo "Entering ${name} devShell"
44+
addToSearchPath "LD_LIBRARY_PATH" "${lib.getLib stdenv.cc.cc}/lib"
45+
'';
46+
};
47+
}
48+
))
49+
(lib.filterAttrs (name: value: value != null))
50+
];
1251
};
1352
}

.devops/nix/nixpkgs-instances.nix

+8-10
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@
2626
config.cudaSupport = true;
2727
config.allowUnfreePredicate =
2828
p:
29-
builtins.all
30-
(
31-
license:
32-
license.free
33-
|| builtins.elem license.shortName [
34-
"CUDA EULA"
35-
"cuDNN EULA"
36-
]
37-
)
38-
(p.meta.licenses or [ p.meta.license ]);
29+
builtins.all (
30+
license:
31+
license.free
32+
|| builtins.elem license.shortName [
33+
"CUDA EULA"
34+
"cuDNN EULA"
35+
]
36+
) (p.meta.licenses or [ p.meta.license ]);
3937
};
4038
# Ensure dependencies use ROCm consistently
4139
pkgsRocm = import inputs.nixpkgs {

.devops/nix/package-gguf-py.nix

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
lib,
3+
llamaVersion,
4+
numpy,
5+
tqdm,
6+
sentencepiece,
7+
pyyaml,
8+
poetry-core,
9+
buildPythonPackage,
10+
pytestCheckHook,
11+
}:
12+
13+
buildPythonPackage {
14+
pname = "gguf";
15+
version = llamaVersion;
16+
pyproject = true;
17+
nativeBuildInputs = [ poetry-core ];
18+
propagatedBuildInputs = [
19+
numpy
20+
tqdm
21+
sentencepiece
22+
pyyaml
23+
];
24+
src = lib.cleanSource ../../gguf-py;
25+
pythonImportsCheck = [
26+
"numpy"
27+
"gguf"
28+
];
29+
nativeCheckInputs = [ pytestCheckHook ];
30+
doCheck = true;
31+
meta = with lib; {
32+
description = "Python package for writing binary files in the GGUF format";
33+
license = licenses.mit;
34+
maintainers = [ maintainers.ditsuke ];
35+
};
36+
}

0 commit comments

Comments
 (0)