-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing for Python backend request rescheduling (#6509)
* Add testing * Fix up * Enhance testing * Fix up * Revert test changes * Add grpc endpoint test * Remove unused import * Remove unused import * Update qa/L0_backend_python/request_rescheduling/grpc_endpoint_test.py Co-authored-by: Iman Tabrizian <[email protected]> * Update qa/python_models/bls_request_rescheduling/model.py Co-authored-by: Iman Tabrizian <[email protected]> --------- Co-authored-by: Iman Tabrizian <[email protected]>
- Loading branch information
Showing
13 changed files
with
853 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
qa/L0_backend_python/request_rescheduling/grpc_endpoint_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/usr/bin/env python | ||
# 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. | ||
|
||
import sys | ||
|
||
sys.path.append("../../common") | ||
|
||
# GRPC streaming helpers.. | ||
import queue | ||
import unittest | ||
from functools import partial | ||
|
||
import numpy as np | ||
import test_util as tu | ||
import tritonclient.grpc as grpcclient | ||
from tritonclient.utils import InferenceServerException | ||
|
||
|
||
class UserData: | ||
def __init__(self): | ||
self._completed_requests = queue.Queue() | ||
|
||
|
||
def callback(user_data, result, error): | ||
if error: | ||
user_data._completed_requests.put(error) | ||
else: | ||
user_data._completed_requests.put(result) | ||
|
||
|
||
class GrpcEndpointTest(tu.TestResultCollector): | ||
def test_grpc_decoupled(self, sequence_id=0, sequence_start=False): | ||
user_data = UserData() | ||
with grpcclient.InferenceServerClient("localhost:8001") as triton_client: | ||
# Reload the model to reset the flag | ||
triton_client.unload_model("generative_sequence") | ||
triton_client.load_model("generative_sequence") | ||
|
||
triton_client.start_stream(callback=partial(callback, user_data)) | ||
inputs = [] | ||
inputs.append(grpcclient.InferInput("IN", [1], "INT32")) | ||
inputs[0].set_data_from_numpy(np.array([3], dtype=np.int32)) | ||
|
||
triton_client.async_stream_infer( | ||
model_name="generative_sequence", | ||
inputs=inputs, | ||
sequence_id=sequence_id, | ||
sequence_start=sequence_start, | ||
) | ||
res_count = 3 | ||
while res_count > 0: | ||
data_item = user_data._completed_requests.get() | ||
res_count -= 1 | ||
if type(data_item) == InferenceServerException: | ||
raise data_item | ||
else: | ||
self.assertEqual(res_count, data_item.as_numpy("OUT")[0]) | ||
self.assertEqual(0, res_count) | ||
|
||
def test_grpc_non_decoupled(self, sequence_id=0, sequence_start=False): | ||
with grpcclient.InferenceServerClient("localhost:8001") as triton_client: | ||
# Reload the model to reset the flag | ||
triton_client.unload_model("request_rescheduling_addsub") | ||
triton_client.load_model("request_rescheduling_addsub") | ||
|
||
inputs = [] | ||
inputs.append(grpcclient.InferInput("INPUT0", [16], "FP32")) | ||
inputs.append(grpcclient.InferInput("INPUT1", [16], "FP32")) | ||
input0_val = np.random.randn(*[16]).astype(np.float32) | ||
input1_val = np.random.randn(*[16]).astype(np.float32) | ||
inputs[0].set_data_from_numpy(input0_val) | ||
inputs[1].set_data_from_numpy(input1_val) | ||
|
||
results = triton_client.infer( | ||
model_name="request_rescheduling_addsub", | ||
inputs=inputs, | ||
) | ||
|
||
output0_data = results.as_numpy("OUTPUT0") | ||
output1_data = results.as_numpy("OUTPUT1") | ||
|
||
self.assertTrue(np.array_equal(output0_data, input0_val + input1_val)) | ||
self.assertTrue(np.array_equal(output1_data, input0_val - input1_val)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/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. | ||
|
||
CLIENT_PY=../python_unittest.py | ||
CLIENT_LOG="./request_rescheduling_client.log" | ||
EXPECTED_NUM_TESTS="1" | ||
TEST_RESULT_FILE='test_results.txt' | ||
source ../../common/util.sh | ||
|
||
TRITON_DIR=${TRITON_DIR:="/opt/tritonserver"} | ||
SERVER=${TRITON_DIR}/bin/tritonserver | ||
BACKEND_DIR=${TRITON_DIR}/backends | ||
|
||
RET=0 | ||
|
||
rm -fr *.log ./models *.txt | ||
|
||
mkdir -p models/bls_request_rescheduling/1/ | ||
cp ../../python_models/bls_request_rescheduling/model.py models/bls_request_rescheduling/1/ | ||
cp ../../python_models/bls_request_rescheduling/config.pbtxt models/bls_request_rescheduling | ||
|
||
mkdir -p models/request_rescheduling_addsub/1/ | ||
cp ../../python_models/request_rescheduling_addsub/model.py models/request_rescheduling_addsub/1/ | ||
cp ../../python_models/request_rescheduling_addsub/config.pbtxt models/request_rescheduling_addsub | ||
|
||
mkdir -p models/generative_sequence/1/ | ||
cp ../../python_models/generative_sequence/model.py models/generative_sequence/1/ | ||
cp ../../python_models/generative_sequence/config.pbtxt models/generative_sequence | ||
|
||
mkdir -p models/wrong_return_type/1/ | ||
cp ../../python_models/wrong_return_type/model.py models/wrong_return_type/1/ | ||
cp ../../python_models/wrong_return_type/config.pbtxt models/wrong_return_type | ||
|
||
SERVER_LOG="./request_rescheduling_server.log" | ||
SERVER_ARGS="--model-repository=`pwd`/models --backend-directory=${BACKEND_DIR} --model-control-mode=explicit --load-model=* --log-verbose=1" | ||
|
||
run_server | ||
if [ "$SERVER_PID" == "0" ]; then | ||
echo -e "\n***\n*** Failed to start $SERVER\n***" | ||
cat $SERVER_LOG | ||
exit 1 | ||
fi | ||
|
||
export MODEL_NAME='bls_request_rescheduling' | ||
|
||
set +e | ||
python3 $CLIENT_PY >> $CLIENT_LOG 2>&1 | ||
if [ $? -ne 0 ]; then | ||
echo -e "\n***\n*** bls_request_rescheduling test FAILED. \n***" | ||
cat $CLIENT_LOG | ||
RET=1 | ||
else | ||
check_test_results $TEST_RESULT_FILE $EXPECTED_NUM_TESTS | ||
if [ $? -ne 0 ]; then | ||
cat $CLIENT_LOG | ||
echo -e "\n***\n*** Test Result Verification Failed\n***" | ||
RET=1 | ||
fi | ||
fi | ||
set -e | ||
|
||
GRPC_TEST_PY=./grpc_endpoint_test.py | ||
EXPECTED_NUM_TESTS="2" | ||
|
||
set +e | ||
python3 $GRPC_TEST_PY >> $CLIENT_LOG 2>&1 | ||
if [ $? -ne 0 ]; then | ||
echo -e "\n***\n*** GRPC Endpoint test FAILED. \n***" | ||
cat $CLIENT_LOG | ||
RET=1 | ||
else | ||
check_test_results $TEST_RESULT_FILE $EXPECTED_NUM_TESTS | ||
if [ $? -ne 0 ]; then | ||
cat $CLIENT_LOG | ||
echo -e "\n***\n*** Test Result Verification Failed\n***" | ||
RET=1 | ||
fi | ||
fi | ||
set -e | ||
|
||
kill $SERVER_PID | ||
wait $SERVER_PID | ||
|
||
|
||
if [ $RET -eq 1 ]; then | ||
cat $SERVER_LOG | ||
echo -e "\n***\n*** Request Rescheduling test FAILED. \n***" | ||
else | ||
echo -e "\n***\n*** Request Rescheduling test PASSED. \n***" | ||
fi | ||
|
||
exit $RET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# 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. | ||
|
||
name: "bls_request_rescheduling" | ||
backend: "python" | ||
|
||
output [ | ||
{ | ||
name: "OUTPUT0" | ||
data_type: TYPE_FP32 | ||
dims: [ 16 ] | ||
} | ||
] | ||
|
||
instance_group [{ kind: KIND_CPU }] |
Oops, something went wrong.