-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
157 lines (157 loc) · 5.56 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{ pkgs, config, extendModules, ... }:
let
deps = config.deps;
python3 = config.python-env.deps.python;
cudaPackages = pkgs.cudaPackages_12_1;
site = python3.sitePackages;
pythonDrvs = config.python-env.pip.drvs;
inherit (pkgs) lib;
cfg = config.cog-triton; # defined in interface.nix
in
{
imports = [ ./interface.nix ];
cog.build = {
python_version = "3.10";
cog_version = "0.10.0-alpha16";
cuda = "12.1"; # todo: 12.2
gpu = true;
# inspiration: echo tensorrt_llm==0.8.0 | uv pip compile - --extra-index-url https://pypi.nvidia.com -p 3.10 --prerelease=allow --annotation-style=line
python_packages = [
"--extra-index-url"
"https://pypi.nvidia.com"
"tensorrt_llm==0.9.0"
"torch==2.2.2"
"tensorrt==9.3.0.post12.dev1"
"tensorrt-bindings==9.3.0.post12.dev1"
"tensorrt-libs==9.3.0.post12.dev1"
"nvidia-pytriton==0.5.2" # corresponds to 2.42.0
"httpx"
"nvidia-cublas-cu12<12.2"
"nvidia-cuda-nvrtc-cu12<12.2"
"nvidia-cuda-runtime-cu12<12.2"
"omegaconf"
"hf-transfer"
"tokenizers"
];
# don't ask why it needs ssh
system_packages = [ "pget" "openssh" "openmpi" ];
};
python-env.pip = {
uv.enable = true;
# todo: add some constraints to match cudaPackages
constraintsList = [
"nvidia-cudnn-cu12<9"
];
overridesList = [
"tokenizers==0.19.0"
"transformers==4.40.0"
];
};
cognix.includeNix = true;
cognix.nix.extraOptions = ''
extra-trusted-public-keys = replicate-1:rbU0MI8kgUmqLINtKfXoDkrl9NxXQMw6//+LHHDYflk=
extra-substituters = https://storage.googleapis.com/replicate-nix-cache-dev/
'';
python-env.pip.drvs = {
# tensorrt likes doing a pip invocation from it's setup.py
# circumvent by manually depending on tensorrt_libs, tensorrt_bindings
# and setting this env variable
tensorrt.env.NVIDIA_TENSORRT_DISABLE_INTERNAL_PIP = true;
# TODO remove upon next rebuild:
tensorrt.mkDerivation.propagatedBuildInputs = with pythonDrvs; [
tensorrt-libs.public
tensorrt-bindings.public
];
tensorrt-bindings.mkDerivation.propagatedBuildInputs = [ pythonDrvs.tensorrt-libs.public ];
tensorrt-libs.mkDerivation.postFixup = ''
pushd $out/${site}/tensorrt_libs
ln -s libnvinfer.so.9 libnvinfer.so
ln -s libnvonnxparser.so.9 libnvonnxparser.so
popd
'';
tensorrt-libs.env.appendRunpaths = [ "/usr/lib64" "$ORIGIN" ];
tensorrt-llm = {
mkDerivation.buildInputs = [ cudaPackages.nccl ];
mkDerivation.propagatedBuildInputs = with pythonDrvs; [
tensorrt-libs.public # libnvinfer, onnxparse
];
env.appendRunpaths = [ "/usr/lib64" "$ORIGIN" ];
env.autoPatchelfIgnoreMissingDeps = ["libcuda.so.1"];
};
# has some binaries that want cudart
tritonclient.mkDerivation.postInstall = "rm -r $out/bin";
# replace libtritonserver-90a4cf82.so with libtritonserver.so
# so backends don't have to know about the hash
nvidia-pytriton.mkDerivation.postInstall = ''
pushd $out/${site}/nvidia_pytriton.libs
ln -s libtritonserver-*.so libtritonserver.so
patchelf --replace-needed libtritonserver-*.so libtritonserver.so $out/${python3.sitePackages}/pytriton/tritonserver/bin/tritonserver
popd
pushd $out/${site}/pytriton/tritonserver/python_backend_stubs
# remove every python stub but the current python version
for d in *; do
if [ "$d" != "${python3.pythonVersion}" ]; then
rm -r $d
fi
done
popd
'';
# patch in cuda packages from nixpkgs
nvidia-cublas-cu12.mkDerivation.postInstall = ''
pushd $out/${python3.sitePackages}/nvidia/cublas/lib
for f in ./*.so.12; do
chmod +w "$f"
rm $f
ln -s ${cudaPackages.libcublas.lib}/lib/$f ./$f
done
popd
'';
nvidia-cudnn-cu12.mkDerivation.postInstall = ''
pushd $out/${python3.sitePackages}/nvidia/cudnn/lib
for f in ./*.so.8; do
chmod +w "$f"
rm $f
ln -s ${cudaPackages.cudnn.lib}/lib/$f ./$f
done
popd
'';
};
deps.backend_dir = pkgs.runCommand "triton_backends" {} ''
mkdir $out
tritonserver=${pythonDrvs.nvidia-pytriton.public}/${site}/pytriton/tritonserver
cp -r $tritonserver/backends $out/
chmod -R +w $out/backends
cp $tritonserver/python_backend_stubs/${python3.pythonVersion}/triton_python_backend_stub $out/backends/python/
cp -r ${deps.trtllm-backend}/backends/tensorrtllm $out/backends/
for f in $out/backends/tensorrtllm/*; do
chmod +w $f
patchelf --add-rpath ${pythonDrvs.nvidia-pytriton.public}/${site}/nvidia_pytriton.libs $f
done
'';
deps.tensorrt-src = pkgs.fetchFromGitHub {
owner = "NVIDIA";
repo = "TensorRT";
rev = "6d1397ed4bb65933d02725623c122a157544a729"; # release/9.3 branch
hash = "sha256-XWFyMD7jjvgIihlqCJNyH5iSa1vZCDhv1maLJqMM3UE=";
};
# todo: replace with lockfile
deps.pybind11-stubgen = python3.pkgs.buildPythonPackage rec {
pname = "pybind11-stubgen";
version = "2.5";
src = pkgs.fetchPypi {
inherit pname version;
hash = "sha256-lqf+vKski/mKvUu3LMX3KbqHsjRCR0VMF1nmPN6f7zQ=";
};
};
deps.tensorrt-llm = pkgs.callPackage ./nix/tensorrt-llm.nix {
inherit python3 cudaPackages pythonDrvs;
# TODO: turn into config option
withPython = false;
inherit (cfg) architectures;
inherit (deps) pybind11-stubgen tensorrt-src;
};
deps.trtllm-backend = pkgs.callPackage ./nix/trtllm-backend.nix {
inherit python3 cudaPackages pythonDrvs;
inherit (deps) tensorrt-llm tensorrt-src;
};
}