|
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 |
31 | 1 | 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" |
32 | 7 |
|
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) |
35 | 10 |
|
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: |
39 | 12 | inputs = [ |
40 | 13 | 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 | + ) |
46 | 18 | ] |
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) |
50 | 20 |
|
51 | 21 | outputs = [ |
52 | | - httpclient.InferRequestedOutput("OUTPUT0"), |
53 | | - httpclient.InferRequestedOutput("OUTPUT1"), |
| 22 | + httpclient.InferRequestedOutput("OUTPUT", binary_data=True) |
54 | 23 | ] |
| 24 | + print("Type of outputs[0]:", type(outputs[0])) |
| 25 | + print("Outputs:", outputs) |
55 | 26 |
|
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 |
66 | 31 | ) |
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) |
80 | 32 |
|
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