2121# It is recommended to execute this script inside the Model Optimization Toolkit TensorRT Docker container.
2222# Please ensure that the ImageNet dataset is available in the container at the specified path.
2323
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]
2525
2626set -exo pipefail
2727
@@ -34,12 +34,35 @@ cuda_capability=$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader | hea
3434
3535
3636pushd $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+
3760export TQDM_DISABLE=1
3861
3962
4063# 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}
4366calib_size=64
4467batch_size=1
4568
@@ -88,9 +111,9 @@ declare -A timm_model_name=(
88111latency_models=(" efficientnet_b0" " efficientnet_b3" " efficientnet-lite4-11" " faster_vit_timm_opset13_simplified" " faster_vit_timm_opset17_simplified" " inception-v1-12" " inception-v2-9" )
89112
90113# Create build directory to store all the results
114+ rm -rf build
91115mkdir -p build
92116
93-
94117# Iterate over each model path to create directories for all modes for each model
95118for model_path in " ${model_paths[@]} " ; do
96119 model_name=$( basename " $model_path " .onnx)
@@ -129,7 +152,8 @@ for model_path in "${model_paths[@]}"; do
129152 --onnx_path=$model_dir /fp16/model.onnx \
130153 --quantize_mode=$quant_mode \
131154 --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 &
133157 pids+=($! )
134158 done
135159
@@ -163,25 +187,30 @@ for model_path in "${model_paths[@]}"; do
163187
164188 if [ " $quant_mode " == " fp16" ]; then
165189 eval_model_path=$model_dir /fp16/model.onnx
190+ engine_path=$model_dir /fp16/model.engine
166191 precision=" fp16"
167192 elif [ " $quant_mode " == " int8_iq" ]; then
168193 eval_model_path=$model_dir /fp16/model.onnx
194+ engine_path=$model_dir /int8_iq/model.engine
169195 precision=" best"
170196 else
171197 eval_model_path=$model_dir /$quant_mode /model.quant.onnx
198+ engine_path=$model_dir /$quant_mode /model.quant.engine
172199 precision=" stronglyTyped"
173200 fi
174201
175202 echo " Starting evaluation of $model_name for mode: $quant_mode on GPU $gpu_id "
176203 if [[ " ${latency_models[@]} " =~ " $model_name " ]]; then
177204 CUDA_VISIBLE_DEVICES=$gpu_id python evaluate.py \
178205 --onnx_path=$eval_model_path \
206+ --engine_path=$engine_path \
179207 --model_name=" ${timm_model_name[$model_name]} " \
180208 --engine_precision=$precision \
181209 --results_path=$model_dir /$quant_mode /${model_name} _${quant_mode} .csv &
182210 else
183211 CUDA_VISIBLE_DEVICES=$gpu_id python evaluate.py \
184212 --onnx_path=$eval_model_path \
213+ --engine_path=$engine_path \
185214 --imagenet_path=$imagenet_path \
186215 --eval_data_size=$calib_size \
187216 --batch_size $batch_size \
@@ -209,6 +238,15 @@ for model_path in "${model_paths[@]}"; do
209238done
210239
211240python $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+
212250popd
213251
214252
0 commit comments