From d8c8ea24b5049f93e56a46ca8c717c01efe83944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wawrzy=C5=84ski?= Date: Mon, 17 Apr 2023 14:15:48 +0200 Subject: [PATCH 1/3] Fix some of the errors I've encountered while following tutorials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adam Wawrzyński --- Conceptual_Guide/Part_1-model_deployment/README.md | 6 +++--- Conceptual_Guide/Part_1-model_deployment/client.py | 2 +- .../model_repository/text_detection/config.pbtxt | 6 +++--- .../model_repository/text_recognition/config.pbtxt | 2 +- .../Part_2-improving_resource_utilization/README.md | 4 ++-- .../model_repository/text_recognition/config.pbtxt | 2 +- Conceptual_Guide/Part_5-Model_Ensembles/README.md | 4 ++-- .../model_repository/ensemble_model/config.pbtxt | 2 +- .../model_repository/text_recognition/config.pbtxt | 2 +- .../utils/export_text_recognition.py | 2 +- .../ensemble_model/config.pbtxt | 9 --------- .../python_model_repository/python_vit/1/model.py | 8 ++++---- 12 files changed, 20 insertions(+), 29 deletions(-) mode change 100644 => 100755 Conceptual_Guide/Part_1-model_deployment/model_repository/text_detection/config.pbtxt diff --git a/Conceptual_Guide/Part_1-model_deployment/README.md b/Conceptual_Guide/Part_1-model_deployment/README.md index dd980825..5efbc944 100644 --- a/Conceptual_Guide/Part_1-model_deployment/README.md +++ b/Conceptual_Guide/Part_1-model_deployment/README.md @@ -181,21 +181,21 @@ input [ { name: "input_images:0" data_type: TYPE_FP32 - dims: [ -1, -1, -1, 3 ] + dims: [ -1, -1, 3 ] } ] output [ { name: "feature_fusion/Conv_7/Sigmoid:0" data_type: TYPE_FP32 - dims: [ -1, -1, -1, 1 ] + dims: [ -1, -1, 1 ] } ] output [ { name: "feature_fusion/concat_3:0" data_type: TYPE_FP32 - dims: [ -1, -1, -1, 5 ] + dims: [ -1, -1, 5 ] } ] ``` diff --git a/Conceptual_Guide/Part_1-model_deployment/client.py b/Conceptual_Guide/Part_1-model_deployment/client.py index e6357d36..1e9b0b15 100644 --- a/Conceptual_Guide/Part_1-model_deployment/client.py +++ b/Conceptual_Guide/Part_1-model_deployment/client.py @@ -207,6 +207,6 @@ def recognition_postprocessing(scores: np.ndarray) -> str: ) # Process response from recognition model - final_text = recognition_postprocessing(recognition_response.as_numpy("308")) + final_text = recognition_postprocessing(recognition_response.as_numpy("307")) print(final_text) diff --git a/Conceptual_Guide/Part_1-model_deployment/model_repository/text_detection/config.pbtxt b/Conceptual_Guide/Part_1-model_deployment/model_repository/text_detection/config.pbtxt old mode 100644 new mode 100755 index c16ed662..8fa41ddc --- a/Conceptual_Guide/Part_1-model_deployment/model_repository/text_detection/config.pbtxt +++ b/Conceptual_Guide/Part_1-model_deployment/model_repository/text_detection/config.pbtxt @@ -31,20 +31,20 @@ input [ { name: "input_images:0" data_type: TYPE_FP32 - dims: [ -1, -1, -1, 3 ] + dims: [ -1, -1, 3 ] } ] output [ { name: "feature_fusion/Conv_7/Sigmoid:0" data_type: TYPE_FP32 - dims: [ -1, -1, -1, 1 ] + dims: [ -1, -1, 1 ] } ] output [ { name: "feature_fusion/concat_3:0" data_type: TYPE_FP32 - dims: [ -1, -1, -1, 5 ] + dims: [ -1, -1, 5 ] } ] diff --git a/Conceptual_Guide/Part_1-model_deployment/model_repository/text_recognition/config.pbtxt b/Conceptual_Guide/Part_1-model_deployment/model_repository/text_recognition/config.pbtxt index 20671fa1..739c5af8 100644 --- a/Conceptual_Guide/Part_1-model_deployment/model_repository/text_recognition/config.pbtxt +++ b/Conceptual_Guide/Part_1-model_deployment/model_repository/text_recognition/config.pbtxt @@ -36,7 +36,7 @@ input [ ] output [ { - name: "308" + name: "307" data_type: TYPE_FP32 dims: [ 1, 26, 37 ] } diff --git a/Conceptual_Guide/Part_2-improving_resource_utilization/README.md b/Conceptual_Guide/Part_2-improving_resource_utilization/README.md index ae0cb2b8..87486451 100644 --- a/Conceptual_Guide/Part_2-improving_resource_utilization/README.md +++ b/Conceptual_Guide/Part_2-improving_resource_utilization/README.md @@ -110,7 +110,7 @@ model.load_state_dict(state) # Create ONNX file by tracing model trace_input = torch.randn(1, 1, 32, 100) -torch.onnx.export(model, trace_input, "str.onnx", verbose=True, dynamic_axes={'input.1':[0],'308':[0]}) +torch.onnx.export(model, trace_input, "str.onnx", verbose=True, dynamic_axes={'input.1':[0],'307':[0]}) ``` ### Launching the server @@ -231,7 +231,7 @@ Request concurrency: 16 ``` As each of the requests had a batch size (of 2), while the maximum batch size of the model was 8, dynamically batching these requests resulted in considerably improved throughput. Another consequence is a reduction in the latency. This reduction can be primarily attributed to reduced wait time in queue wait time. As the requests are batched together, multiple requests can be processed in parallel. -* **Dynamic Batching with multiple model instances**: To set up the Triton Server in this configuration, add `instance_group` in `config.pbtxt` and make sure to include `--gpus=1` and make sure to include `--gpus=1` in the `docker run` command to set up the server. Include `dynamic_batching` per instructions of the previous section in the model configuration. A point to note is that peak GPU utilization on the GPU shot up to 74% (A100 in this case) while just using a single model instance with dynamic batching. Adding one more instance will definitely improve performance but linear perf scaling will not be achieved in this case. +* **Dynamic Batching with multiple model instances**: To set up the Triton Server in this configuration, add `instance_group` in `config.pbtxt` and make sure to include `--gpus=1` in the `docker run` command to set up the server. Include `dynamic_batching` per instructions of the previous section in the model configuration. A point to note is that peak GPU utilization on the GPU shot up to 74% (A100 in this case) while just using a single model instance with dynamic batching. Adding one more instance will definitely improve performance but linear perf scaling will not be achieved in this case. ``` # Query diff --git a/Conceptual_Guide/Part_2-improving_resource_utilization/model_repository/text_recognition/config.pbtxt b/Conceptual_Guide/Part_2-improving_resource_utilization/model_repository/text_recognition/config.pbtxt index a19bd2c5..2f627c8e 100644 --- a/Conceptual_Guide/Part_2-improving_resource_utilization/model_repository/text_recognition/config.pbtxt +++ b/Conceptual_Guide/Part_2-improving_resource_utilization/model_repository/text_recognition/config.pbtxt @@ -36,7 +36,7 @@ input [ ] output [ { - name: "308" + name: "307" data_type: TYPE_FP32 dims: [ 26, 37 ] } diff --git a/Conceptual_Guide/Part_5-Model_Ensembles/README.md b/Conceptual_Guide/Part_5-Model_Ensembles/README.md index cfb53256..222f821f 100644 --- a/Conceptual_Guide/Part_5-Model_Ensembles/README.md +++ b/Conceptual_Guide/Part_5-Model_Ensembles/README.md @@ -316,10 +316,10 @@ ensemble_scheduling { We'll again be launching Triton using docker containers. This time, we'll start an interactive session within the container instead of directly launching the triton server. ```bash -docker run --gpus=all -it --shm-size=256m --rm \ +docker run --gpus=all -it --shm-size=512m --rm \ -p8000:8000 -p8001:8001 -p8002:8002 \ -v ${PWD}:/workspace/ -v ${PWD}/model_repository:/models \ - nvcr.io/nvidia/tritonserver:22.12-py3 + nvcr.io/nvidia/tritonserver:yy.mm-py3 ``` We'll need to install a couple of dependencies for our Python backend scripts. diff --git a/Conceptual_Guide/Part_5-Model_Ensembles/model_repository/ensemble_model/config.pbtxt b/Conceptual_Guide/Part_5-Model_Ensembles/model_repository/ensemble_model/config.pbtxt index 79bb200c..bbe0e4ed 100644 --- a/Conceptual_Guide/Part_5-Model_Ensembles/model_repository/ensemble_model/config.pbtxt +++ b/Conceptual_Guide/Part_5-Model_Ensembles/model_repository/ensemble_model/config.pbtxt @@ -100,7 +100,7 @@ ensemble_scheduling { value: "cropped_images" } output_map { - key: "308" + key: "307" value: "recognition_output" } }, diff --git a/Conceptual_Guide/Part_5-Model_Ensembles/model_repository/text_recognition/config.pbtxt b/Conceptual_Guide/Part_5-Model_Ensembles/model_repository/text_recognition/config.pbtxt index b37312a2..25d21a9c 100644 --- a/Conceptual_Guide/Part_5-Model_Ensembles/model_repository/text_recognition/config.pbtxt +++ b/Conceptual_Guide/Part_5-Model_Ensembles/model_repository/text_recognition/config.pbtxt @@ -36,7 +36,7 @@ input [ ] output [ { - name: "308" + name: "307" data_type: TYPE_FP32 dims: [ 26, 37 ] } diff --git a/Conceptual_Guide/Part_5-Model_Ensembles/utils/export_text_recognition.py b/Conceptual_Guide/Part_5-Model_Ensembles/utils/export_text_recognition.py index e58f268e..2e489d1c 100644 --- a/Conceptual_Guide/Part_5-Model_Ensembles/utils/export_text_recognition.py +++ b/Conceptual_Guide/Part_5-Model_Ensembles/utils/export_text_recognition.py @@ -45,5 +45,5 @@ trace_input, model_directory / "model.onnx", verbose=True, - dynamic_axes={"input.1": [0], "308": [0]}, + dynamic_axes={"input.1": [0], "307": [0]}, ) diff --git a/HuggingFace/ensemble_model_repository/ensemble_model/config.pbtxt b/HuggingFace/ensemble_model_repository/ensemble_model/config.pbtxt index 4ca33b89..e1baf1b0 100644 --- a/HuggingFace/ensemble_model_repository/ensemble_model/config.pbtxt +++ b/HuggingFace/ensemble_model_repository/ensemble_model/config.pbtxt @@ -40,11 +40,6 @@ output [ name: "last_hidden_state" data_type: TYPE_FP32 dims: [-1, -1] - }, - { - name: "1519" - data_type: TYPE_FP32 - dims: [768] } ] ensemble_scheduling { @@ -72,10 +67,6 @@ ensemble_scheduling { key: "last_hidden_state" value: "last_hidden_state" } - output_map { - key: "1519" - value: "1519" - } } ] } diff --git a/HuggingFace/python_model_repository/python_vit/1/model.py b/HuggingFace/python_model_repository/python_vit/1/model.py index e6f9a117..975129bd 100644 --- a/HuggingFace/python_model_repository/python_vit/1/model.py +++ b/HuggingFace/python_model_repository/python_vit/1/model.py @@ -30,7 +30,7 @@ class TritonPythonModel: def initialize(self, args): - self.feature_extractor = ViTFeatureExtractor.from_pretrained('google/vit-base-patch16-224-in21k').to("cuda") + self.feature_extractor = ViTFeatureExtractor.from_pretrained('google/vit-base-patch16-224-in21k')#.to("cuda") self.model = ViTModel.from_pretrained("google/vit-base-patch16-224-in21k").to("cuda") def execute(self, requests): @@ -38,14 +38,14 @@ def execute(self, requests): for request in requests: inp = pb_utils.get_input_tensor_by_name(request, "image") input_image = np.squeeze(inp.as_numpy()).transpose((2,0,1)) - inputs = self.feature_extractor(images=input_image, return_tensors="pt") + inputs = self.feature_extractor(images=input_image, return_tensors="pt").to("cuda") outputs = self.model(**inputs) inference_response = pb_utils.InferenceResponse(output_tensors=[ pb_utils.Tensor( - "label", - outputs.last_hidden_state.numpy() + "last_hidden_state", + outputs.last_hidden_state.detach().cpu().numpy() ) ]) responses.append(inference_response) From 0d05dd55d42473641459d1f83c1c56e8611998f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wawrzy=C5=84ski?= Date: Mon, 17 Apr 2023 14:53:49 +0200 Subject: [PATCH 2/3] Add example config.pbtxt for ONNX, fix preprocessing data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adam Wawrzyński --- Quick_Deploy/ONNX/client.py | 2 +- .../densenet_onnx/config.pbtxt | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Quick_Deploy/ONNX/model_repository/densenet_onnx/config.pbtxt diff --git a/Quick_Deploy/ONNX/client.py b/Quick_Deploy/ONNX/client.py index 050f5471..a68cb851 100644 --- a/Quick_Deploy/ONNX/client.py +++ b/Quick_Deploy/ONNX/client.py @@ -39,7 +39,7 @@ def rn50_preprocess(img_path="img1.jpg"): transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), ]) - return np.expand_dims(preprocess(img).numpy(),axis=0) + return np.expand_dims(preprocess(img).numpy(), axis=0).squeeze() transformed_img = rn50_preprocess() diff --git a/Quick_Deploy/ONNX/model_repository/densenet_onnx/config.pbtxt b/Quick_Deploy/ONNX/model_repository/densenet_onnx/config.pbtxt new file mode 100644 index 00000000..494d93b6 --- /dev/null +++ b/Quick_Deploy/ONNX/model_repository/densenet_onnx/config.pbtxt @@ -0,0 +1,44 @@ +# Copyright 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. + +name: "densenet_onnx" +platform: "onnxruntime_onnx" +max_batch_size : 0 +input [ + { + name: "data_0" + data_type: TYPE_FP32 + dims: [ 3, 224, 224 ] + reshape { shape: [ 1, 3, 224, 224 ] } + } +] +output [ + { + name: "fc6_1" + data_type: TYPE_FP32 + dims: [ 1, 1000 ,1, 1] + } +] From f4b240846ad543416c5bb3c9b150989ea3a302af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wawrzy=C5=84ski?= Date: Mon, 17 Apr 2023 15:19:12 +0200 Subject: [PATCH 3/3] Revert changes to config.pbtxt in Part1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adam Wawrzyński --- Conceptual_Guide/Part_1-model_deployment/README.md | 6 +++--- .../model_repository/text_detection/config.pbtxt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Conceptual_Guide/Part_1-model_deployment/README.md b/Conceptual_Guide/Part_1-model_deployment/README.md index 5efbc944..dd980825 100644 --- a/Conceptual_Guide/Part_1-model_deployment/README.md +++ b/Conceptual_Guide/Part_1-model_deployment/README.md @@ -181,21 +181,21 @@ input [ { name: "input_images:0" data_type: TYPE_FP32 - dims: [ -1, -1, 3 ] + dims: [ -1, -1, -1, 3 ] } ] output [ { name: "feature_fusion/Conv_7/Sigmoid:0" data_type: TYPE_FP32 - dims: [ -1, -1, 1 ] + dims: [ -1, -1, -1, 1 ] } ] output [ { name: "feature_fusion/concat_3:0" data_type: TYPE_FP32 - dims: [ -1, -1, 5 ] + dims: [ -1, -1, -1, 5 ] } ] ``` diff --git a/Conceptual_Guide/Part_1-model_deployment/model_repository/text_detection/config.pbtxt b/Conceptual_Guide/Part_1-model_deployment/model_repository/text_detection/config.pbtxt index 8fa41ddc..c16ed662 100755 --- a/Conceptual_Guide/Part_1-model_deployment/model_repository/text_detection/config.pbtxt +++ b/Conceptual_Guide/Part_1-model_deployment/model_repository/text_detection/config.pbtxt @@ -31,20 +31,20 @@ input [ { name: "input_images:0" data_type: TYPE_FP32 - dims: [ -1, -1, 3 ] + dims: [ -1, -1, -1, 3 ] } ] output [ { name: "feature_fusion/Conv_7/Sigmoid:0" data_type: TYPE_FP32 - dims: [ -1, -1, 1 ] + dims: [ -1, -1, -1, 1 ] } ] output [ { name: "feature_fusion/concat_3:0" data_type: TYPE_FP32 - dims: [ -1, -1, 5 ] + dims: [ -1, -1, -1, 5 ] } ]