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

Test Python execute() to return Triton error code #6228

Merged
merged 6 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions qa/L0_backend_python/lifecycle/lifecycle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,39 @@ class LifecycleTest(tu.TestResultCollector):
def setUp(self):
self._shm_leak_detector = shm_util.ShmLeakDetector()

def test_error_code(self):
model_name = "error_code"
shape = [1, 1]
# [(Triton error, expected gRPC error message starting), ...]
errors = [
("UNKNOWN", "[StatusCode.UNKNOWN]"),
("INTERNAL", "[StatusCode.INTERNAL]"),
("NOT_FOUND", "[StatusCode.NOT_FOUND]"),
("INVALID_ARG", "[StatusCode.INVALID_ARGUMENT]"),
("UNAVAILABLE", "[StatusCode.UNAVAILABLE]"),
("UNSUPPORTED", "[StatusCode.UNIMPLEMENTED]"),
("ALREADY_EXISTS", "[StatusCode.ALREADY_EXISTS]"),
("(default)", "[StatusCode.INTERNAL] unrecognized"),
]
with self._shm_leak_detector.Probe() as shm_probe:
with grpcclient.InferenceServerClient("localhost:8001") as client:
for error, expected_grpc_error_start in errors:
input_data = np.array([[error]], dtype=np.object_)
inputs = [
grpcclient.InferInput(
"ERROR_CODE", shape, np_to_triton_dtype(input_data.dtype)
)
]
inputs[0].set_data_from_numpy(input_data)
with self.assertRaises(InferenceServerException) as e:
client.infer(model_name, inputs)
# e.g. [StatusCode.UNKNOWN] error code: TRITONSERVER_ERROR_UNKNOWN
# e.g. [StatusCode.INTERNAL] unrecognized error code: (default)
self.assertEqual(
str(e.exception),
expected_grpc_error_start + " error code: " + error,
)

def test_batch_error(self):
# The execute_error model returns an error for the first and third
# request and successfully processes the second request. This is making
Expand Down
6 changes: 5 additions & 1 deletion qa/L0_backend_python/lifecycle/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

CLIENT_LOG="./lifecycle_client.log"
EXPECTED_NUM_TESTS="3"
EXPECTED_NUM_TESTS="4"
TEST_RESULT_FILE='test_results.txt'
source ../common.sh
source ../../common/util.sh
Expand All @@ -40,6 +40,10 @@ SERVER_LOG="./lifecycle_server.log"
RET=0
rm -fr *.log ./models

mkdir -p models/error_code/1/
cp ../../python_models/error_code/model.py ./models/error_code/1/
cp ../../python_models/error_code/config.pbtxt ./models/error_code/

mkdir -p models/execute_error/1/
cp ../../python_models/execute_error/model.py ./models/execute_error/1/
cp ../../python_models/execute_error/config.pbtxt ./models/execute_error/
Expand Down
47 changes: 47 additions & 0 deletions qa/python_models/error_code/config.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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: "error_code"
backend: "python"
max_batch_size: 4

input [
{
name: "ERROR_CODE"
data_type: TYPE_STRING
dims: [ 1 ]
}
]

output [
{
name: "DUMMY_OUT"
data_type: TYPE_STRING
dims: [ 1 ]
}
]

instance_group [{ kind: KIND_CPU }]
58 changes: 58 additions & 0 deletions qa/python_models/error_code/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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 triton_python_backend_utils as pb_utils


class TritonPythonModel:
def execute(self, requests):
error_code_map = {
"UNKNOWN": pb_utils.TritonError.UNKNOWN,
"INTERNAL": pb_utils.TritonError.INTERNAL,
"NOT_FOUND": pb_utils.TritonError.NOT_FOUND,
"INVALID_ARG": pb_utils.TritonError.INVALID_ARG,
"UNAVAILABLE": pb_utils.TritonError.UNAVAILABLE,
"UNSUPPORTED": pb_utils.TritonError.UNSUPPORTED,
"ALREADY_EXISTS": pb_utils.TritonError.ALREADY_EXISTS,
}

responses = []

for request in requests:
err_code_tensor = pb_utils.get_input_tensor_by_name(
request, "ERROR_CODE"
).as_numpy()
err_code_str = str(err_code_tensor[0][0], encoding="utf-8")
if err_code_str in error_code_map:
error = pb_utils.TritonError(
message=("error code: " + err_code_str),
code=error_code_map[err_code_str],
)
else:
error = pb_utils.TritonError("unrecognized error code: " + err_code_str)
responses.append(pb_utils.InferenceResponse(error=error))

return responses