-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Custom container composition script #3039
Changes from 1 commit
41a2ee1
5cf56a6
1f58666
5790f4f
d76bd6d
bdbce38
12c24f7
c1cdc3d
e1461b4
fb9fa2f
21cd7b4
4a4d49a
ad0a15b
a4734c9
d04a225
970264e
151924c
f25aaf5
4a291ed
e2b16d3
d42f956
080faea
b34a725
048bfd1
dad9be5
5382383
60fbfb5
2ac9e3d
d2639f1
f3cb329
a06784a
3165e91
5508fd9
dbea483
da3b716
344fb50
adf7e9c
32da9db
3144fba
279f9d4
8d72b6d
e1eced4
46b3be4
12b78b9
da3c92e
f3a25d2
b0748af
ad8b523
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,17 +28,10 @@ | |
import os | ||
import subprocess | ||
import sys | ||
import docker | ||
|
||
### Global variables | ||
TRITON_VERSION_MAP = { | ||
'2.12.0dev': ( | ||
'21.07dev', # triton container | ||
'21.06'), # upstream container | ||
} | ||
|
||
FLAGS = None | ||
|
||
|
||
#### helper functions | ||
def log(msg, force=False): | ||
if force or not FLAGS.quiet: | ||
|
@@ -56,12 +49,12 @@ def log_verbose(msg): | |
def fail(msg): | ||
deadeyegoodwin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print('error: {}'.format(msg), file=sys.stderr) | ||
sys.exit(1) | ||
|
||
|
||
def fail_if(p, msg): | ||
if p: | ||
fail(msg) | ||
|
||
|
||
##### create base image for gpu | ||
def start_gpu_dockerfile(ddir, argmap, dockerfile_name): | ||
|
@@ -72,15 +65,8 @@ def start_gpu_dockerfile(ddir, argmap, dockerfile_name): | |
# | ||
FROM nvcr.io/nvidia/tritonserver:{}-py3 as full | ||
FROM nvcr.io/nvidia/tritonserver:{}-py3-min | ||
ARG TRITON_VERSION={} | ||
ARG TRITON_CONTAINER_VERSION={} | ||
ENV TRITON_SERVER_VERSION ${{TRITON_VERSION}} | ||
ENV NVIDIA_TRITON_SERVER_VERSION ${{TRITON_CONTAINER_VERSION}} | ||
ENV TRITON_SERVER_VERSION ${{TRITON_VERSION}} | ||
ENV NVIDIA_TRITON_SERVER_VERSION ${{TRITON_CONTAINER_VERSION}} | ||
LABEL com.nvidia.tritonserver.version="${{TRITON_SERVER_VERSION}}" | ||
ENV PATH /opt/tritonserver/bin:${{PATH}} | ||
'''.format(argmap['TRITON_CONTAINER_VERSION'], argmap['TRITON_CONTAINER_VERSION'], argmap['TRITON_VERSION'], argmap['TRITON_CONTAINER_VERSION']) | ||
'''.format(argmap['TRITON_CONTAINER_VERSION'], | ||
argmap['TRITON_CONTAINER_VERSION']) | ||
|
||
# Copy over files | ||
df += ''' | ||
|
@@ -107,6 +93,7 @@ def start_gpu_dockerfile(ddir, argmap, dockerfile_name): | |
with open(os.path.join(ddir, dockerfile_name), "w") as dfile: | ||
dfile.write(df) | ||
|
||
|
||
### add additional backends needed | ||
def add_requested_backends(ddir, dockerfile_name, backends): | ||
df = "# Copying over backends \n" | ||
|
@@ -127,33 +114,48 @@ def add_requested_repoagents(ddir, dockerfile_name, repoagents): | |
with open(os.path.join(ddir, dockerfile_name), "a") as dfile: | ||
dfile.write(df) | ||
|
||
|
||
def create_argmap(container_version): | ||
upstreamDockerImage = 'nvcr.io/nvidia/tritonserver:{}-py3'.format(container_version) | ||
|
||
baseRunArgs = [ 'docker', 'inspect', '-f'] | ||
p_version = subprocess.run(baseRunArgs + ['{{range $index, $value := .Config.Env}}{{$value}} {{end}}', upstreamDockerImage], capture_output=True, text=True) | ||
upstreamDockerImage = 'nvcr.io/nvidia/tritonserver:{}-py3'.format( | ||
container_version) | ||
|
||
baseRunArgs = ['docker', 'inspect', '-f'] | ||
p_version = subprocess.run(baseRunArgs + [ | ||
'{{range $index, $value := .Config.Env}}{{$value}} {{end}}', | ||
upstreamDockerImage | ||
], | ||
capture_output=True, | ||
text=True) | ||
vars = p_version.stdout | ||
import re # parse all PATH enviroment variables | ||
import re # parse all PATH enviroment variables | ||
e = re.search("TRITON_SERVER_VERSION=([\S]{6,}) ", vars) | ||
version = "" if e == None else e.group(1) | ||
fail_if(p_version.returncode != 0 or len(version) == 0, 'docker inspect to find triton version failed') | ||
p_sha = subprocess.run(baseRunArgs + ['{{ index .Config.Labels "com.nvidia.build.ref"}}', upstreamDockerImage], capture_output=True, text=True) | ||
fail_if(p_sha.returncode != 0, 'docker inspect of upstream docker image build sha failed') | ||
p_build = subprocess.run(baseRunArgs + ['{{ index .Config.Labels "com.nvidia.build.id"}}', upstreamDockerImage], capture_output=True, text=True) | ||
fail_if(p_build.returncode != 0, 'docker inspect of upstream docker image build sha failed') | ||
|
||
fail_if(p_version.returncode != 0 or len(version) == 0, | ||
'docker inspect to find triton version failed') | ||
p_sha = subprocess.run(baseRunArgs + [ | ||
'{{ index .Config.Labels "com.nvidia.build.ref"}}', upstreamDockerImage | ||
], | ||
capture_output=True, | ||
text=True) | ||
fail_if(p_sha.returncode != 0, | ||
'docker inspect of upstream docker image build sha failed') | ||
p_build = subprocess.run(baseRunArgs + [ | ||
'{{ index .Config.Labels "com.nvidia.build.id"}}', upstreamDockerImage | ||
], | ||
capture_output=True, | ||
text=True) | ||
fail_if(p_build.returncode != 0, | ||
'docker inspect of upstream docker image build sha failed') | ||
|
||
argmap = { | ||
'NVIDIA_BUILD_REF': | ||
p_sha.stdout.rstrip(), | ||
'NVIDIA_BUILD_ID': | ||
p_build.stdout.rstrip(), | ||
'TRITON_VERSION': | ||
version, | ||
'TRITON_CONTAINER_VERSION': | ||
container_version, | ||
'NVIDIA_BUILD_REF': p_sha.stdout.rstrip(), | ||
'NVIDIA_BUILD_ID': p_build.stdout.rstrip(), | ||
'TRITON_VERSION': version, | ||
'TRITON_CONTAINER_VERSION': container_version, | ||
} | ||
return argmap | ||
|
||
|
||
# Install dependencies and run entrypoint script | ||
def end_gpu_dockerfile(ddir, dockerfile_name, argmap, backends, endpoint): | ||
import build | ||
|
@@ -183,30 +185,28 @@ def build_docker_image(ddir, dockerfile_name, container_name): | |
action="store_true", | ||
required=False, | ||
help='Enable verbose output.') | ||
parser.add_argument('--output-name', | ||
type=str, | ||
required=False, | ||
help='Name for the generated Docker image. Default is "tritonserver".') | ||
parser.add_argument( | ||
'--output-name', | ||
type=str, | ||
required=False, | ||
help='Name for the generated Docker image. Default is "tritonserver".') | ||
parser.add_argument( | ||
'--work-dir', | ||
type=str, | ||
required=False, | ||
help= | ||
'Generated dockerfiles are placed here. Default to current directory.' | ||
) | ||
'Generated dockerfiles are placed here. Default to current directory.') | ||
parser.add_argument( | ||
'--container-version', | ||
'--upstream-container-version', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just --container-version not upstream-container-version |
||
type=str, | ||
required=True, | ||
required=False, | ||
help= | ||
'The version to use for the generated Docker image. If not specified the container version will be chosen automatically based on --version value.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no --version flag, so change desc to be "... will be chosen automatically based on the repository branch." |
||
) | ||
parser.add_argument( | ||
'--enable-gpu', | ||
action="store_true", | ||
required=False, | ||
help='Generate a Triton image that supports GPU' | ||
) | ||
parser.add_argument('--enable-gpu', | ||
action="store_true", | ||
required=False, | ||
help='Generate a Triton image that supports GPU') | ||
parser.add_argument( | ||
'--backend', | ||
action='append', | ||
|
@@ -218,14 +218,22 @@ def build_docker_image(ddir, dockerfile_name, container_name): | |
'--repoagent', | ||
action='append', | ||
required=False, | ||
help='Include <repoagent-name> in the generated Docker image. The flag may be specified multiple times.') | ||
help= | ||
'Include <repoagent-name> in the generated Docker image. The flag may be specified multiple times.' | ||
) | ||
parser.add_argument( | ||
deadeyegoodwin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'--endpoint', | ||
action='append', | ||
required=False, | ||
help='Include <endpoint-name> in the generated Docker image. The flag may be specified multiple times.') | ||
help= | ||
'Include <endpoint-name> in the generated Docker image. The flag may be specified multiple times.' | ||
) | ||
FLAGS = parser.parse_args() | ||
|
||
fail_if( | ||
not FLAGS.enable_gpu, | ||
"Only GPU versions are supported right now. Add --enable-gpu to compose.py command" | ||
) | ||
|
||
if FLAGS.work_dir is None: | ||
FLAGS.work_dir = "." | ||
if FLAGS.output_name is None: | ||
|
@@ -240,9 +248,21 @@ def build_docker_image(ddir, dockerfile_name, container_name): | |
if FLAGS.endpoint is None: | ||
FLAGS.endpoint = [] | ||
|
||
deadeyegoodwin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
argmap = create_argmap(FLAGS.container_version) | ||
if FLAGS.upstream_container_version is None: | ||
# Read from TRITON_VERSION file in server repo to determine version | ||
with open('TRITON_VERSION', "r") as vfile: | ||
version = vfile.readline().strip() | ||
import build | ||
container_version, FLAGS.upstream_container_version = build.get_container_versions( | ||
version, "", FLAGS.upstream_container_version) | ||
log('version {}'.format(version)) | ||
log('upstream container version {}'.format( | ||
FLAGS.upstream_container_version)) | ||
argmap = create_argmap(FLAGS.upstream_container_version) | ||
|
||
start_gpu_dockerfile(FLAGS.work_dir, argmap, dockerfile_name) | ||
deadeyegoodwin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
add_requested_backends(FLAGS.work_dir, dockerfile_name, FLAGS.backend) | ||
add_requested_repoagents(FLAGS.work_dir, dockerfile_name, FLAGS.repoagent) | ||
end_gpu_dockerfile(FLAGS.work_dir, dockerfile_name, argmap, FLAGS.backend, FLAGS.endpoint) | ||
end_gpu_dockerfile(FLAGS.work_dir, dockerfile_name, argmap, FLAGS.backend, | ||
FLAGS.endpoint) | ||
build_docker_image(FLAGS.work_dir, dockerfile_name, FLAGS.output_name) |
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.
In python function comments go after the def, so this should be after line 689.