-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
build.py
executable file
·3069 lines (2713 loc) · 108 KB
/
build.py
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# Copyright 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import argparse
import importlib.util
import multiprocessing
import os
import os.path
import pathlib
import platform
import stat
import subprocess
import sys
from inspect import getsourcefile
import distro
import requests
#
# Build Triton Inference Server.
#
# By default build.py builds the Triton Docker image, but can also be
# used to build without Docker. See docs/build.md and --help for more
# information.
#
# The TRITON_VERSION file indicates the Triton version and
# DEFAULT_TRITON_VERSION_MAP is used to determine the corresponding container
# version and upstream container version (upstream containers are
# dependencies required by Triton). These versions may be overridden.
# Map from Triton version to corresponding container and component versions.
#
# triton version ->
# (triton container version,
# upstream container version,
# ORT version,
# ORT OpenVINO version (use None to disable OpenVINO in ORT),
# Standalone OpenVINO version,
# DCGM version
# )
#
# Currently the OpenVINO versions used in ORT and standalone must
# match because of the way dlopen works with loading the backends. If
# different versions are used then one backend or the other will
# incorrectly load the other version of the openvino libraries.
#
DEFAULT_TRITON_VERSION_MAP = {
"release_version": "2.53.0dev",
"triton_container_version": "24.12dev",
"upstream_container_version": "24.10",
"ort_version": "1.19.2",
"ort_openvino_version": "2024.4.0",
"standalone_openvino_version": "2024.4.0",
"dcgm_version": "3.2.6",
"vllm_version": "0.5.5",
"rhel_py_version": "3.12.3",
}
CORE_BACKENDS = ["ensemble"]
FLAGS = None
EXTRA_CORE_CMAKE_FLAGS = {}
OVERRIDE_CORE_CMAKE_FLAGS = {}
EXTRA_BACKEND_CMAKE_FLAGS = {}
OVERRIDE_BACKEND_CMAKE_FLAGS = {}
THIS_SCRIPT_DIR = os.path.dirname(os.path.abspath(getsourcefile(lambda: 0)))
def log(msg, force=False):
if force or not FLAGS.quiet:
try:
print(msg, file=sys.stderr)
except Exception:
print("<failed to log>", file=sys.stderr)
def log_verbose(msg):
if FLAGS.verbose:
log(msg, force=True)
def fail(msg):
fail_if(True, msg)
def fail_if(p, msg):
if p:
print("error: {}".format(msg), file=sys.stderr)
sys.exit(1)
def target_platform():
# When called by compose.py, FLAGS will be None
if FLAGS and FLAGS.target_platform is not None:
return FLAGS.target_platform
platform_string = platform.system().lower()
if platform_string == "linux":
# Need to inspect the /etc/os-release file to get
# the distribution of linux
id_like_list = distro.like().split()
if "debian" in id_like_list:
return "linux"
else:
return "rhel"
else:
return platform_string
def target_machine():
# When called by compose.py, FLAGS will be None
if FLAGS and FLAGS.target_machine is not None:
return FLAGS.target_machine
return platform.machine().lower()
def container_versions(version, container_version, upstream_container_version):
if container_version is None:
container_version = FLAGS.triton_container_version
if upstream_container_version is None:
upstream_container_version = FLAGS.upstream_container_version
return container_version, upstream_container_version
class BuildScript:
"""Utility class for writing build scripts"""
def __init__(self, filepath, desc=None, verbose=False):
self._filepath = filepath
self._file = open(self._filepath, "w")
self._verbose = verbose
self.header(desc)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
def __del__(self):
self.close()
def close(self):
if self._file is not None:
if target_platform() == "windows":
self.blankln()
self._file.write("}\n")
self._file.write("catch {\n")
self._file.write(" $_;\n")
self._file.write(" ExitWithCode 1;\n")
self._file.write("}\n")
"""Close the file"""
self._file.close()
self._file = None
st = os.stat(self._filepath)
os.chmod(self._filepath, st.st_mode | stat.S_IEXEC)
def blankln(self):
self._file.write("\n")
def commentln(self, cnt):
self._file.write("#" * cnt + "\n")
def comment(self, msg=""):
if not isinstance(msg, str):
try:
for m in msg:
self._file.write(f"# {msg}\n")
return
except TypeError:
pass
self._file.write(f"# {msg}\n")
def comment_verbose(self, msg=""):
if self._verbose:
self.comment(msg)
def header(self, desc=None):
if target_platform() != "windows":
self._file.write("#!/usr/bin/env bash\n\n")
if desc is not None:
self.comment()
self.comment(desc)
self.comment()
self.blankln()
self.comment("Exit script immediately if any command fails")
if target_platform() == "windows":
self._file.write("$UseStructuredOutput = $false\n")
self.blankln()
self._file.write("function ExitWithCode($exitcode) {\n")
self._file.write(" $host.SetShouldExit($exitcode)\n")
self._file.write(" exit $exitcode\n")
self._file.write("}\n")
self.blankln()
if self._verbose:
self._file.write("Set-PSDebug -Trace 1\n")
self.blankln()
self._file.write("try {\n")
else:
self._file.write("set -e\n")
if self._verbose:
self._file.write("set -x\n")
self.blankln()
def envvar_ref(self, v):
if target_platform() == "windows":
return f"${{env:{v}}}"
return f"${{{v}}}"
def cmd(self, clist, check_exitcode=False):
if isinstance(clist, str):
self._file.write(f"{clist}\n")
else:
for c in clist:
self._file.write(f"{c} ")
self.blankln()
if check_exitcode:
if target_platform() == "windows":
self._file.write("if ($LASTEXITCODE -ne 0) {\n")
self._file.write(
' Write-Output "exited with status code $LASTEXITCODE";\n'
)
self._file.write(" ExitWithCode 1;\n")
self._file.write("}\n")
def cwd(self, path):
if target_platform() == "windows":
self.cmd(f"Set-Location -EV Err -EA Stop {path}")
else:
self.cmd(f"cd {path}")
def cp(self, src, dest):
if target_platform() == "windows":
self.cmd(f"Copy-Item -EV Err -EA Stop {src} -Destination {dest}")
else:
self.cmd(f"cp {src} {dest}")
def mkdir(self, path):
if target_platform() == "windows":
self.cmd(
f"New-Item -EV Err -EA Stop -ItemType Directory -Force -Path {path}"
)
else:
self.cmd(f"mkdir -p {pathlib.Path(path)}")
def rmdir(self, path):
if target_platform() == "windows":
self.cmd(f"if (Test-Path -Path {path}) {{")
self.cmd(f" Remove-Item -EV Err -EA Stop -Recurse -Force {path}")
self.cmd("}")
else:
self.cmd(f"rm -fr {pathlib.Path(path)}")
def cpdir(self, src, dest):
if target_platform() == "windows":
self.cmd(f"Copy-Item -EV Err -EA Stop -Recurse {src} -Destination {dest}")
else:
self.cmd(f"cp -r {src} {dest}")
def tar(self, subdir, tar_filename):
if target_platform() == "windows":
fail("unsupported operation: tar")
else:
self.cmd(f"tar zcf {tar_filename} {subdir}")
def cmake(self, args):
# Pass some additional envvars into cmake...
env_args = []
for k in ("TRT_VERSION", "CMAKE_TOOLCHAIN_FILE", "VCPKG_TARGET_TRIPLET"):
env_args += [f'"-D{k}={self.envvar_ref(k)}"']
self.cmd(f'cmake {" ".join(env_args)} {" ".join(args)}', check_exitcode=True)
def makeinstall(self, target="install"):
verbose_flag = "-v" if self._verbose else ""
self.cmd(
f"cmake --build . --config {FLAGS.build_type} -j{FLAGS.build_parallel} {verbose_flag} -t {target}"
)
def gitclone(self, repo, tag, subdir, org):
clone_dir = subdir
if not FLAGS.no_force_clone:
self.rmdir(clone_dir)
if target_platform() == "windows":
self.cmd(f"if (-Not (Test-Path -Path {clone_dir})) {{")
else:
self.cmd(f"if [[ ! -e {clone_dir} ]]; then")
# FIXME [DLIS-4045 - Currently the tag starting with "pull/" is not
# working with "--repo-tag" as the option is not forwarded to the
# individual repo build correctly.]
# If 'tag' starts with "pull/" then it must be of form
# "pull/<pr>/head". We just clone at "main" and then fetch the
# reference onto a new branch we name "tritonbuildref".
if tag.startswith("pull/"):
self.cmd(
f" git clone --recursive --depth=1 {org}/{repo}.git {subdir};",
check_exitcode=True,
)
self.cmd("}" if target_platform() == "windows" else "fi")
self.cwd(subdir)
self.cmd(f"git fetch origin {tag}:tritonbuildref", check_exitcode=True)
self.cmd(f"git checkout tritonbuildref", check_exitcode=True)
else:
self.cmd(
f" git clone --recursive --single-branch --depth=1 -b {tag} {org}/{repo}.git {subdir};",
check_exitcode=True,
)
self.cmd("}" if target_platform() == "windows" else "fi")
def cmake_core_arg(name, type, value):
# Return cmake -D setting to set name=value for core build. Use
# command-line specified value if one is given.
if name in OVERRIDE_CORE_CMAKE_FLAGS:
value = OVERRIDE_CORE_CMAKE_FLAGS[name]
if type is None:
type = ""
else:
type = ":{}".format(type)
return '"-D{}{}={}"'.format(name, type, value)
def cmake_core_enable(name, flag):
# Return cmake -D setting to set name=flag?ON:OFF for core
# build. Use command-line specified value for 'flag' if one is
# given.
if name in OVERRIDE_CORE_CMAKE_FLAGS:
value = OVERRIDE_CORE_CMAKE_FLAGS[name]
else:
value = "ON" if flag else "OFF"
return '"-D{}:BOOL={}"'.format(name, value)
def cmake_core_extra_args():
args = []
for k, v in EXTRA_CORE_CMAKE_FLAGS.items():
args.append('"-D{}={}"'.format(k, v))
return args
def cmake_backend_arg(backend, name, type, value):
# Return cmake -D setting to set name=value for backend build. Use
# command-line specified value if one is given.
if backend in OVERRIDE_BACKEND_CMAKE_FLAGS:
if name in OVERRIDE_BACKEND_CMAKE_FLAGS[backend]:
value = OVERRIDE_BACKEND_CMAKE_FLAGS[backend][name]
if type is None:
type = ""
else:
type = ":{}".format(type)
return '"-D{}{}={}"'.format(name, type, value)
def cmake_backend_enable(backend, name, flag):
# Return cmake -D setting to set name=flag?ON:OFF for backend
# build. Use command-line specified value for 'flag' if one is
# given.
value = None
if backend in OVERRIDE_BACKEND_CMAKE_FLAGS:
if name in OVERRIDE_BACKEND_CMAKE_FLAGS[backend]:
value = OVERRIDE_BACKEND_CMAKE_FLAGS[backend][name]
if value is None:
value = "ON" if flag else "OFF"
return '"-D{}:BOOL={}"'.format(name, value)
def cmake_backend_extra_args(backend):
args = []
if backend in EXTRA_BACKEND_CMAKE_FLAGS:
for k, v in EXTRA_BACKEND_CMAKE_FLAGS[backend].items():
args.append('"-D{}={}"'.format(k, v))
return args
def cmake_repoagent_arg(name, type, value):
# For now there is no override for repo-agents
if type is None:
type = ""
else:
type = ":{}".format(type)
return '"-D{}{}={}"'.format(name, type, value)
def cmake_repoagent_enable(name, flag):
# For now there is no override for repo-agents
value = "ON" if flag else "OFF"
return '"-D{}:BOOL={}"'.format(name, value)
def cmake_repoagent_extra_args():
# For now there is no extra args for repo-agents
args = []
return args
def cmake_cache_arg(name, type, value):
# For now there is no override for caches
if type is None:
type = ""
else:
type = ":{}".format(type)
return '"-D{}{}={}"'.format(name, type, value)
def cmake_cache_enable(name, flag):
# For now there is no override for caches
value = "ON" if flag else "OFF"
return '"-D{}:BOOL={}"'.format(name, value)
def cmake_cache_extra_args():
# For now there is no extra args for caches
args = []
return args
def core_cmake_args(components, backends, cmake_dir, install_dir):
cargs = [
cmake_core_arg("CMAKE_BUILD_TYPE", None, FLAGS.build_type),
cmake_core_arg("CMAKE_INSTALL_PREFIX", "PATH", install_dir),
cmake_core_arg("TRITON_VERSION", "STRING", FLAGS.version),
cmake_core_arg("TRITON_REPO_ORGANIZATION", "STRING", FLAGS.github_organization),
cmake_core_arg("TRITON_COMMON_REPO_TAG", "STRING", components["common"]),
cmake_core_arg("TRITON_CORE_REPO_TAG", "STRING", components["core"]),
cmake_core_arg("TRITON_BACKEND_REPO_TAG", "STRING", components["backend"]),
cmake_core_arg(
"TRITON_THIRD_PARTY_REPO_TAG", "STRING", components["thirdparty"]
),
]
cargs.append(cmake_core_enable("TRITON_ENABLE_LOGGING", FLAGS.enable_logging))
cargs.append(cmake_core_enable("TRITON_ENABLE_STATS", FLAGS.enable_stats))
cargs.append(cmake_core_enable("TRITON_ENABLE_METRICS", FLAGS.enable_metrics))
cargs.append(
cmake_core_enable("TRITON_ENABLE_METRICS_GPU", FLAGS.enable_gpu_metrics)
)
cargs.append(
cmake_core_enable("TRITON_ENABLE_METRICS_CPU", FLAGS.enable_cpu_metrics)
)
cargs.append(cmake_core_enable("TRITON_ENABLE_TRACING", FLAGS.enable_tracing))
cargs.append(cmake_core_enable("TRITON_ENABLE_NVTX", FLAGS.enable_nvtx))
cargs.append(cmake_core_enable("TRITON_ENABLE_GPU", FLAGS.enable_gpu))
cargs.append(
cmake_core_arg(
"TRITON_MIN_COMPUTE_CAPABILITY", None, FLAGS.min_compute_capability
)
)
cargs.append(cmake_core_enable("TRITON_ENABLE_MALI_GPU", FLAGS.enable_mali_gpu))
cargs.append(cmake_core_enable("TRITON_ENABLE_GRPC", "grpc" in FLAGS.endpoint))
cargs.append(cmake_core_enable("TRITON_ENABLE_HTTP", "http" in FLAGS.endpoint))
cargs.append(
cmake_core_enable("TRITON_ENABLE_SAGEMAKER", "sagemaker" in FLAGS.endpoint)
)
cargs.append(
cmake_core_enable("TRITON_ENABLE_VERTEX_AI", "vertex-ai" in FLAGS.endpoint)
)
cargs.append(cmake_core_enable("TRITON_ENABLE_GCS", "gcs" in FLAGS.filesystem))
cargs.append(cmake_core_enable("TRITON_ENABLE_S3", "s3" in FLAGS.filesystem))
cargs.append(
cmake_core_enable(
"TRITON_ENABLE_AZURE_STORAGE", "azure_storage" in FLAGS.filesystem
)
)
cargs.append(cmake_core_enable("TRITON_ENABLE_ENSEMBLE", "ensemble" in backends))
cargs.append(cmake_core_enable("TRITON_ENABLE_TENSORRT", "tensorrt" in backends))
cargs += cmake_core_extra_args()
cargs.append(cmake_dir)
return cargs
def repoagent_repo(ra):
return "{}_repository_agent".format(ra)
def repoagent_cmake_args(images, components, ra, install_dir):
args = []
cargs = args + [
cmake_repoagent_arg("CMAKE_BUILD_TYPE", None, FLAGS.build_type),
cmake_repoagent_arg("CMAKE_INSTALL_PREFIX", "PATH", install_dir),
cmake_repoagent_arg(
"TRITON_REPO_ORGANIZATION", "STRING", FLAGS.github_organization
),
cmake_repoagent_arg("TRITON_COMMON_REPO_TAG", "STRING", components["common"]),
cmake_repoagent_arg("TRITON_CORE_REPO_TAG", "STRING", components["core"]),
]
cargs.append(cmake_repoagent_enable("TRITON_ENABLE_GPU", FLAGS.enable_gpu))
cargs += cmake_repoagent_extra_args()
cargs.append("..")
return cargs
def cache_repo(cache):
# example: "local", or "redis"
return "{}_cache".format(cache)
def cache_cmake_args(images, components, cache, install_dir):
args = []
cargs = args + [
cmake_cache_arg("CMAKE_BUILD_TYPE", None, FLAGS.build_type),
cmake_cache_arg("CMAKE_INSTALL_PREFIX", "PATH", install_dir),
cmake_cache_arg(
"TRITON_REPO_ORGANIZATION", "STRING", FLAGS.github_organization
),
cmake_cache_arg("TRITON_COMMON_REPO_TAG", "STRING", components["common"]),
cmake_cache_arg("TRITON_CORE_REPO_TAG", "STRING", components["core"]),
]
cargs.append(cmake_cache_enable("TRITON_ENABLE_GPU", FLAGS.enable_gpu))
cargs += cmake_cache_extra_args()
cargs.append("..")
return cargs
def backend_repo(be):
return "{}_backend".format(be)
def backend_cmake_args(images, components, be, install_dir, library_paths):
cmake_build_type = FLAGS.build_type
if be == "onnxruntime":
args = onnxruntime_cmake_args(images, library_paths)
elif be == "openvino":
args = openvino_cmake_args()
elif be == "tensorflow":
args = tensorflow_cmake_args(images, library_paths)
elif be == "python":
args = []
elif be == "dali":
args = dali_cmake_args()
elif be == "pytorch":
args = pytorch_cmake_args(images)
elif be == "armnn_tflite":
args = armnn_tflite_cmake_args()
elif be == "fil":
args = fil_cmake_args(images)
# DLIS-4618: FIL backend fails debug build, so override it for now.
cmake_build_type = "Release"
elif be == "fastertransformer":
args = fastertransformer_cmake_args()
elif be == "tensorrt":
args = tensorrt_cmake_args()
elif be == "tensorrtllm":
args = tensorrtllm_cmake_args(images)
else:
args = []
cargs = args + [
cmake_backend_arg(be, "CMAKE_BUILD_TYPE", None, cmake_build_type),
cmake_backend_arg(be, "CMAKE_INSTALL_PREFIX", "PATH", install_dir),
cmake_backend_arg(
be, "TRITON_REPO_ORGANIZATION", "STRING", FLAGS.github_organization
),
cmake_backend_arg(be, "TRITON_COMMON_REPO_TAG", "STRING", components["common"]),
cmake_backend_arg(be, "TRITON_CORE_REPO_TAG", "STRING", components["core"]),
cmake_backend_arg(
be, "TRITON_BACKEND_REPO_TAG", "STRING", components["backend"]
),
]
cargs.append(cmake_backend_enable(be, "TRITON_ENABLE_GPU", FLAGS.enable_gpu))
cargs.append(
cmake_backend_enable(be, "TRITON_ENABLE_MALI_GPU", FLAGS.enable_mali_gpu)
)
cargs.append(cmake_backend_enable(be, "TRITON_ENABLE_STATS", FLAGS.enable_stats))
cargs.append(
cmake_backend_enable(be, "TRITON_ENABLE_METRICS", FLAGS.enable_metrics)
)
# [DLIS-4950] always enable below once Windows image is updated with CUPTI
# cargs.append(cmake_backend_enable(be, 'TRITON_ENABLE_MEMORY_TRACKER', True))
if (target_platform() == "windows") and (not FLAGS.no_container_build):
print(
"Warning: Detected docker build is used for Windows, backend utility 'device memory tracker' will be disabled due to missing library in CUDA Windows docker image."
)
cargs.append(cmake_backend_enable(be, "TRITON_ENABLE_MEMORY_TRACKER", False))
elif target_platform() == "igpu":
print(
"Warning: Detected iGPU build, backend utility 'device memory tracker' will be disabled as iGPU doesn't contain required version of the library."
)
cargs.append(cmake_backend_enable(be, "TRITON_ENABLE_MEMORY_TRACKER", False))
elif FLAGS.enable_gpu:
cargs.append(cmake_backend_enable(be, "TRITON_ENABLE_MEMORY_TRACKER", True))
cargs += cmake_backend_extra_args(be)
if be == "tensorrtllm":
cargs.append("-S ../inflight_batcher_llm -B .")
else:
cargs.append("..")
return cargs
def pytorch_cmake_args(images):
if "pytorch" in images:
image = images["pytorch"]
else:
image = "nvcr.io/nvidia/pytorch:{}-py3".format(FLAGS.upstream_container_version)
cargs = [
cmake_backend_arg("pytorch", "TRITON_PYTORCH_DOCKER_IMAGE", None, image),
]
# TODO: TPRD-372 TorchTRT extension is not currently supported by our manylinux build
# TODO: TPRD-373 NVTX extension is not currently supported by our manylinux build
if target_platform() != "rhel":
if FLAGS.enable_gpu:
cargs.append(
cmake_backend_enable("pytorch", "TRITON_PYTORCH_ENABLE_TORCHTRT", True)
)
cargs.append(
cmake_backend_enable("pytorch", "TRITON_ENABLE_NVTX", FLAGS.enable_nvtx)
)
return cargs
def onnxruntime_cmake_args(images, library_paths):
cargs = [
cmake_backend_arg(
"onnxruntime",
"TRITON_BUILD_ONNXRUNTIME_VERSION",
None,
os.getenv("TRITON_BUILD_ONNXRUNTIME_VERSION")
if os.getenv("TRITON_BUILD_ONNXRUNTIME_VERSION")
else FLAGS.ort_version,
)
]
# TRITON_ENABLE_GPU is already set for all backends in backend_cmake_args()
if FLAGS.enable_gpu:
# TODO: TPRD-712 TensorRT is not currently supported by our RHEL build for SBSA.
if target_platform() != "rhel" or (
target_platform() == "rhel" and target_machine() == "x86_64"
):
cargs.append(
cmake_backend_enable(
"onnxruntime", "TRITON_ENABLE_ONNXRUNTIME_TENSORRT", True
)
)
if target_platform() == "windows":
if "base" in images:
cargs.append(
cmake_backend_arg(
"onnxruntime", "TRITON_BUILD_CONTAINER", None, images["base"]
)
)
else:
if "base" in images:
cargs.append(
cmake_backend_arg(
"onnxruntime", "TRITON_BUILD_CONTAINER", None, images["base"]
)
)
else:
cargs.append(
cmake_backend_arg(
"onnxruntime",
"TRITON_BUILD_CONTAINER_VERSION",
None,
FLAGS.triton_container_version,
)
)
# TODO: TPRD-333 OpenVino extension is not currently supported by our manylinux build
if (
(target_machine() != "aarch64")
and (target_platform() != "rhel")
and (FLAGS.ort_openvino_version is not None)
):
cargs.append(
cmake_backend_enable(
"onnxruntime", "TRITON_ENABLE_ONNXRUNTIME_OPENVINO", True
)
)
cargs.append(
cmake_backend_arg(
"onnxruntime",
"TRITON_BUILD_ONNXRUNTIME_OPENVINO_VERSION",
None,
FLAGS.ort_openvino_version,
)
)
if (target_platform() == "igpu") or (target_platform() == "rhel"):
cargs.append(
cmake_backend_arg(
"onnxruntime",
"TRITON_BUILD_TARGET_PLATFORM",
None,
target_platform(),
)
)
return cargs
def openvino_cmake_args():
cargs = [
cmake_backend_arg(
"openvino",
"TRITON_BUILD_OPENVINO_VERSION",
None,
FLAGS.standalone_openvino_version,
)
]
if target_platform() == "windows":
if "base" in images:
cargs.append(
cmake_backend_arg(
"openvino", "TRITON_BUILD_CONTAINER", None, images["base"]
)
)
else:
if "base" in images:
cargs.append(
cmake_backend_arg(
"openvino", "TRITON_BUILD_CONTAINER", None, images["base"]
)
)
else:
cargs.append(
cmake_backend_arg(
"openvino",
"TRITON_BUILD_CONTAINER_VERSION",
None,
FLAGS.upstream_container_version,
)
)
return cargs
def tensorrt_cmake_args():
cargs = [
cmake_backend_enable("tensorrt", "TRITON_ENABLE_NVTX", FLAGS.enable_nvtx),
]
if target_platform() == "windows":
cargs.append(
cmake_backend_arg(
"tensorrt", "TRITON_TENSORRT_INCLUDE_PATHS", None, "c:/TensorRT/include"
)
)
return cargs
def tensorflow_cmake_args(images, library_paths):
backend_name = "tensorflow"
extra_args = []
# If a specific TF image is specified use it, otherwise pull from NGC.
if backend_name in images:
image = images[backend_name]
else:
image = "nvcr.io/nvidia/tensorflow:{}-tf2-py3".format(
FLAGS.upstream_container_version
)
extra_args = [
cmake_backend_arg(backend_name, "TRITON_TENSORFLOW_DOCKER_IMAGE", None, image)
]
return extra_args
def dali_cmake_args():
return [
cmake_backend_enable("dali", "TRITON_DALI_SKIP_DOWNLOAD", False),
]
def fil_cmake_args(images):
cargs = [cmake_backend_enable("fil", "TRITON_FIL_DOCKER_BUILD", True)]
if "base" in images:
cargs.append(
cmake_backend_arg("fil", "TRITON_BUILD_CONTAINER", None, images["base"])
)
else:
cargs.append(
cmake_backend_arg(
"fil",
"TRITON_BUILD_CONTAINER_VERSION",
None,
FLAGS.upstream_container_version,
)
)
return cargs
def armnn_tflite_cmake_args():
return [
cmake_backend_arg("armnn_tflite", "JOBS", None, multiprocessing.cpu_count()),
]
def fastertransformer_cmake_args():
print("Warning: FasterTransformer backend is not officially supported.")
cargs = [
cmake_backend_arg(
"fastertransformer", "CMAKE_EXPORT_COMPILE_COMMANDS", None, 1
),
cmake_backend_arg("fastertransformer", "ENABLE_FP8", None, "OFF"),
]
return cargs
def tensorrtllm_cmake_args(images):
cargs = []
cargs.append(cmake_backend_enable("tensorrtllm", "USE_CXX11_ABI", True))
return cargs
def install_dcgm_libraries(dcgm_version, target_machine):
if dcgm_version == "":
fail(
"unable to determine default repo-tag, DCGM version not known for {}".format(
FLAGS.version
)
)
return ""
else:
# RHEL has the same install instructions for both aarch64 and x86
if target_platform() == "rhel":
if target_machine == "aarch64":
return """
ENV DCGM_VERSION {}
# Install DCGM. Steps from https://developer.nvidia.com/dcgm#Downloads
RUN dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel8/sbsa/cuda-rhel8.repo \\
&& dnf clean expire-cache \\
&& dnf install -y datacenter-gpu-manager-{}
""".format(
dcgm_version, dcgm_version
)
else:
return """
ENV DCGM_VERSION {}
# Install DCGM. Steps from https://developer.nvidia.com/dcgm#Downloads
RUN dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo \\
&& dnf clean expire-cache \\
&& dnf install -y datacenter-gpu-manager-{}
""".format(
dcgm_version, dcgm_version
)
else:
if target_machine == "aarch64":
return """
ENV DCGM_VERSION {}
# Install DCGM. Steps from https://developer.nvidia.com/dcgm#Downloads
RUN curl -o /tmp/cuda-keyring.deb \\
https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/sbsa/cuda-keyring_1.0-1_all.deb \\
&& apt install /tmp/cuda-keyring.deb \\
&& rm /tmp/cuda-keyring.deb \\
&& apt-get update \\
&& apt-get install -y datacenter-gpu-manager=1:{}
""".format(
dcgm_version, dcgm_version
)
else:
return """
ENV DCGM_VERSION {}
# Install DCGM. Steps from https://developer.nvidia.com/dcgm#Downloads
RUN curl -o /tmp/cuda-keyring.deb \\
https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb \\
&& apt install /tmp/cuda-keyring.deb \\
&& rm /tmp/cuda-keyring.deb \\
&& apt-get update \\
&& apt-get install -y datacenter-gpu-manager=1:{}
""".format(
dcgm_version, dcgm_version
)
def create_dockerfile_buildbase_rhel(ddir, dockerfile_name, argmap):
df = """
ARG TRITON_VERSION={}
ARG TRITON_CONTAINER_VERSION={}
ARG BASE_IMAGE={}
""".format(
argmap["TRITON_VERSION"],
argmap["TRITON_CONTAINER_VERSION"],
argmap["BASE_IMAGE"],
)
df += """
FROM ${BASE_IMAGE}
ARG TRITON_VERSION
ARG TRITON_CONTAINER_VERSION
"""
df += """
# Install docker docker buildx
RUN yum install -y ca-certificates curl gnupg yum-utils \\
&& yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo \\
&& yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# && yum install -y docker.io docker-buildx-plugin
# libcurl4-openSSL-dev is needed for GCS
# python3-dev is needed by Torchvision
# python3-pip and libarchive-dev is needed by python backend
# libxml2-dev is needed for Azure Storage
# scons is needed for armnn_tflite backend build dep
RUN yum install -y \\
ca-certificates \\
autoconf \\
automake \\
git \\
gperf \\
re2-devel \\
openssl-devel \\
libtool \\
libcurl-devel \\
libb64-devel \\
gperftools-devel \\
patchelf \\
python3-pip \\
python3-setuptools \\
rapidjson-devel \\
python3-scons \\
pkg-config \\
unzip \\
wget \\
zlib-devel \\
libarchive-devel \\
libxml2-devel \\
numactl-devel \\
wget
"""
# Requires openssl-devel to be installed first for pyenv build to be successful
df += change_default_python_version_rhel(FLAGS.rhel_py_version)
df += """
RUN pip3 install --upgrade pip \\
&& pip3 install --upgrade \\
wheel \\
setuptools \\
docker \\
virtualenv
# Install boost version >= 1.78 for boost::span
# Current libboost-dev apt packages are < 1.78, so install from tar.gz
RUN wget -O /tmp/boost.tar.gz \\
https://archives.boost.io/release/1.80.0/source/boost_1_80_0.tar.gz \\
&& (cd /tmp && tar xzf boost.tar.gz) \\
&& mv /tmp/boost_1_80_0/boost /usr/include/boost
# Server build requires recent version of CMake (FetchContent required)
# Might not need this if the installed version of cmake is high enough for our build.
# RUN apt update -q=2 \\
# && apt install -y gpg wget \\
# && wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null \\
# && . /etc/os-release \\
# && echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ $UBUNTU_CODENAME main" | tee /etc/apt/sources.list.d/kitware.list >/dev/null \\
# && apt-get update -q=2 \\
# && apt-get install -y --no-install-recommends cmake=3.27.7* cmake-data=3.27.7*
"""
if FLAGS.enable_gpu:
df += install_dcgm_libraries(argmap["DCGM_VERSION"], target_machine())
df += """
ENV TRITON_SERVER_VERSION ${TRITON_VERSION}
ENV NVIDIA_TRITON_SERVER_VERSION ${TRITON_CONTAINER_VERSION}
"""