Skip to content

Commit 42812a5

Browse files
committed
Update testing to verify the infer result
1 parent e610adb commit 42812a5

File tree

4 files changed

+22
-40
lines changed

4 files changed

+22
-40
lines changed

qa/L0_libtorch_instance_group_kind_model/client.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,19 @@ def test_infer(self):
7474
outputs.append(
7575
httpclient.InferRequestedOutput('OUTPUT__1', binary_data=True))
7676

77-
if model_name == "libtorch_instance_kind_err":
78-
with self.assertRaises(InferenceServerException) as ex:
79-
triton_client.infer(model_name, inputs, outputs=outputs)
80-
self.assertIn(
81-
"Expected all tensors to be on the same device, but found at least two devices",
82-
str(ex.exception))
83-
return
84-
8577
results = triton_client.infer(model_name, inputs, outputs=outputs)
8678

8779
output0_data = results.as_numpy('OUTPUT__0')
8880
output1_data = results.as_numpy('OUTPUT__1')
8981

90-
# Only validate the shape, as the output will differ every time the
91-
# model is compiled and used on different devices.
92-
self.assertEqual(output0_data.shape, (1, 4))
93-
self.assertEqual(output1_data.shape, (1, 4))
82+
expected_output_0 = input0_data + input0_data
83+
expected_output_1 = input1_data + input1_data
84+
85+
self.assertEqual(output0_data.shape, (1, 16))
86+
self.assertEqual(output1_data.shape, (1, 16))
87+
88+
self.assertTrue(np.all(expected_output_0 == output0_data))
89+
self.assertTrue(np.all(expected_output_1 == output1_data))
9490

9591

9692
if __name__ == '__main__':

qa/L0_libtorch_instance_group_kind_model/gen_models.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,32 @@
2929
import torch.nn as nn
3030

3131

32+
class SumModule(nn.Module):
33+
34+
def __init__(self):
35+
super(SumModule, self).__init__()
36+
37+
def forward(self, x):
38+
return torch.sum(x, dim=1)
39+
40+
3241
class TestModel(nn.Module):
3342

3443
def __init__(self, device1, device2):
3544
super(TestModel, self).__init__()
3645
self.device1 = device1
3746
self.device2 = device2
38-
self.layers1 = nn.Sequential(nn.Linear(16, 4),).to(self.device1)
39-
self.layers2 = nn.Sequential(nn.Linear(16, 4)).to(self.device2)
47+
self.layers1 = SumModule().to(self.device1)
48+
self.layers2 = SumModule().to(self.device2)
4049

4150
def forward(self, INPUT0, INPUT1):
4251
INPUT0 = INPUT0.to(self.device1)
4352
INPUT1 = INPUT1.to(self.device2)
4453
print('INPUT0 device: {}, INPUT1 device: {}\n'.format(
4554
INPUT0.device, INPUT1.device))
4655

47-
op0 = self.layers1(INPUT0 + INPUT0)
48-
op1 = self.layers2(INPUT1 + INPUT1)
56+
op0 = self.layers1(torch.stack([INPUT0, INPUT0], dim=1))
57+
op1 = self.layers2(torch.stack([INPUT1, INPUT1], dim=1))
4958
return op0, op1
5059

5160

Binary file not shown.

qa/L0_libtorch_instance_group_kind_model/test.sh

+1-24
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ RET=0
5757

5858
rm -f *.log *.txt
5959

60+
mkdir -p models/libtorch_multi_devices/1
6061
mkdir -p models/libtorch_multi_gpu/1
6162
cp models/libtorch_multi_devices/config.pbtxt models/libtorch_multi_gpu/.
6263
(cd models/libtorch_multi_gpu && \
@@ -72,14 +73,6 @@ if [ $? -ne 0 ]; then
7273
fi
7374
set -e
7475

75-
# Create the model that does not set instance_group_kind to 'KIND_MODEL'
76-
mkdir -p models/libtorch_instance_kind_err/1
77-
cp models/libtorch_multi_devices/config.pbtxt models/libtorch_instance_kind_err/.
78-
cp models/libtorch_multi_devices/1/model.pt models/libtorch_instance_kind_err/1/.
79-
(cd models/libtorch_instance_kind_err && \
80-
sed -i "s/name: \"libtorch_multi_devices\"/name: \"libtorch_instance_kind_err\"/" config.pbtxt && \
81-
sed -i "s/kind: KIND_MODEL/kind: KIND_GPU/" config.pbtxt)
82-
8376
run_server
8477
if [ "$SERVER_PID" == "0" ]; then
8578
echo -e "\n***\n*** Failed to start $SERVER\n***"
@@ -135,22 +128,6 @@ else
135128
RET=1
136129
fi
137130

138-
MESSAGE="INPUT0 device: cuda:2, INPUT1 device: cuda:0"
139-
export MODEL_NAME='libtorch_instance_kind_err'
140-
python3 $CLIENT_PY >> $CLIENT_LOG 2>&1
141-
if [ $? -ne 0 ]; then
142-
echo -e "\n***\n*** Model $MODEL_NAME FAILED. \n***"
143-
cat $CLIENT_LOG
144-
RET=1
145-
else
146-
check_test_results $TEST_RESULT_FILE $EXPECTED_NUM_TESTS
147-
if [ $? -ne 0 ]; then
148-
cat $CLIENT_LOG
149-
echo -e "\n***\n*** Test Result Verification Failed\n***"
150-
RET=1
151-
fi
152-
fi
153-
154131
set -e
155132

156133
kill $SERVER_PID

0 commit comments

Comments
 (0)