-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add testing for Triton Client Plugin API #5706
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f31969f
Add HTTP client plugin test
Tabrizian be67ab4
Add testing for HTTP asyncio
Tabrizian ceb0172
Add async plugin support
Tabrizian e2203e3
Fix qa container for L0_grpc
Tabrizian c3efe50
Add testing for grpc client plugin
Tabrizian 03d2892
Remove unused imports
Tabrizian 8bcac42
Fix up
Tabrizian 5785937
Fix L0_grpc models QA folder
Tabrizian 7d7152d
Update the test based on review feedback
Tabrizian 14e0c49
Remove unused import
Tabrizian 74f7531
Add testing for .plugin method
Tabrizian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
qa/L0_grpc/client_plugin_models/client_plugin_test/1/model.py
This file contains hidden or 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,58 @@ | ||
# Copyright (c) 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 json | ||
import triton_python_backend_utils as pb_utils | ||
import numpy as np | ||
|
||
|
||
class TritonPythonModel: | ||
|
||
def execute(self, requests): | ||
responses = [] | ||
|
||
for request in requests: | ||
json_string = pb_utils.get_input_tensor_by_name( | ||
request, "EXPECTED_HEADERS").as_numpy()[0].decode("utf-8") | ||
expected_headers = json.loads(json_string) | ||
|
||
success = True | ||
if request.parameters() != '': | ||
parameters = json.loads(request.parameters()) | ||
for key, value in expected_headers.items(): | ||
if key in parameters: | ||
if parameters[key] != value: | ||
success = False | ||
else: | ||
success = False | ||
|
||
test_success = pb_utils.Tensor("TEST_SUCCESS", | ||
np.array([success], dtype=bool)) | ||
inference_response = pb_utils.InferenceResponse( | ||
output_tensors=[test_success]) | ||
responses.append(inference_response) | ||
|
||
return responses |
45 changes: 45 additions & 0 deletions
45
qa/L0_grpc/client_plugin_models/client_plugin_test/config.pbtxt
This file contains hidden or 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,45 @@ | ||
# Copyright (c) 2020, NVIDIA CORPORATION. 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: "client_plugin_test" | ||
backend: "python" | ||
|
||
input [ | ||
{ | ||
name: "EXPECTED_HEADERS" | ||
data_type: TYPE_STRING | ||
dims: [ 1 ] | ||
} | ||
] | ||
output [ | ||
{ | ||
name: "TEST_SUCCESS" | ||
data_type: TYPE_BOOL | ||
dims: [ 1 ] | ||
} | ||
] | ||
|
||
instance_group [{ kind: KIND_CPU }] |
This file contains hidden or 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,120 @@ | ||
#!/usr/bin/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 | ||
import json | ||
|
||
sys.path.append("../common") | ||
|
||
import unittest | ||
import numpy as np | ||
import test_util as tu | ||
import tritonclient.grpc as tritongrpcclient | ||
from tritonclient.grpc import InferenceServerClientPlugin | ||
from tritonclient.utils import np_to_triton_dtype | ||
import tritonclient.grpc.aio as asynctritongrpcclient | ||
|
||
|
||
# A simple plugin that adds headers to the inference request. | ||
class TestPlugin(InferenceServerClientPlugin): | ||
|
||
def __init__(self, headers): | ||
self._headers = headers | ||
|
||
def __call__(self, request): | ||
request.headers.update(self._headers) | ||
|
||
|
||
def prepare_infer_inputs(headers): | ||
expected_headers = np.array([json.dumps(headers)], dtype=object) | ||
inputs = [] | ||
inputs.append( | ||
tritongrpcclient.InferInput('EXPECTED_HEADERS', expected_headers.shape, | ||
np_to_triton_dtype(expected_headers.dtype))) | ||
inputs[0].set_data_from_numpy(expected_headers) | ||
|
||
return inputs | ||
|
||
|
||
class GRPCClientPluginAsyncTest(unittest.IsolatedAsyncioTestCase): | ||
|
||
async def asyncSetUp(self): | ||
self._headers = {'my-key': 'my-value'} | ||
self._plugin = TestPlugin(self._headers) | ||
self._client = asynctritongrpcclient.InferenceServerClient( | ||
url='localhost:8001') | ||
|
||
async def test_simple_infer(self): | ||
model = "client_plugin_test" | ||
inputs = prepare_infer_inputs(self._headers) | ||
self._client.register_plugin(self._plugin) | ||
response = await self._client.infer(model_name=model, inputs=inputs) | ||
test_success = response.as_numpy('TEST_SUCCESS') | ||
self.assertEqual(test_success, True) | ||
|
||
self._client.unregister_plugin() | ||
inputs = prepare_infer_inputs({}) | ||
response = await self._client.infer(model_name=model, inputs=inputs) | ||
test_success = response.as_numpy('TEST_SUCCESS') | ||
self.assertEqual(test_success, True) | ||
|
||
async def asyncTearDown(self): | ||
await self._client.close() | ||
|
||
|
||
class GRPCClientPluginTest(tu.TestResultCollector): | ||
|
||
def setUp(self): | ||
self._headers = {'my-key': 'my-value'} | ||
self._plugin = TestPlugin(self._headers) | ||
self._client = tritongrpcclient.InferenceServerClient( | ||
url='localhost:8001') | ||
|
||
def test_simple_infer(self): | ||
# Set the binary data to False so that 'Inference-Header-Length' is not | ||
# added to the headers. | ||
model = "client_plugin_test" | ||
inputs = prepare_infer_inputs(self._headers) | ||
self._client.register_plugin(self._plugin) | ||
self.assertEqual(self._plugin, self._client.plugin()) | ||
response = self._client.infer(model_name=model, inputs=inputs) | ||
test_success = response.as_numpy('TEST_SUCCESS') | ||
self.assertEqual(test_success, True) | ||
|
||
# Unregister the plugin | ||
inputs = prepare_infer_inputs({}) | ||
self._client.unregister_plugin() | ||
self.assertEqual(None, self._client.plugin()) | ||
response = self._client.infer(model_name=model, inputs=inputs) | ||
test_success = response.as_numpy('TEST_SUCCESS') | ||
self.assertEqual(test_success, True) | ||
|
||
def tearDown(self): | ||
self._client.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have test to register multiple plugins and only the latest one will be used. Also may be a good idea to have API to return the registered plugin or None from the client that the user may check which plugin instance is registered.