Skip to content

Commit fa82bf5

Browse files
Update client.py
1 parent 1ab97b7 commit fa82bf5

File tree

1 file changed

+23
-70
lines changed

1 file changed

+23
-70
lines changed

examples/add_sub/client.py

Lines changed: 23 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,35 @@
1-
# Copyright 2020-2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2-
#
3-
# Redistribution and use in source and binary forms, with or without
4-
# modification, are permitted provided that the following conditions
5-
# are met:
6-
# * Redistributions of source code must retain the above copyright
7-
# notice, this list of conditions and the following disclaimer.
8-
# * Redistributions in binary form must reproduce the above copyright
9-
# notice, this list of conditions and the following disclaimer in the
10-
# documentation and/or other materials provided with the distribution.
11-
# * Neither the name of NVIDIA CORPORATION nor the names of its
12-
# contributors may be used to endorse or promote products derived
13-
# from this software without specific prior written permission.
14-
#
15-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
16-
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18-
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19-
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20-
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21-
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22-
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23-
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26-
27-
import sys
28-
29-
import numpy as np
30-
import tritonclient.http as httpclient
311
from tritonclient.utils import *
2+
import tritonclient.http as httpclient
3+
import numpy as np
4+
5+
triton_url = "localhost:8000"
6+
model_name = "openpom_model"
327

33-
model_name = "add_sub"
34-
shape = [4]
8+
smiles = ["CC(=O)OC1=CC=CC=C1C(=O)O"]
9+
input_data = np.array(smiles, dtype=object).reshape(1, 1)
3510

36-
with httpclient.InferenceServerClient("localhost:8000") as client:
37-
input0_data = np.random.rand(*shape).astype(np.float32)
38-
input1_data = np.random.rand(*shape).astype(np.float32)
11+
with httpclient.InferenceServerClient(triton_url) as client:
3912
inputs = [
4013
httpclient.InferInput(
41-
"INPUT0", input0_data.shape, np_to_triton_dtype(input0_data.dtype)
42-
),
43-
httpclient.InferInput(
44-
"INPUT1", input1_data.shape, np_to_triton_dtype(input1_data.dtype)
45-
),
14+
name="SMILES",
15+
shape=input_data.shape,
16+
datatype="BYTES"
17+
)
4618
]
47-
48-
inputs[0].set_data_from_numpy(input0_data)
49-
inputs[1].set_data_from_numpy(input1_data)
19+
inputs[0].set_data_from_numpy(input_data)
5020

5121
outputs = [
52-
httpclient.InferRequestedOutput("OUTPUT0"),
53-
httpclient.InferRequestedOutput("OUTPUT1"),
22+
httpclient.InferRequestedOutput("OUTPUT", binary_data=True)
5423
]
24+
print("Type of outputs[0]:", type(outputs[0]))
25+
print("Outputs:", outputs)
5526

56-
response = client.infer(model_name, inputs, request_id=str(1), outputs=outputs)
57-
58-
result = response.get_response()
59-
output0_data = response.as_numpy("OUTPUT0")
60-
output1_data = response.as_numpy("OUTPUT1")
61-
62-
print(
63-
"INPUT0 ({}) + INPUT1 ({}) = OUTPUT0 ({})".format(
64-
input0_data, input1_data, output0_data
65-
)
27+
response = client.infer(
28+
model_name=model_name,
29+
inputs=inputs,
30+
outputs=outputs
6631
)
67-
print(
68-
"INPUT0 ({}) - INPUT1 ({}) = OUTPUT1 ({})".format(
69-
input0_data, input1_data, output1_data
70-
)
71-
)
72-
73-
if not np.allclose(input0_data + input1_data, output0_data):
74-
print("add_sub example error: incorrect sum")
75-
sys.exit(1)
76-
77-
if not np.allclose(input0_data - input1_data, output1_data):
78-
print("add_sub example error: incorrect difference")
79-
sys.exit(1)
8032

81-
print("PASS: add_sub")
82-
sys.exit(0)
33+
embeddings = response.as_numpy("OUTPUT")
34+
print("shape:", embeddings.shape)
35+
print("embedding vector: \n", embeddings[0])

0 commit comments

Comments
 (0)