Skip to content

Commit 9dd4cc8

Browse files
authored
Merge pull request #768 from NVIDIA/anuragd/perf_benchmark
feat: Added a comprehensive perf benchmark script in Python
2 parents 733a4b1 + c4413e1 commit 9dd4cc8

File tree

6 files changed

+451
-0
lines changed

6 files changed

+451
-0
lines changed

examples/benchmark/py/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Performance Benchmarking
2+
3+
This is a comprehensive Python benchmark suite to run perf runs using different supported backends. Following backends are supported:
4+
5+
1. Torch
6+
2. Torch-TensorRT
7+
3. TensorRT
8+
9+
Note: Please note that for ONNX models, user can convert the ONNX model to TensorRT serialized engine and then use this package.
10+
11+
## Prerequisite
12+
13+
Benchmark scripts depends on following Python packages in addition to requirements.txt packages
14+
15+
1. Torch-TensorRT
16+
2. Torch
17+
3. TensorRT
18+
19+
## Structure
20+
21+
```
22+
./
23+
├── config
24+
│ ├── vgg16_trt.yml
25+
│ └── vgg16.yml
26+
├── models
27+
├── perf_run.py
28+
└── README.md
29+
```
30+
31+
Please save your configuration files at config directory. Similarly, place your model files at models path.
32+
33+
## Usage
34+
35+
To run the benchmark for a given configuration file:
36+
37+
```
38+
python perf_run.py --config=config/vgg16.yml
39+
```
40+
41+
## Configuration
42+
43+
There are two sample configuration files added.
44+
45+
* vgg16.yml demonstrates a configuration with all the supported backends (Torch, Torch-TensorRT, TensorRT)
46+
* vgg16_trt.yml demonstrates how to use an external TensorRT serialized engine file directly.
47+
48+
49+
### Supported fields
50+
51+
| Name | Supported Values | Description |
52+
| --- | --- | --- |
53+
| backend | all, torch, torch_tensorrt, tensorrt | Supported backends for inference. |
54+
| input | - | Input binding names. Expected to list shapes of each input bindings |
55+
| model | - | Configure the model filename and name |
56+
| filename | - | Model file name to load from disk. |
57+
| name | - | Model name |
58+
| runtime | - | Runtime configurations |
59+
| device | 0 | Target device ID to run inference. Range depends on available GPUs |
60+
| precision | fp32, fp16 or half, int8 | Target precision to run inference. int8 cannot be used with 'all' backend |
61+
| calibration_cache | - | Calibration cache file expected for torch_tensorrt runtime in int8 precision |
62+
63+
Note:
64+
1. Please note that torch runtime perf is not supported for int8 yet.
65+
2. Torchscript module filename should end with .jit.pt otherwise it will be treated as a TensorRT engine.
66+
67+
68+
69+
Additional sample use case:
70+
71+
```
72+
backend:
73+
- torch
74+
- torch_tensorrt
75+
- tensorrt
76+
input:
77+
input0:
78+
- 3
79+
- 224
80+
- 224
81+
num_inputs: 1
82+
model:
83+
filename: model.plan
84+
name: vgg16
85+
runtime:
86+
device: 0
87+
precision:
88+
- fp32
89+
- fp16
90+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
backend:
3+
- all
4+
input:
5+
input0:
6+
- 1
7+
- 3
8+
- 224
9+
- 224
10+
num_inputs: 1
11+
model:
12+
filename: models/vgg16_traced.jit.pt
13+
name: vgg16
14+
runtime:
15+
device: 0
16+
precision:
17+
- fp32
18+
- fp16
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
backend:
3+
- tensorrt
4+
input:
5+
input0:
6+
- 3
7+
- 224
8+
- 224
9+
num_inputs: 1
10+
model:
11+
filename: models/model.plan
12+
name: vgg16
13+
calibration_cache:
14+
- vgg16.cache
15+
runtime:
16+
device: 0
17+
precision:
18+
- fp32
19+
- fp16
20+
- int8

examples/benchmark/py/models/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)