63
63
suffices != [ ]
64
64
) ", accelerated with ${ strings . concatStringsSep ", " suffices } " ;
65
65
66
+ mapToPythonPackages = ps : packages : map ( package : ps . ${ package } ) packages ;
67
+
66
68
# TODO: package the Python in this repository in a Nix-like way.
67
69
# It'd be nice to migrate to buildPythonPackage, as well as ensure this repo
68
70
# is PEP 517-compatible, and ensure the correct .dist-info is generated.
69
71
# https://peps.python.org/pep-0517/
70
- llama-python = python3 . withPackages ( ps : [
71
- ps . numpy
72
- ps . sentencepiece
73
- gguf-py
74
- ] ) ;
72
+ llama-python-base-deps = [
73
+ "numpy"
74
+ "sentencepiece"
75
+ ] ;
75
76
76
77
# TODO(Green-Sky): find a better way to opt-into the heavy ml python runtime
77
- llama-python-extra = python3 . withPackages ( ps : [
78
- ps . numpy
79
- ps . sentencepiece
80
- ps . tiktoken
81
- ps . torchWithoutCuda
82
- ps . transformers
83
- ] ) ;
78
+ llama-python-full-deps = llama-python-base-deps ++ [
79
+ "tiktoken"
80
+ "torchWithoutCuda"
81
+ "transformers"
82
+ ] ;
83
+
84
+ llama-python-base-with-gguf = python3 . withPackages (
85
+ ps : ( mapToPythonPackages ps llama-python-base-deps ) ++ [ gguf-py ]
86
+ ) ;
84
87
85
88
# apple_sdk is supposed to choose sane defaults, no need to handle isAarch64
86
89
# separately
@@ -148,7 +151,7 @@ effectiveStdenv.mkDerivation (finalAttrs: {
148
151
# TODO: Package up each Python script or service appropriately.
149
152
# If we were to migrate to buildPythonPackage and prepare the `pyproject.toml`,
150
153
# we could make those *.py into setuptools' entrypoints
151
- substituteInPlace ./*.py --replace "/usr/bin/env python" "${ llama-python } /bin/python"
154
+ substituteInPlace ./*.py --replace "/usr/bin/env python" "${ llama-python-base-with-gguf } /bin/python"
152
155
'' ;
153
156
154
157
nativeBuildInputs =
@@ -233,7 +236,10 @@ effectiveStdenv.mkDerivation (finalAttrs: {
233
236
shell = mkShell {
234
237
name = "shell-${ finalAttrs . finalPackage . name } " ;
235
238
description = "contains numpy and sentencepiece" ;
236
- buildInputs = [ llama-python ] ;
239
+ buildInputs = [
240
+ python3 . withPackages
241
+ ( ps : mapToPythonPackages ps llama-python-base-deps )
242
+ ] ;
237
243
inputsFrom = [ finalAttrs . finalPackage ] ;
238
244
shellHook = ''
239
245
addToSearchPath "LD_LIBRARY_PATH" "${ lib . getLib effectiveStdenv . cc . cc } /lib"
@@ -243,7 +249,10 @@ effectiveStdenv.mkDerivation (finalAttrs: {
243
249
shell-extra = mkShell {
244
250
name = "shell-extra-${ finalAttrs . finalPackage . name } " ;
245
251
description = "contains numpy, sentencepiece, torchWithoutCuda, and transformers" ;
246
- buildInputs = [ llama-python-extra ] ;
252
+ buildInputs = [
253
+ python3 . withPackages
254
+ ( ps : mapToPythonPackages ps llama-python-full-deps )
255
+ ] ;
247
256
inputsFrom = [ finalAttrs . finalPackage ] ;
248
257
} ;
249
258
} ;
0 commit comments