Skip to content

Commit

Permalink
Add exec env build
Browse files Browse the repository at this point in the history
  • Loading branch information
kthui committed Nov 14, 2023
1 parent d126b08 commit 8d50071
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ option(TRITON_ENABLE_STATS "Include statistics collections in backend" ON)
option(TRITON_ENABLE_NVTX "Include nvtx markers collection in backend." OFF)
option(TRITON_PYTORCH_ENABLE_TORCHTRT "Enable TorchTRT support" OFF)
option(TRITON_PYTORCH_ENABLE_TORCHVISION "Enable Torchvision support" ON)
option(TRITON_PYTORCH_ENABLE_PYTHON_RUNTIME "Enable Python backend runtime support" ON)

set(TRITON_PYTORCH_DOCKER_IMAGE "" CACHE STRING "Docker image containing the PyTorch build required by backend.")
set(TRITON_PYTORCH_INCLUDE_PATHS "" CACHE PATH "Paths to Torch includes")
Expand Down Expand Up @@ -504,12 +505,16 @@ install(
${INSTALL_CONFIGDIR}
)

install(
FILES
src/model.py
DESTINATION
${CMAKE_INSTALL_PREFIX}/backends/pytorch
)
if (${TRITON_PYTORCH_ENABLE_PYTHON_RUNTIME})
install(CODE "execute_process(COMMAND bash -c ${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_pb_exec_env.sh)")
install(
FILES
src/model.py
${CMAKE_CURRENT_BINARY_DIR}/pb_exec_env_model.py.tar.gz
DESTINATION
${CMAKE_INSTALL_PREFIX}/backends/pytorch
)
endif() # TRITON_PYTORCH_ENABLE_PYTHON_RUNTIME

include(CMakePackageConfigHelpers)
configure_package_config_file(
Expand Down
52 changes: 52 additions & 0 deletions tools/gen_pb_exec_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
# Copyright 2023, 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.

# install conda
rm -rf ./miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-py310_23.3.1-0-Linux-x86_64.sh
bash Miniconda3-py310_23.3.1-0-Linux-x86_64.sh -p ./miniconda -b
eval "$(./miniconda/bin/conda shell.bash hook)"

# create conda environment
conda create -n pt python=3.10 -y
conda activate pt
conda install -c conda-forge conda-pack -y

# pre install step
export PYTHONNOUSERSITE=True
conda install -c conda-forge libstdcxx-ng=12 -y

# install PyTorch
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia -y

# pack environment
rm -f pb_exec_env_model.py.tar.gz
conda pack -o pb_exec_env_model.py.tar.gz

# deactivate conda
conda deactivate
conda deactivate

0 comments on commit 8d50071

Please sign in to comment.