Skip to content
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

Have ability to split the build in CI #7076

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 88 additions & 52 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,8 @@ def dockerfile_prepare_container_linux(argmap, backends, enable_gpu, target_mach
"""

if "vllm" in backends:
# [DLIS-5606] Build Conda environment for vLLM backend
# Remove Pip install once vLLM backend moves to Conda environment.
df += """
# vLLM needed for vLLM backend
RUN pip3 install vllm=={}
Expand Down Expand Up @@ -1480,11 +1482,7 @@ def create_docker_build_script(script_name, container_install_dir, container_ci_
)
docker_script.comment()

cachefrommap = [
"tritonserver_buildbase",
"tritonserver_buildbase_cache0",
"tritonserver_buildbase_cache1",
]
cachefrommap = FLAGS.cache_from_map

baseargs = [
"docker",
Expand Down Expand Up @@ -1557,7 +1555,7 @@ def create_docker_build_script(script_name, container_install_dir, container_ci_
docker_script.cmd(["docker", "rm", "tritonserver_builder"])
else:
docker_script._file.write(
'if [ "$(docker ps -a | grep tritonserver_builder)" ]; then docker rm -f tritonserver_builder; fi\n'
'if [ ! -z $( docker ps -a --filter "name=tritonserver_builder$" -q ) ]; then docker rm tritonserver_builder; fi\n'
)

docker_script.cmd(runargs, check_exitcode=True)
Expand All @@ -1571,57 +1569,59 @@ def create_docker_build_script(script_name, container_install_dir, container_ci_
],
check_exitcode=True,
)
docker_script.cmd(
[
"docker",
"cp",
"tritonserver_builder:/tmp/tritonbuild/ci",
FLAGS.build_dir,
],
check_exitcode=True,
)

#
# Final image... tritonserver
#
docker_script.blankln()
docker_script.commentln(8)
docker_script.comment("Create final tritonserver image")
docker_script.comment()
if not FLAGS.split_build:
docker_script.cmd(
[
"docker",
"cp",
"tritonserver_builder:/tmp/tritonbuild/ci",
FLAGS.build_dir,
],
check_exitcode=True,
)

finalargs = [
"docker",
"build",
"-t",
"tritonserver",
"-f",
os.path.join(FLAGS.build_dir, "Dockerfile"),
".",
]
#
# Final image... tritonserver
#
docker_script.blankln()
docker_script.commentln(8)
docker_script.comment("Create final tritonserver image")
docker_script.comment()

docker_script.cwd(THIS_SCRIPT_DIR)
docker_script.cmd(finalargs, check_exitcode=True)
finalargs = [
"docker",
"build",
"-t",
"tritonserver",
"-f",
os.path.join(FLAGS.build_dir, "Dockerfile"),
".",
]

#
# CI base image... tritonserver_cibase
#
docker_script.blankln()
docker_script.commentln(8)
docker_script.comment("Create CI base image")
docker_script.comment()
docker_script.cwd(THIS_SCRIPT_DIR)
docker_script.cmd(finalargs, check_exitcode=True)

cibaseargs = [
"docker",
"build",
"-t",
"tritonserver_cibase",
"-f",
os.path.join(FLAGS.build_dir, "Dockerfile.cibase"),
".",
]
#
# CI base image... tritonserver_cibase
#
docker_script.blankln()
docker_script.commentln(8)
docker_script.comment("Create CI base image")
docker_script.comment()

docker_script.cwd(THIS_SCRIPT_DIR)
docker_script.cmd(cibaseargs, check_exitcode=True)
cibaseargs = [
"docker",
"build",
"-t",
"tritonserver_cibase",
"-f",
os.path.join(FLAGS.build_dir, "Dockerfile.cibase"),
".",
]

docker_script.cwd(THIS_SCRIPT_DIR)
docker_script.cmd(cibaseargs, check_exitcode=True)


def core_build(
Expand Down Expand Up @@ -2047,6 +2047,16 @@ def enable_all():
FLAGS.endpoint += [ep]


def split_cmake_script(script_name):
if target_platform() == "windows":
script_name += ".ps1"
return BuildScript(
os.path.join(FLAGS.build_dir, script_name),
verbose=FLAGS.verbose,
desc=("Build script for Triton Inference Server"),
)


if __name__ == "__main__":
parser = argparse.ArgumentParser()

Expand Down Expand Up @@ -2338,6 +2348,23 @@ def enable_all():
required=False,
help="Override specified backend CMake argument in the build as <backend>:<name>=<value>. The argument is passed to CMake as -D<name>=<value>. This flag only impacts CMake arguments that are used by build.py. To unconditionally add a CMake argument to the backend build use --extra-backend-cmake-arg.",
)
parser.add_argument(
"--split-build",
action="store_true",
required=False,
help="Split the intermediate build artifacts into independently build-able targets",
mc-nv marked this conversation as resolved.
Show resolved Hide resolved
)
parser.add_argument(
"--cache-from-map",
action="append",
required=False,
help="A set of docker images to `--cache-from` where applicable to help speedup builds",
default=[
"tritonserver_buildbase",
"tritonserver_buildbase_cache0",
"tritonserver_buildbase_cache1",
],
)
Comment on lines +2357 to +2367
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that it was called a map before, but it's really just a list. What do you think about changing this to something like --cache-image or --cache-images? We can make use of the multiple arguments in a couple of different ways. We can use the action="append" or the nargs='+' fields (SO comment for example). I might lean towards the --cache-image with action="append" API just because we have precedent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think name was used to keep consistency with original command which is relates to: docker build --cache-from

$ docker build --help | grep cache-from
      --cache-from stringArray        External cache sources (e.g., "user/app:cache", "type=local,src=path/to/dir")


FLAGS = parser.parse_args()

Expand Down Expand Up @@ -2639,9 +2666,12 @@ def enable_all():
components,
backends,
)

# Commands to build each backend...
for be in backends:
# Define function to create cmake_script with backend name as suffix
if FLAGS.split_build:
cmake_script = split_cmake_script("cmake_build_backend_" + be)

# Core backends are not built separately from core so skip...
if be in CORE_BACKENDS:
continue
Expand Down Expand Up @@ -2676,6 +2706,8 @@ def enable_all():

# Commands to build each repo agent...
for ra in repoagents:
if FLAGS.split_build:
cmake_script = split_cmake_script("cmake_build_agent_" + ra)
repo_agent_build(
ra,
cmake_script,
Expand All @@ -2687,6 +2719,8 @@ def enable_all():

# Commands to build each cache...
for cache in caches:
if FLAGS.split_build:
cmake_script = split_cmake_script("cmake_build_cache_" + cache)
cache_build(
cache,
cmake_script,
Expand All @@ -2700,6 +2734,8 @@ def enable_all():
if not FLAGS.no_container_build:
# Commands to collect all the build artifacts needed for CI
# testing.
if FLAGS.split_build:
cmake_script = split_cmake_script("cmake_build_collect")
cibase_build(
cmake_script,
script_repo_dir,
Expand Down
Loading