21
21
# It is recommended to execute this script inside the Model Optimization Toolkit TensorRT Docker container.
22
22
# Please ensure that the ImageNet dataset is available in the container at the specified path.
23
23
24
- # Usage: ./test_onnx_ptq.sh /path/to/imagenet /path/to/models
24
+ # Usage: ./test_onnx_ptq.sh [--no-clean] [ /path/to/imagenet] [ /path/to/models]
25
25
26
26
set -exo pipefail
27
27
@@ -34,12 +34,35 @@ cuda_capability=$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader | hea
34
34
35
35
36
36
pushd $public_example_dir
37
+
38
+ # Parse arguments
39
+ clean_mode=true
40
+ imagenet_path=" "
41
+ models_folder=" "
42
+
43
+ for arg in " $@ " ; do
44
+ case $arg in
45
+ --no-clean)
46
+ clean_mode=false
47
+ shift
48
+ ;;
49
+ * )
50
+ if [ -z " $imagenet_path " ]; then
51
+ imagenet_path=" $arg "
52
+ elif [ -z " $models_folder " ]; then
53
+ models_folder=" $arg "
54
+ fi
55
+ shift
56
+ ;;
57
+ esac
58
+ done
59
+
37
60
export TQDM_DISABLE=1
38
61
39
62
40
63
# Setting image and model paths (contains 8 models)
41
- imagenet_path=${1 :-/ data/ imagenet/ }
42
- models_folder=${2 :-/ models/ onnx}
64
+ imagenet_path=${imagenet_path :-/ data/ imagenet/ }
65
+ models_folder=${models_folder :-/ models/ onnx}
43
66
calib_size=64
44
67
batch_size=1
45
68
@@ -88,9 +111,9 @@ declare -A timm_model_name=(
88
111
latency_models=(" efficientnet_b0" " efficientnet_b3" " efficientnet-lite4-11" " faster_vit_timm_opset13_simplified" " faster_vit_timm_opset17_simplified" " inception-v1-12" " inception-v2-9" )
89
112
90
113
# Create build directory to store all the results
114
+ rm -rf build
91
115
mkdir -p build
92
116
93
-
94
117
# Iterate over each model path to create directories for all modes for each model
95
118
for model_path in " ${model_paths[@]} " ; do
96
119
model_name=$( basename " $model_path " .onnx)
@@ -129,7 +152,8 @@ for model_path in "${model_paths[@]}"; do
129
152
--onnx_path=$model_dir /fp16/model.onnx \
130
153
--quantize_mode=$quant_mode \
131
154
--calibration_data=$calib_data_path \
132
- --output_path=$model_dir /$quant_mode /model.quant.onnx &
155
+ --output_path=$model_dir /$quant_mode /model.quant.onnx \
156
+ --calibration_eps=cuda:0 &
133
157
pids+=($! )
134
158
done
135
159
@@ -163,25 +187,30 @@ for model_path in "${model_paths[@]}"; do
163
187
164
188
if [ " $quant_mode " == " fp16" ]; then
165
189
eval_model_path=$model_dir /fp16/model.onnx
190
+ engine_path=$model_dir /fp16/model.engine
166
191
precision=" fp16"
167
192
elif [ " $quant_mode " == " int8_iq" ]; then
168
193
eval_model_path=$model_dir /fp16/model.onnx
194
+ engine_path=$model_dir /int8_iq/model.engine
169
195
precision=" best"
170
196
else
171
197
eval_model_path=$model_dir /$quant_mode /model.quant.onnx
198
+ engine_path=$model_dir /$quant_mode /model.quant.engine
172
199
precision=" stronglyTyped"
173
200
fi
174
201
175
202
echo " Starting evaluation of $model_name for mode: $quant_mode on GPU $gpu_id "
176
203
if [[ " ${latency_models[@]} " =~ " $model_name " ]]; then
177
204
CUDA_VISIBLE_DEVICES=$gpu_id python evaluate.py \
178
205
--onnx_path=$eval_model_path \
206
+ --engine_path=$engine_path \
179
207
--model_name=" ${timm_model_name[$model_name]} " \
180
208
--engine_precision=$precision \
181
209
--results_path=$model_dir /$quant_mode /${model_name} _${quant_mode} .csv &
182
210
else
183
211
CUDA_VISIBLE_DEVICES=$gpu_id python evaluate.py \
184
212
--onnx_path=$eval_model_path \
213
+ --engine_path=$engine_path \
185
214
--imagenet_path=$imagenet_path \
186
215
--eval_data_size=$calib_size \
187
216
--batch_size $batch_size \
@@ -209,6 +238,15 @@ for model_path in "${model_paths[@]}"; do
209
238
done
210
239
211
240
python $test_utils_dir /aggregate_results.py --results_dir=build
241
+
242
+ if [ " $clean_mode " = true ]; then
243
+ echo " Cleaning build artifacts..."
244
+ rm -rf build/
245
+ echo " Build artifacts cleaned successfully."
246
+ popd
247
+ exit 0
248
+ fi
249
+
212
250
popd
213
251
214
252
0 commit comments