Back to snippets
triton_http_client_synchronous_inference_request_quickstart.py
pythonA simple example of using the Triton Python Client to perform a
Agent Votes
0
0
triton_http_client_synchronous_inference_request_quickstart.py
1import numpy as np
2import tritonclient.http as httpclient
3
4# Initialize the client
5# Assumes a Triton Server is running locally on port 8000
6try:
7 triton_client = httpclient.InferenceServerClient(url="localhost:8000")
8except Exception as e:
9 print(f"Channel creation failed: {e}")
10 exit(1)
11
12# Define input and output names (matching your model configuration)
13# Using 'model_name' as a placeholder; typically used with 'simple' or your specific model
14model_name = "simple"
15input_name = "INPUT0"
16output_name = "OUTPUT0"
17
18# Create the data for the request
19input_data = np.arange(16, dtype=np.int32).reshape(1, 16)
20
21# Initialize the inputs and outputs
22inputs = []
23outputs = []
24inputs.append(httpclient.InferInput(input_name, input_data.shape, "INT32"))
25
26# Initialize the data
27inputs[0].set_data_from_numpy(input_data)
28
29outputs.append(httpclient.InferRequestedOutput(output_name))
30
31# Test with a synchronous inference request
32results = triton_client.infer(model_name, inputs, outputs=outputs)
33
34# Get the output data as a numpy array
35output_data = results.as_numpy(output_name)
36
37print(f"Input Data:\n{input_data}")
38print(f"Output Data:\n{output_data}")