-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add L0_generative_sequence test #6475
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
451f2bb
Add testing backend and test
GuanLuo 0be53e8
Add test to build / CI. Minor fix on L0_http
GuanLuo dd3f14f
Format. Update backend documentation
GuanLuo a448194
Fix up
GuanLuo fd9dc5a
Address comment
GuanLuo b172f56
Add negative testing
GuanLuo 7d2f4ae
Fix up
GuanLuo 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
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,175 @@ | ||
#!/usr/bin/env python | ||
# 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 sys | ||
|
||
sys.path.append("../common") | ||
|
||
import json | ||
|
||
# GRPC streaming helpers.. | ||
import queue | ||
import unittest | ||
from functools import partial | ||
|
||
import numpy as np | ||
import requests | ||
import sseclient | ||
import test_util as tu | ||
import tritonclient.grpc as grpcclient | ||
from tritonclient.utils import InferenceServerException | ||
|
||
MODEL_CONFIG_BASE = """ | ||
{{ | ||
"backend": "generative_sequence", | ||
"max_batch_size": 4, | ||
"input" : [ | ||
{{ | ||
"name": "INPUT", | ||
"data_type": "TYPE_INT32", | ||
"dims": [ 1 ] | ||
}} | ||
], | ||
"output" : [ | ||
{{ | ||
"name": "OUTPUT", | ||
"data_type": "TYPE_INT32", | ||
"dims": [ 1 ] | ||
}} | ||
], | ||
"model_transaction_policy" : {{ | ||
"decoupled": true | ||
}}, | ||
{}, | ||
"instance_group" : [{{ "kind": "KIND_CPU" }}] | ||
}} | ||
""" | ||
|
||
|
||
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 GenerativeSequenceTest(tu.TestResultCollector): | ||
def setUp(self): | ||
# Always make sure the original config is used | ||
with grpcclient.InferenceServerClient("localhost:8001") as triton_client: | ||
triton_client.load_model("generative_sequence") | ||
|
||
def test_generate_stream(self): | ||
headers = {"Accept": "text/event-stream"} | ||
url = "http://localhost:8000/v2/models/generative_sequence/generate_stream" | ||
inputs = {"INPUT": 2} | ||
res = requests.post(url, data=json.dumps(inputs), headers=headers) | ||
res.raise_for_status() | ||
client = sseclient.SSEClient(res) | ||
res_count = 2 | ||
for event in client.events(): | ||
res_count -= 1 | ||
data = json.loads(event.data) | ||
self.assertIn("OUTPUT", data) | ||
self.assertEqual(res_count, data["OUTPUT"]) | ||
self.assertEqual(0, res_count) | ||
|
||
def test_grpc_stream(self, sequence_id=0, sequence_start=False): | ||
user_data = UserData() | ||
with grpcclient.InferenceServerClient("localhost:8001") as triton_client: | ||
triton_client.start_stream(callback=partial(callback, user_data)) | ||
inputs = [] | ||
inputs.append(grpcclient.InferInput("INPUT", [1, 1], "INT32")) | ||
inputs[0].set_data_from_numpy(np.array([[2]], dtype=np.int32)) | ||
|
||
triton_client.async_stream_infer( | ||
model_name="generative_sequence", | ||
inputs=inputs, | ||
sequence_id=sequence_id, | ||
sequence_start=sequence_start, | ||
) | ||
res_count = 2 | ||
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("OUTPUT")[0][0]) | ||
self.assertEqual(0, res_count) | ||
|
||
def test_unsupported_sequence_scheduler(self): | ||
# Override model config with scheduler settings that do not support | ||
# request rescheduling. | ||
configs = [ | ||
r'"sequence_batching" : { "direct" : {}, "generative_sequence" : false }', | ||
r'"sequence_batching" : { "oldest" : {}, "generative_sequence" : false }', | ||
] | ||
sid = 1 | ||
for sc in configs: | ||
with grpcclient.InferenceServerClient("localhost:8001") as triton_client: | ||
triton_client.load_model( | ||
"generative_sequence", config=MODEL_CONFIG_BASE.format(sc) | ||
) | ||
with self.assertRaises(InferenceServerException) as context: | ||
# Without specifying 'generative_sequence : true', the sequence | ||
# batcher expects sequence parameters to be provided explicitly | ||
self.test_grpc_stream(sequence_id=sid, sequence_start=True) | ||
sid += 1 | ||
print(str(context.exception)) | ||
self.assertTrue( | ||
"Request is released with TRITONSERVER_REQUEST_RELEASE_RESCHEDULE" | ||
in str(context.exception) | ||
) | ||
|
||
def test_unsupported_dynamic_scheduler(self): | ||
# Override model config with scheduler settings that do not support | ||
# request rescheduling. | ||
configs = [ | ||
r'"dynamic_batching" : {}', | ||
] | ||
for sc in configs: | ||
with grpcclient.InferenceServerClient("localhost:8001") as triton_client: | ||
triton_client.load_model( | ||
"generative_sequence", config=MODEL_CONFIG_BASE.format(sc) | ||
) | ||
with self.assertRaises(InferenceServerException) as context: | ||
self.test_grpc_stream() | ||
print(str(context.exception)) | ||
self.assertTrue( | ||
"Request is released with TRITONSERVER_REQUEST_RELEASE_RESCHEDULE" | ||
in str(context.exception) | ||
) | ||
Comment on lines
+168
to
+171
Check notice Code scanning / CodeQL Imprecise assert Note
assertTrue(a in b) cannot provide an informative message. Using assertIn(a, b) instead will give more informative messages.
|
||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
48 changes: 48 additions & 0 deletions
48
qa/L0_generative_sequence/models/generative_sequence/config.pbtxt
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,48 @@ | ||
# 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. | ||
backend: "generative_sequence" | ||
max_batch_size: 4 | ||
input [ | ||
{ | ||
name: "INPUT" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
} | ||
] | ||
output [ | ||
{ | ||
name: "OUTPUT" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
} | ||
] | ||
model_transaction_policy { | ||
decoupled: True | ||
} | ||
sequence_batching { | ||
generative_sequence : true | ||
} | ||
instance_group [{ kind: KIND_CPU }] |
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,92 @@ | ||
#!/bin/bash | ||
# 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. | ||
|
||
REPO_VERSION=${NVIDIA_TRITON_SERVER_VERSION} | ||
if [ "$#" -ge 1 ]; then | ||
REPO_VERSION=$1 | ||
fi | ||
if [ -z "$REPO_VERSION" ]; then | ||
echo -e "Repository version must be specified" | ||
echo -e "\n***\n*** Test Failed\n***" | ||
exit 1 | ||
fi | ||
if [ ! -z "$TEST_REPO_ARCH" ]; then | ||
REPO_VERSION=${REPO_VERSION}_${TEST_REPO_ARCH} | ||
fi | ||
|
||
source ../common/util.sh | ||
|
||
RET=0 | ||
|
||
CLIENT_LOG="./generative_sequence_client.log" | ||
TEST_PY=./generative_sequence_e2e.py | ||
EXPECTED_NUM_TESTS="4" | ||
TEST_RESULT_FILE='test_results.txt' | ||
|
||
|
||
export CUDA_VISIBLE_DEVICES=0 | ||
|
||
rm -fr *.log | ||
|
||
pip install sseclient-py | ||
|
||
SERVER=/opt/tritonserver/bin/tritonserver | ||
SERVER_ARGS="--model-repository=`pwd`/models --model-control-mode=EXPLICIT" | ||
SERVER_LOG="./inference_server.log" | ||
run_server | ||
if [ "$SERVER_PID" == "0" ]; then | ||
echo -e "\n***\n*** Failed to start $SERVER\n***" | ||
cat $SERVER_LOG | ||
exit 1 | ||
fi | ||
|
||
set +e | ||
python $TEST_PY >>$CLIENT_LOG 2>&1 | ||
if [ $? -ne 0 ]; then | ||
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 0 ]; then | ||
echo -e "\n***\n*** Test Passed\n***" | ||
else | ||
cat $CLIENT_LOG | ||
cat $SERVER_LOG | ||
echo -e "\n***\n*** Test FAILED\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
Oops, something went wrong.
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.
Check notice
Code scanning / CodeQL
Imprecise assert Note