Skip to content

Commit

Permalink
Fix L0_backend_python/env test (#5799)
Browse files Browse the repository at this point in the history
* Fix L0_backend_python/env test

* Address comment

* Update the copyright

* Fix up
  • Loading branch information
Tabrizian authored May 18, 2023
1 parent f982ec4 commit 335cf59
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
6 changes: 3 additions & 3 deletions qa/L0_backend_python/common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
# Copyright 2021-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
Expand Down Expand Up @@ -31,7 +31,7 @@ get_shm_pages() {

install_conda() {
rm -rf ./miniconda
file_name="Miniconda3-py310_23.1.0-1-Linux-x86_64.sh"
file_name="Miniconda3-py310_23.3.1-0-Linux-x86_64.sh"
wget https://repo.anaconda.com/miniconda/$file_name

# install miniconda in silent mode
Expand Down Expand Up @@ -60,7 +60,7 @@ create_conda_env() {
env_name=$2
conda create -n $env_name python=$python_version -y
conda activate $env_name
conda install conda-pack -y
conda install -c conda-forge conda-pack -y
}

create_python_backend_stub() {
Expand Down
58 changes: 32 additions & 26 deletions qa/L0_backend_python/env/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright 2021-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
Expand Down Expand Up @@ -48,6 +48,8 @@ install_conda
create_conda_env "3.7" "python-3-7"
conda install numpy=1.20.1 -y
conda install tensorflow=2.1.0 -y
conda install -c conda-forge libstdcxx-ng=12 -y

PY37_VERSION_STRING="Python version is 3.7, NumPy version is 1.20.1, and Tensorflow version is 2.1.0"
create_python_backend_stub
conda-pack -o python3.7.tar.gz
Expand All @@ -65,6 +67,7 @@ conda deactivate
# Tensorflow 2.1.0 only works with Python 3.4 - 3.7. Successful execution of
# the Python model indicates that the environment has been setup correctly.
create_conda_env "3.6" "python-3-6"
conda install -c conda-forge libstdcxx-ng=12 -y
conda install numpy=1.18.1 -y
conda install tensorflow=2.1.0 -y
PY36_VERSION_STRING="Python version is 3.6, NumPy version is 1.18.1, and Tensorflow version is 2.1.0"
Expand All @@ -82,21 +85,23 @@ cp python3.6.tar.gz models/python_3_6/python_3_6_environment.tar.gz
cp ../../python_models/python_version/model.py ./models/python_3_6/1/
cp python_backend/builddir/triton_python_backend_stub ./models/python_3_6

# Test conda env without custom Python backend stub
# Tensorflow 2.3.0 only works with Python 3.5 - 3.8.
path_to_conda_pack='$$TRITON_MODEL_DIRECTORY/python_3_8_environment.tar.gz'
create_conda_env "3.8" "python-3-8"
conda install numpy=1.19.1 -y
conda install tensorflow=2.3.0 -y
PY38_VERSION_STRING="Python version is 3.8, NumPy version is 1.19.1, and Tensorflow version is 2.3.0"
conda-pack -o python3.8.tar.gz
mkdir -p models/python_3_8/1/
cp ../../python_models/python_version/config.pbtxt ./models/python_3_8
cp python3.8.tar.gz models/python_3_8/python_3_8_environment.tar.gz
(cd models/python_3_8 && \
sed -i "s/^name:.*/name: \"python_3_8\"/" config.pbtxt && \
# Test conda env without custom Python backend stub This environment should
# always use the default Python version shipped in the container. For Ubuntu 22.04
# it is Python 3.10 and for Ubuntu 20.04 is 3.8
path_to_conda_pack='$$TRITON_MODEL_DIRECTORY/python_3_10_environment.tar.gz'
create_conda_env "3.10" "python-3-10"
conda install -c conda-forge libstdcxx-ng=12 -y
conda install numpy=1.23.4 -y
conda install tensorflow=2.10.0 -y
PY310_VERSION_STRING="Python version is 3.10, NumPy version is 1.23.4, and Tensorflow version is 2.10.0"
conda pack -o python3.10.tar.gz
mkdir -p models/python_3_10/1/
cp ../../python_models/python_version/config.pbtxt ./models/python_3_10
cp python3.10.tar.gz models/python_3_10/python_3_10_environment.tar.gz
(cd models/python_3_10 && \
sed -i "s/^name:.*/name: \"python_3_10\"/" config.pbtxt && \
echo "parameters: {key: \"EXECUTION_ENV_PATH\", value: {string_value: \"$path_to_conda_pack\"}}" >> config.pbtxt)
cp ../../python_models/python_version/model.py ./models/python_3_8/1/
cp ../../python_models/python_version/model.py ./models/python_3_10/1/
rm -rf ./miniconda

run_server
Expand All @@ -110,7 +115,7 @@ kill $SERVER_PID
wait $SERVER_PID

set +e
for EXPECTED_VERSION_STRING in "$PY36_VERSION_STRING" "$PY37_VERSION_STRING" "$PY38_VERSION_STRING"; do
for EXPECTED_VERSION_STRING in "$PY36_VERSION_STRING" "$PY37_VERSION_STRING" "$PY310_VERSION_STRING"; do
grep "$EXPECTED_VERSION_STRING" $SERVER_LOG
if [ $? -ne 0 ]; then
cat $SERVER_LOG
Expand All @@ -130,22 +135,23 @@ if [ "$SERVER_PID" == "0" ]; then
cat $SERVER_LOG
exit 1
fi

# The environment should be extracted
curl -v -X POST localhost:8000/v2/repository/models/python_3_8/load
touch -m models/python_3_8/1/model.py
curl -v -X POST localhost:8000/v2/repository/models/python_3_10/load
touch -m models/python_3_10/1/model.py
# The environment should not be re-extracted
curl -v -X POST localhost:8000/v2/repository/models/python_3_8/load
touch -m models/python_3_8/python_3_8_environment.tar.gz
curl -v -X POST localhost:8000/v2/repository/models/python_3_10/load
touch -m models/python_3_10/python_3_10_environment.tar.gz
# The environment should be re-extracted
curl -v -X POST localhost:8000/v2/repository/models/python_3_8/load
curl -v -X POST localhost:8000/v2/repository/models/python_3_10/load

kill $SERVER_PID
wait $SERVER_PID

set +e

PY38_ENV_EXTRACTION="Extracting Python execution env"
if [ `grep -c "${PY38_ENV_EXTRACTION}" ${SERVER_LOG}` != "2" ]; then
PY310_ENV_EXTRACTION="Extracting Python execution env"
if [ `grep -c "${PY310_ENV_EXTRACTION}" ${SERVER_LOG}` != "2" ]; then
cat $SERVER_LOG
echo -e "\n***\n*** Python execution environment should be extracted exactly twice. \n***"
RET=1
Expand Down Expand Up @@ -207,8 +213,8 @@ aws s3 rm "${BUCKET_URL_SLASH}" --recursive --include "*"
# Test with EXECUTION_ENV_PATH outside the model directory
sed -i "s/TRITON_MODEL_DIRECTORY\/python_3_6_environment/TRITON_MODEL_DIRECTORY\/..\/python_3_6_environment/" models/python_3_6/config.pbtxt
mv models/python_3_6/python_3_6_environment.tar.gz models
sed -i "s/\$\$TRITON_MODEL_DIRECTORY\/python_3_8_environment/s3:\/\/triton-bucket-${CI_JOB_ID}\/python_3_8_environment/" models/python_3_8/config.pbtxt
mv models/python_3_8/python_3_8_environment.tar.gz models
sed -i "s/\$\$TRITON_MODEL_DIRECTORY\/python_3_10_environment/s3:\/\/triton-bucket-${CI_JOB_ID}\/python_3_10_environment/" models/python_3_10/config.pbtxt
mv models/python_3_10/python_3_10_environment.tar.gz models

aws s3 cp models/ "${BUCKET_URL_SLASH}" --recursive --include "*"

Expand All @@ -226,7 +232,7 @@ kill $SERVER_PID
wait $SERVER_PID

set +e
for EXPECTED_VERSION_STRING in "$PY36_VERSION_STRING" "$PY38_VERSION_STRING"; do
for EXPECTED_VERSION_STRING in "$PY36_VERSION_STRING" "$PY310_VERSION_STRING"; do
grep "$EXPECTED_VERSION_STRING" $SERVER_LOG
if [ $? -ne 0 ]; then
cat $SERVER_LOG
Expand Down

0 comments on commit 335cf59

Please sign in to comment.