|
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 |
| -``` |
| 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. FX-TRT |
| 8 | +4. TensorRT |
| 9 | + |
| 10 | + |
| 11 | +Note: Please note that for ONNX models, user can convert the ONNX model to TensorRT serialized engine and then use this package. |
| 12 | + |
| 13 | +## Prerequisite |
| 14 | + |
| 15 | +Benchmark scripts depends on following Python packages in addition to requirements.txt packages |
| 16 | + |
| 17 | +1. Torch-TensorRT |
| 18 | +2. Torch |
| 19 | +3. TensorRT |
| 20 | + |
| 21 | +## Structure |
| 22 | + |
| 23 | +``` |
| 24 | +./ |
| 25 | +├── config |
| 26 | +│ ├── vgg16_trt.yml |
| 27 | +│ └── vgg16.yml |
| 28 | +├── models |
| 29 | +├── perf_run.py |
| 30 | +├── hub.py |
| 31 | +├── custom_models.py |
| 32 | +├── requirements.txt |
| 33 | +├── benchmark.sh |
| 34 | +└── README.md |
| 35 | +``` |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +* `config` - Directory which contains sample yaml configuration files for VGG network. |
| 40 | +* `models` - Model directory |
| 41 | +* `perf_run.py` - Performance benchmarking script which supports torch, torch_tensorrt, fx2trt, tensorrt backends |
| 42 | +* `hub.py` - Script to download torchscript models for VGG16, Resnet50, EfficientNet-B0, VIT, HF-BERT |
| 43 | +* `custom_models.py` - Script which includes custom models other than torchvision and timm (eg: HF BERT) |
| 44 | +* `utils.py` - utility functions script |
| 45 | +* `benchmark.sh` - This is used for internal performance testing of VGG16, Resnet50, EfficientNet-B0, VIT, HF-BERT. |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +There are two ways you can run a performance benchmark. |
| 50 | + |
| 51 | +### Using YAML config files |
| 52 | + |
| 53 | +To run the benchmark for a given configuration file: |
| 54 | + |
| 55 | +```python |
| 56 | +python perf_run.py --config=config/vgg16.yml |
| 57 | +``` |
| 58 | + |
| 59 | +There are two sample configuration files added. |
| 60 | + |
| 61 | +* vgg16.yml demonstrates a configuration with all the supported backends (Torch, Torch-TensorRT, TensorRT) |
| 62 | +* vgg16_trt.yml demonstrates how to use an external TensorRT serialized engine file directly. |
| 63 | + |
| 64 | + |
| 65 | +### Supported fields |
| 66 | + |
| 67 | +| Name | Supported Values | Description | |
| 68 | +| ----------------- | ------------------------------------ | ------------------------------------------------------------ | |
| 69 | +| backend | all, torch, torch_tensorrt, tensorrt | Supported backends for inference. | |
| 70 | +| input | - | Input binding names. Expected to list shapes of each input bindings | |
| 71 | +| model | - | Configure the model filename and name | |
| 72 | +| filename | - | Model file name to load from disk. | |
| 73 | +| name | - | Model name | |
| 74 | +| runtime | - | Runtime configurations | |
| 75 | +| device | 0 | Target device ID to run inference. Range depends on available GPUs | |
| 76 | +| precision | fp32, fp16 or half, int8 | Target precision to run inference. int8 cannot be used with 'all' backend | |
| 77 | +| calibration_cache | - | Calibration cache file expected for torch_tensorrt runtime in int8 precision | |
| 78 | + |
| 79 | +Additional sample use case: |
| 80 | + |
| 81 | +``` |
| 82 | +backend: |
| 83 | + - torch |
| 84 | + - torch_tensorrt |
| 85 | + - tensorrt |
| 86 | +input: |
| 87 | + input0: |
| 88 | + - 3 |
| 89 | + - 224 |
| 90 | + - 224 |
| 91 | + num_inputs: 1 |
| 92 | +model: |
| 93 | + filename: model.plan |
| 94 | + name: vgg16 |
| 95 | +runtime: |
| 96 | + device: 0 |
| 97 | + precision: |
| 98 | + - fp32 |
| 99 | + - fp16 |
| 100 | +``` |
| 101 | + |
| 102 | +Note: |
| 103 | + |
| 104 | +1. Please note that measuring INT8 performance is only supported via a `calibration cache` file or QAT mode for `torch_tensorrt` backend. |
| 105 | +2. TensorRT engine filename should end with `.plan` otherwise it will be treated as Torchscript module. |
| 106 | + |
| 107 | +### Using CompileSpec options via CLI |
| 108 | + |
| 109 | +Here are the list of `CompileSpec` options that can be provided directly to compile the pytorch module |
| 110 | + |
| 111 | +* `--backends` : Comma separated string of backends. Eg: torch,torch_tensorrt,tensorrt |
| 112 | +* `--model` : Name of the model file (Can be a torchscript module or a tensorrt engine (ending in `.plan` extension)) |
| 113 | +* `--inputs` : List of input shapes & dtypes. Eg: (1, 3, 224, 224)@fp32 for Resnet or (1, 128)@int32;(1, 128)@int32 for BERT |
| 114 | +* `--batch_size` : Batch size |
| 115 | +* `--precision` : Comma separated list of precisions to build TensorRT engine Eg: fp32,fp16 |
| 116 | +* `--device` : Device ID |
| 117 | +* `--truncate` : Truncate long and double weights in the network in Torch-TensorRT |
| 118 | +* `--is_trt_engine` : Boolean flag to be enabled if the model file provided is a TensorRT engine. |
| 119 | +* `--report` : Path of the output file where performance summary is written. |
| 120 | + |
| 121 | +Eg: |
| 122 | + |
| 123 | +``` |
| 124 | + python perf_run.py --model ${MODELS_DIR}/vgg16_scripted.jit.pt \ |
| 125 | + --precision fp32,fp16 --inputs="(1, 3, 224, 224)@fp32" \ |
| 126 | + --batch_size 1 \ |
| 127 | + --backends torch,torch_tensorrt,tensorrt \ |
| 128 | + --report "vgg_perf_bs1.txt" |
| 129 | +``` |
0 commit comments