Skip to content

Commit 276e2dd

Browse files
committed
Disable model evaluation by default
Signed-off-by: ajrasane <[email protected]>
1 parent 0951c2c commit 276e2dd

File tree

1 file changed

+53
-45
lines changed

1 file changed

+53
-45
lines changed

tests/examples/test_onnx_ptq.sh

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
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 [--no-clean] [/path/to/imagenet] [/path/to/models]
24+
# Usage: ./test_onnx_ptq.sh [--no-clean] [--eval] [/path/to/imagenet] [/path/to/models]
2525

2626
set -exo pipefail
2727

@@ -37,6 +37,7 @@ pushd $public_example_dir
3737

3838
# Parse arguments
3939
clean_mode=true
40+
eval_mode=false
4041
imagenet_path=""
4142
models_folder=""
4243

@@ -46,6 +47,10 @@ for arg in "$@"; do
4647
clean_mode=false
4748
shift
4849
;;
50+
--eval)
51+
eval_mode=true
52+
shift
53+
;;
4954
*)
5055
if [ -z "$imagenet_path" ]; then
5156
imagenet_path="$arg"
@@ -63,7 +68,8 @@ export TQDM_DISABLE=1
6368
# Setting image and model paths (contains 8 models)
6469
imagenet_path=${imagenet_path:-/data/imagenet/}
6570
models_folder=${models_folder:-/models/onnx}
66-
calib_size=64
71+
calib_size=1
72+
eval_size=100
6773
batch_size=1
6874

6975

@@ -157,53 +163,55 @@ done
157163

158164

159165
# Evaluate the quantized models for each mode
160-
for model_path in "${model_paths[@]}"; do
161-
model_name=$(basename "$model_path" .onnx)
162-
model_dir=build/$model_name
166+
if [ "$eval_mode" = true ]; then
167+
for model_path in "${model_paths[@]}"; do
168+
model_name=$(basename "$model_path" .onnx)
169+
model_dir=build/$model_name
170+
171+
echo "Evaluating model $model_name for all quantization modes"
172+
for quant_mode in "${all_modes[@]}"; do
173+
if [ "$quant_mode" == "fp16" ]; then
174+
eval_model_path=$model_dir/fp16/model.onnx
175+
engine_path=$model_dir/fp16/model.engine
176+
precision="fp16"
177+
elif [ "$quant_mode" == "int8_iq" ]; then
178+
eval_model_path=$model_dir/fp16/model.onnx
179+
engine_path=$model_dir/int8_iq/model.engine
180+
precision="best"
181+
else
182+
eval_model_path=$model_dir/$quant_mode/model.quant.onnx
183+
engine_path=$model_dir/$quant_mode/model.quant.engine
184+
precision="stronglyTyped"
185+
fi
163186

164-
echo "Evaluating model $model_name for all quantization modes"
165-
for quant_mode in "${all_modes[@]}"; do
166-
if [ "$quant_mode" == "fp16" ]; then
167-
eval_model_path=$model_dir/fp16/model.onnx
168-
engine_path=$model_dir/fp16/model.engine
169-
precision="fp16"
170-
elif [ "$quant_mode" == "int8_iq" ]; then
171-
eval_model_path=$model_dir/fp16/model.onnx
172-
engine_path=$model_dir/int8_iq/model.engine
173-
precision="best"
174-
else
175-
eval_model_path=$model_dir/$quant_mode/model.quant.onnx
176-
engine_path=$model_dir/$quant_mode/model.quant.engine
177-
precision="stronglyTyped"
178-
fi
187+
echo "Starting evaluation of $model_name for mode: $quant_mode"
188+
if [[ " ${latency_models[@]} " =~ " $model_name " ]]; then
189+
python evaluate.py \
190+
--onnx_path=$eval_model_path \
191+
--engine_path=$engine_path \
192+
--model_name="${timm_model_name[$model_name]}" \
193+
--engine_precision=$precision \
194+
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv \
195+
--timing_cache_path=build/timing.cache
196+
else
197+
python evaluate.py \
198+
--onnx_path=$eval_model_path \
199+
--engine_path=$engine_path \
200+
--imagenet_path=$imagenet_path \
201+
--eval_data_size=$eval_size \
202+
--batch_size $batch_size \
203+
--model_name="${timm_model_name[$model_name]}" \
204+
--engine_precision=$precision \
205+
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv \
206+
--timing_cache_path=build/timing.cache
207+
fi
208+
done
179209

180-
echo "Starting evaluation of $model_name for mode: $quant_mode"
181-
if [[ " ${latency_models[@]} " =~ " $model_name " ]]; then
182-
python evaluate.py \
183-
--onnx_path=$eval_model_path \
184-
--engine_path=$engine_path \
185-
--model_name="${timm_model_name[$model_name]}" \
186-
--engine_precision=$precision \
187-
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv \
188-
--timing_cache_path=build/timing.cache
189-
else
190-
python evaluate.py \
191-
--onnx_path=$eval_model_path \
192-
--engine_path=$engine_path \
193-
--imagenet_path=$imagenet_path \
194-
--eval_data_size=$calib_size \
195-
--batch_size $batch_size \
196-
--model_name="${timm_model_name[$model_name]}" \
197-
--engine_precision=$precision \
198-
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv \
199-
--timing_cache_path=build/timing.cache
200-
fi
210+
echo "Completed evaluation of all modes for model: $model_name"
201211
done
202212

203-
echo "Completed evaluation of all modes for model: $model_name"
204-
done
205-
206-
python $test_utils_dir/aggregate_results.py --results_dir=build
213+
python $test_utils_dir/aggregate_results.py --results_dir=build
214+
fi
207215

208216
if [ "$clean_mode" = true ]; then
209217
echo "Cleaning build artifacts..."

0 commit comments

Comments
 (0)