-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: Improve data type validation for classification #8267
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
0152030
Update
pskiran1 34e212c
Update
pskiran1 4c27d94
Update
pskiran1 891fecf
Update
pskiran1 d9e5c70
Update
pskiran1 33871a3
fix pre-commit errors
pskiran1 54b7c45
fix pre-commit errors
pskiran1 f31d463
Update
pskiran1 2503b0e
Undo Dockerfile.QA modifications
pskiran1 8744c17
Update
pskiran1 d515e08
Merge branch 'main' into spolisetty_validation
mc-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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # 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 sys | ||
|
|
||
| sys.path.append("../common") | ||
|
|
||
| import os | ||
| import unittest | ||
|
|
||
| import numpy as np | ||
| import test_util as tu | ||
| import tritonclient.grpc as grpcclient | ||
| import tritonclient.http as httpclient | ||
| from tritonclient.utils import InferenceServerException | ||
|
|
||
|
|
||
| class ClassificationParameterTest(tu.TestResultCollector): | ||
| def setUp(self): | ||
| self.protocol = os.environ.get("CLIENT_TYPE", "http") | ||
| if self.protocol == "http": | ||
| self.client = httpclient.InferenceServerClient("localhost:8000") | ||
| else: | ||
| self.client = grpcclient.InferenceServerClient("localhost:8001") | ||
|
|
||
| def _prepare_io(self, input_data, dtype): | ||
| if self.protocol == "http": | ||
| inputs = [httpclient.InferInput("INPUT0", input_data.shape, dtype)] | ||
| outputs = [httpclient.InferRequestedOutput(name="OUTPUT0", class_count=5)] | ||
| else: | ||
| inputs = [grpcclient.InferInput("INPUT0", input_data.shape, dtype)] | ||
| outputs = [grpcclient.InferRequestedOutput(name="OUTPUT0", class_count=5)] | ||
| inputs[0].set_data_from_numpy(input_data) | ||
| return inputs, outputs | ||
|
|
||
| def test_classificattion(self): | ||
| shape = (1, 8) | ||
| dtype = "FP32" | ||
| model_name = "identity_fp32" | ||
| input_data = np.ones(shape, dtype=np.float32) | ||
|
|
||
| inputs, outputs = self._prepare_io(input_data, dtype) | ||
| result = self.client.infer( | ||
| model_name=model_name, inputs=inputs, outputs=outputs | ||
| ) | ||
| output = result.get_output("OUTPUT0") | ||
| if self.protocol == "http": | ||
| output_dtype = output["datatype"] | ||
| else: | ||
| output_dtype = output.datatype | ||
|
|
||
| self.assertEqual(output_dtype, "BYTES") | ||
|
|
||
| # Validate shape matches to the class_count | ||
| output_data = result.as_numpy("OUTPUT0") | ||
| self.assertIsNotNone(output_data) | ||
| self.assertEqual(output_data.shape, (1, 5)) | ||
|
|
||
| for res_str_bytes in np.nditer(output_data, flags=["refs_ok"]): | ||
| res_str = res_str_bytes.item().decode("utf-8") | ||
| self.assertTrue(res_str.startswith("1.000000:")) | ||
|
|
||
| def test_classificattion_unsupported_data_type(self): | ||
| shape = (1, 8) | ||
| model_name = "identity_bytes" | ||
| dtype = "BYTES" | ||
| input_data = np.array([["test"] * shape[1]], dtype=object) | ||
|
|
||
| inputs, outputs = self._prepare_io(input_data, dtype) | ||
| with self.assertRaises(InferenceServerException) as e: | ||
| self.client.infer(model_name=model_name, inputs=inputs, outputs=outputs) | ||
|
|
||
| self.assertIn( | ||
| "class result not available for output due to unsupported type 'BYTES'", | ||
| str(e.exception), | ||
| ) | ||
|
|
||
|
|
||
| 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
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.
Uh oh!
There was an error while loading. Please reload this page.