-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add testing for Pytorch instance group kind MODEL #5810
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 all commits
dc0f788
5e49dbb
1d2ec56
d674175
f7e8439
824ecb4
2e6a4fa
acb4752
872b2c9
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,92 @@ | ||
#!/usr/bin/env python | ||
# 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. | ||
|
||
import os | ||
import sys | ||
|
||
sys.path.append("../common") | ||
|
||
import unittest | ||
import numpy as np | ||
import test_util as tu | ||
|
||
import tritonclient.http as httpclient | ||
|
||
# By default, find tritonserver on "localhost", but can be overridden | ||
# with TRITONSERVER_IPADDR envvar | ||
_tritonserver_ipaddr = os.environ.get('TRITONSERVER_IPADDR', 'localhost') | ||
|
||
|
||
class InferTest(tu.TestResultCollector): | ||
|
||
def test_infer(self): | ||
try: | ||
triton_client = httpclient.InferenceServerClient( | ||
url=f"{_tritonserver_ipaddr}:8000") | ||
except Exception as e: | ||
print("channel creation failed: " + str(e)) | ||
sys.exit(1) | ||
|
||
model_name = os.environ['MODEL_NAME'] | ||
|
||
inputs = [] | ||
outputs = [] | ||
inputs.append(httpclient.InferInput('INPUT0', [1, 16], "FP32")) | ||
inputs.append(httpclient.InferInput('INPUT1', [1, 16], "FP32")) | ||
|
||
# Create the data for the two input tensors. | ||
input0_data = np.arange(start=0, stop=16, dtype=np.float32) | ||
input0_data = np.expand_dims(input0_data, axis=0) | ||
input1_data = np.arange(start=32, stop=48, dtype=np.float32) | ||
input1_data = np.expand_dims(input1_data, axis=0) | ||
|
||
# Initialize the data | ||
inputs[0].set_data_from_numpy(input0_data, binary_data=True) | ||
inputs[1].set_data_from_numpy(input1_data, binary_data=True) | ||
|
||
outputs.append( | ||
httpclient.InferRequestedOutput('OUTPUT__0', binary_data=True)) | ||
outputs.append( | ||
httpclient.InferRequestedOutput('OUTPUT__1', binary_data=True)) | ||
|
||
results = triton_client.infer(model_name, inputs, outputs=outputs) | ||
|
||
output0_data = results.as_numpy('OUTPUT__0') | ||
output1_data = results.as_numpy('OUTPUT__1') | ||
|
||
expected_output_0 = input0_data + input1_data | ||
expected_output_1 = input0_data - input1_data | ||
|
||
self.assertEqual(output0_data.shape, (1, 16)) | ||
self.assertEqual(output1_data.shape, (1, 16)) | ||
|
||
self.assertTrue(np.all(expected_output_0 == output0_data)) | ||
self.assertTrue(np.all(expected_output_1 == output1_data)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/python | ||
# 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. | ||
|
||
import torch | ||
import torch.nn as nn | ||
|
||
|
||
class SumModule(nn.Module): | ||
|
||
def __init__(self, device): | ||
super(SumModule, self).__init__() | ||
self.device = device | ||
|
||
def forward(self, INPUT0, INPUT1): | ||
INPUT0 = INPUT0.to(self.device) | ||
INPUT1 = INPUT1.to(self.device) | ||
print('SumModule - INPUT0 device: {}, INPUT1 device: {}\n'.format( | ||
INPUT0.device, INPUT1.device)) | ||
return INPUT0 + INPUT1 | ||
|
||
|
||
class DiffModule(nn.Module): | ||
|
||
def __init__(self, device): | ||
super(DiffModule, self).__init__() | ||
self.device = device | ||
|
||
def forward(self, INPUT0, INPUT1): | ||
INPUT0 = INPUT0.to(self.device) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this ensure that execution will also occur on the same device? Is it possible that execution kernels to be invoked on the default device access the tensors via p2p? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran PA on the model that uses device 0 and device 2, and the output of nvidia-smi showed that only the two devices were used:
I think the default device should be used for accessing the tensor. We can see that the default device, which is GPU 0, has more utilization. Also, for a model that uses CPU and device 3, we can see that device 0 is used as well:
Let me try to get the nsight traces. Had some issue with nsight hanging when generating the report. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for confirming Kris! |
||
INPUT1 = INPUT1.to(self.device) | ||
print('DiffModule - INPUT0 device: {}, INPUT1 device: {}\n'.format( | ||
INPUT0.device, INPUT1.device)) | ||
return INPUT0 - INPUT1 | ||
|
||
|
||
class TestModel(nn.Module): | ||
|
||
def __init__(self, device0, device1): | ||
super(TestModel, self).__init__() | ||
self.device0 = device0 | ||
self.device1 = device1 | ||
|
||
self.layer1 = SumModule(self.device0) | ||
self.layer2 = DiffModule(self.device1) | ||
|
||
def forward(self, INPUT0, INPUT1): | ||
op0 = self.layer1(INPUT0, INPUT1) | ||
op1 = self.layer2(INPUT0, INPUT1) | ||
return op0, op1 | ||
|
||
|
||
devices = [("cuda:2", "cuda:0"), ("cpu", "cuda:3")] | ||
model_names = ["libtorch_multi_gpu", "libtorch_multi_device"] | ||
|
||
for device_pair, model_name in zip(devices, model_names): | ||
model = TestModel(device_pair[0], device_pair[1]) | ||
model_path = "models/" + model_name + "/1/model.pt" | ||
scripted_model = torch.jit.script(model) | ||
scripted_model.save(model_path) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# 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: "libtorch_multi_device" | ||
platform: "pytorch_libtorch" | ||
max_batch_size: 8 | ||
|
||
input [ | ||
{ | ||
name: "INPUT0" | ||
data_type: TYPE_FP32 | ||
dims: [ 16 ] | ||
}, | ||
{ | ||
name: "INPUT1" | ||
data_type: TYPE_FP32 | ||
dims: [ 16 ] | ||
} | ||
] | ||
output [ | ||
{ | ||
name: "OUTPUT__0" | ||
data_type: TYPE_FP32 | ||
dims: [ 4 ] | ||
}, | ||
{ | ||
name: "OUTPUT__1" | ||
data_type: TYPE_FP32 | ||
dims: [ 4 ] | ||
} | ||
] | ||
|
||
instance_group [ | ||
{ | ||
kind: KIND_MODEL | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tabrizian This line was the reason for the strange behavior we saw.. Removed this as we already export cuda devices at line 41 above.