-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from 4 commits
b144fc6
9e8e320
2780878
6109dc8
796820e
7b739ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||||||||||||||
Check noticeCode scanning / CodeQL Unused import Note
Import of 'asyncio' is not used.
This autofix suggestion was applied.
Show autofix suggestion
Hide autofix suggestion
Copilot AutofixAI 8 months ago To fix the problem, we need to remove the unused import statement for the
Suggested changeset
1
qa/L0_backend_python/decoupled/models/decoupled_bls_async_cancel/1/model.py
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
||||||||||||||
|
|
||||||||||||||
| 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_NUMBER_OF_RESPONSE. | ||||||||||||||
| """ | ||||||||||||||
|
|
||||||||||||||
| 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_num_response = pb_utils.Tensor( | ||||||||||||||
| "MAX_NUMBER_OF_RESPONSE", np.array([100], dtype=np.int32) | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| infer_request = pb_utils.InferenceRequest( | ||||||||||||||
| model_name="response_sender_until_cancelled", | ||||||||||||||
| inputs=[input, max_num_response, 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 | ||||||||||||||
| 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 | ||
| } | ||
| ] |
Uh oh!
There was an error while loading. Please reload this page.