-
Notifications
You must be signed in to change notification settings - Fork 1.6k
test: Add tests cancelling BLS decoupled request in Python backend #8097
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
6 commits
Select commit
Hold shift + click to select a range
b144fc6
test for bls cancel
richardhuo-nv 9e8e320
resolve comments
richardhuo-nv 2780878
resolve comments 2
richardhuo-nv 6109dc8
add helper function
richardhuo-nv 796820e
resolve comments
richardhuo-nv 7b739ac
resolve comments
richardhuo-nv 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 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
93 changes: 93 additions & 0 deletions
93
qa/L0_backend_python/decoupled/models/decoupled_bls_async_cancel/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,93 @@ | ||
# Copyright 2025, 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 asyncio | ||
|
||
import numpy as np | ||
import triton_python_backend_utils as pb_utils | ||
|
||
|
||
class TritonPythonModel: | ||
""" | ||
This model sends a decoupled bls inference request to 'response_sender_until_cancelled' | ||
model, and sums up its responses. | ||
Once the MAX_SUM is reached, the model will call the response iterator's | ||
cancel() method to cancel the response stream. | ||
If the IGNORE_CANCEL is set to True, the 'response_sender_until_cancelled' model will not hornor | ||
the request cancellation and keep sending the output to the model. | ||
The number of total responses should not reach MAX_RESPONSE_COUNT. | ||
""" | ||
|
||
async def execute(self, requests): | ||
max_sum = ( | ||
pb_utils.get_input_tensor_by_name(requests[0], "MAX_SUM").as_numpy().flat[0] | ||
) | ||
input = pb_utils.get_input_tensor_by_name(requests[0], "INPUT") | ||
ignore_cancel = pb_utils.get_input_tensor_by_name(requests[0], "IGNORE_CANCEL") | ||
delay = pb_utils.Tensor("DELAY", np.array([50], dtype=np.int32)) | ||
max_response_count = pb_utils.Tensor( | ||
"MAX_RESPONSE_COUNT", np.array([20], dtype=np.int32) | ||
) | ||
|
||
infer_request = pb_utils.InferenceRequest( | ||
model_name="response_sender_until_cancelled", | ||
inputs=[input, max_response_count, delay, ignore_cancel], | ||
requested_output_names=["OUTPUT"], | ||
) | ||
|
||
response_stream = await infer_request.async_exec(decoupled=True) | ||
|
||
is_cancelled = False | ||
error = None | ||
response_sum = 0 | ||
for infer_response in response_stream: | ||
if infer_response.has_error(): | ||
if infer_response.error().code() == pb_utils.TritonError.CANCELLED: | ||
is_cancelled = True | ||
else: | ||
error = infer_response.error() | ||
break | ||
|
||
out = pb_utils.get_output_tensor_by_name( | ||
infer_response, "OUTPUT" | ||
).as_numpy()[0] | ||
|
||
response_sum += out | ||
if response_sum >= max_sum: | ||
response_stream.cancel() | ||
|
||
responses = [ | ||
pb_utils.InferenceResponse( | ||
output_tensors=[ | ||
pb_utils.Tensor("SUM", np.array([response_sum], dtype=np.int32)), | ||
pb_utils.Tensor( | ||
"IS_CANCELLED", np.array([is_cancelled], dtype=np.bool_) | ||
), | ||
], | ||
error=error, | ||
) | ||
] | ||
|
||
return responses |
65 changes: 65 additions & 0 deletions
65
qa/L0_backend_python/decoupled/models/decoupled_bls_async_cancel/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,65 @@ | ||
# Copyright 2025, 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: "decoupled_bls_async_cancel" | ||
backend: "python" | ||
|
||
input [ | ||
{ | ||
name: "INPUT" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "MAX_SUM" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "IGNORE_CANCEL" | ||
data_type: TYPE_BOOL | ||
dims: [ 1 ] | ||
} | ||
] | ||
output [ | ||
{ | ||
name: "SUM" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "IS_CANCELLED" | ||
data_type: TYPE_BOOL | ||
dims: [ 1 ] | ||
} | ||
] | ||
|
||
instance_group [ | ||
{ | ||
count: 1 | ||
kind : KIND_CPU | ||
} | ||
] |
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
Unused import Note
Copilot Autofix
AI 6 months ago
To fix the problem, we need to remove the unused import statement for the
asyncio
module. This will eliminate the unnecessary dependency and make the code cleaner and easier to read. The change should be made in the fileqa/L0_backend_python/decoupled/models/decoupled_bls_async_cancel/1/model.py
by deleting the line that importsasyncio
.