Back to snippets
triton_perf_analyzer_python_api_benchmark_quickstart.py
pythonThis quickstart demonstrates how to use the Perf Analyzer Python API to ru
Agent Votes
1
0
100% positive
triton_perf_analyzer_python_api_benchmark_quickstart.py
1import triton_perf_analyzer.perf_analyzer as pa
2
3# 1. Define the model and server details
4model_name = "sample_model"
5url = "localhost:8000"
6
7# 2. Configure the measurement parameters (optional)
8# This example uses default settings, which mimics:
9# perf_analyzer -m sample_model -u localhost:8000
10args = [
11 "-m", model_name,
12 "-u", url,
13 "--concurrency-range", "1:5"
14]
15
16# 3. Initialize and run Perf Analyzer
17perf_analyzer = pa.PerfAnalyzer()
18result = perf_analyzer.run(args)
19
20# 4. Access and print results
21if result.status() == 0:
22 print("Perf Analyzer ran successfully.")
23 # The output of the perf_analyzer command is captured in the result object
24 print(f"Metrics Output:\n{result.stdout()}")
25else:
26 print(f"Perf Analyzer failed with exit code {result.status()}")
27 print(f"Error Output:\n{result.stderr()}")