-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test: Add tests for response parameters support for BLS in Python backend #7987
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
8 commits
Select commit
Hold shift + click to select a range
a75062a
test: Add tests for response parameters support for BLS in Python bac…
ziqifan617 41ec8fc
add model pydoc
ziqifan617 78dc992
remove unused import
ziqifan617 9fa5388
address jacky's comments
ziqifan617 160752d
adopt jacky's suggestion
ziqifan617 76570a3
clean up
ziqifan617 fed80ae
fix typo
ziqifan617 bc8f539
fix test issues
ziqifan617 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
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
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,57 @@ | ||
| # 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: "response_parameters_bls" | ||
| backend: "python" | ||
| max_batch_size: 8 | ||
|
|
||
| input [ | ||
| { | ||
| name: "RESPONSE_PARAMETERS" | ||
| data_type: TYPE_STRING | ||
| dims: [ 1 ] | ||
| }, | ||
| { | ||
| name: "RESPONSE_PARAMETERS_DECOUPLED" | ||
| data_type: TYPE_STRING | ||
| dims: [ 1 ] | ||
| } | ||
| ] | ||
|
|
||
| output [ | ||
| { | ||
| name: "OUTPUT" | ||
| data_type: TYPE_STRING | ||
| dims: [ 1 ] | ||
| } | ||
| ] | ||
|
|
||
| instance_group [ | ||
| { | ||
| count: 1 | ||
| 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,106 @@ | ||
| # 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 json | ||
|
|
||
| import numpy as np | ||
| import triton_python_backend_utils as pb_utils | ||
|
|
||
|
|
||
| class TritonPythonModel: | ||
| """ | ||
| This model (A) is designed to test sending back response parameters when using BLS. | ||
| It takes one input tensor, which is the RESPONSE_PARAMETERS and uses BLS to | ||
| call response_parameters model (B). Model B would set RESPONSE_PARAMETERS (with a bit | ||
| of data massage) as its response parameters. In the end, model A would also set its | ||
| response parameters from model B's response parameters. | ||
|
|
||
| With above model set up, we can easily test whether the real response parameters are | ||
| the same as the input response parameters. | ||
| """ | ||
|
|
||
| def execute(self, requests): | ||
| responses = [] | ||
|
|
||
| for request in requests: | ||
| passed = True | ||
|
|
||
| # test bls response parameters from a regular model | ||
| res_params_tensor = pb_utils.get_input_tensor_by_name( | ||
| request, "RESPONSE_PARAMETERS" | ||
| ).as_numpy() | ||
| res_params_str = str(res_params_tensor[0][0], encoding="utf-8") | ||
| res_params = json.loads(res_params_str) | ||
| bls_input_tensor = pb_utils.Tensor("RESPONSE_PARAMETERS", res_params_tensor) | ||
| bls_req = pb_utils.InferenceRequest( | ||
| model_name="response_parameters", | ||
| inputs=[bls_input_tensor], | ||
| requested_output_names=["OUTPUT"], | ||
| ) | ||
| bls_res = bls_req.exec() # decoupled=False | ||
| bls_res_params_str = bls_res.parameters() | ||
| bls_res_params = ( | ||
| json.loads(bls_res_params_str) if bls_res_params_str != "" else {} | ||
| ) | ||
| passed = passed and bls_res_params == res_params | ||
|
|
||
| # test bls response parameters from a decoupled model | ||
| res_params_decoupled_tensor = pb_utils.get_input_tensor_by_name( | ||
| request, "RESPONSE_PARAMETERS_DECOUPLED" | ||
| ).as_numpy() | ||
| res_params_decoupled_str = str( | ||
| res_params_decoupled_tensor[0][0], encoding="utf-8" | ||
| ) | ||
| res_params_decoupled = json.loads(res_params_decoupled_str) | ||
| bls_decoupled_input_tensor = pb_utils.Tensor( | ||
| "RESPONSE_PARAMETERS", res_params_decoupled_tensor | ||
| ) # response_parameters_decoupled model input name is RESPONSE_PARAMETERS | ||
| bls_decoupled_req = pb_utils.InferenceRequest( | ||
| model_name="response_parameters_decoupled", | ||
| inputs=[bls_decoupled_input_tensor], | ||
| requested_output_names=["OUTPUT"], | ||
| ) | ||
| bls_decoupled_res = bls_decoupled_req.exec(decoupled=True) | ||
| for bls_decoupled_r in bls_decoupled_res: | ||
| if len(bls_decoupled_r.output_tensors()) == 0: | ||
| break # meaning reached final response | ||
| bls_decoupled_r_params_str = bls_decoupled_r.parameters() | ||
| bls_decoupled_r_params = ( | ||
| json.loads(bls_decoupled_r_params_str) | ||
| if bls_decoupled_r_params_str != "" | ||
| else {} | ||
| ) | ||
| passed = passed and bls_decoupled_r_params in res_params_decoupled | ||
| res_params_decoupled.remove(bls_decoupled_r_params) | ||
| passed = passed and len(res_params_decoupled) == 0 | ||
|
|
||
| output_tensor = pb_utils.Tensor( | ||
| "OUTPUT", np.array([[str(passed)]], dtype=np.object_) | ||
| ) | ||
| response = pb_utils.InferenceResponse(output_tensors=[output_tensor]) | ||
| responses.append(response) | ||
|
|
||
| return responses | ||
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.
Uh oh!
There was an error while loading. Please reload this page.