Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 12 additions & 48 deletions tests/examples/test_onnx_ptq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,38 +137,20 @@ for model_path in "${model_paths[@]}"; do
model_name=$(basename "$model_path" .onnx)
model_dir=build/$model_name


echo "Quantizing model $model_name for all quantization modes in parallel"
pids=()
for i in "${!quant_modes[@]}"; do
quant_mode="${quant_modes[$i]}"
gpu_id=$((i % nvidia_gpu_count))
echo "Quantizing model $model_name for all quantization modes"
for quant_mode in "${quant_modes[@]}"; do
if [ "$quant_mode" == "int8_iq" ]; then
continue
fi

echo "Starting quantization of $model_name for mode: $quant_mode on GPU $gpu_id"
CUDA_VISIBLE_DEVICES=$gpu_id python -m modelopt.onnx.quantization \
echo "Starting quantization of $model_name for mode: $quant_mode"
python -m modelopt.onnx.quantization \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this support multi-gpu calibration to use all available GPUs instead of cuda:0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should be able to control which GPU is getting used using CUDA_VISIBLE_DEVICES. However for now, I have disabled the GPU parallelism in the test till I figure out the root cause.

--onnx_path=$model_dir/fp16/model.onnx \
--quantize_mode=$quant_mode \
--calibration_data=$calib_data_path \
--output_path=$model_dir/$quant_mode/model.quant.onnx \
--calibration_eps=cuda:0 &
pids+=($!)
done

# Wait for all quantization processes to complete for this model
error_occurred=false
for pid in "${pids[@]}"; do
if ! wait $pid; then
echo "ERROR: Quantization process (PID: $pid) failed"
error_occurred=true
fi
--calibration_eps=cuda:0
done
if [ "$error_occurred" = true ]; then
echo "Stopping execution due to quantization failure for model: $model_name"
exit 1
fi

echo "Completed quantization of all modes for model: $model_name"
done
Expand All @@ -179,12 +161,8 @@ for model_path in "${model_paths[@]}"; do
model_name=$(basename "$model_path" .onnx)
model_dir=build/$model_name

echo "Evaluating model $model_name for all quantization modes in parallel"
pids=()
for i in "${!all_modes[@]}"; do
quant_mode="${all_modes[$i]}"
gpu_id=$((i % nvidia_gpu_count))

echo "Evaluating model $model_name for all quantization modes"
for quant_mode in "${all_modes[@]}"; do
if [ "$quant_mode" == "fp16" ]; then
eval_model_path=$model_dir/fp16/model.onnx
engine_path=$model_dir/fp16/model.engine
Expand All @@ -199,40 +177,26 @@ for model_path in "${model_paths[@]}"; do
precision="stronglyTyped"
fi

echo "Starting evaluation of $model_name for mode: $quant_mode on GPU $gpu_id"
echo "Starting evaluation of $model_name for mode: $quant_mode"
if [[ " ${latency_models[@]} " =~ " $model_name " ]]; then
CUDA_VISIBLE_DEVICES=$gpu_id python evaluate.py \
python evaluate.py \
--onnx_path=$eval_model_path \
--engine_path=$engine_path \
--model_name="${timm_model_name[$model_name]}" \
--engine_precision=$precision \
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv &
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv
else
CUDA_VISIBLE_DEVICES=$gpu_id python evaluate.py \
python evaluate.py \
--onnx_path=$eval_model_path \
--engine_path=$engine_path \
--imagenet_path=$imagenet_path \
--eval_data_size=$calib_size \
--batch_size $batch_size \
--model_name="${timm_model_name[$model_name]}" \
--engine_precision=$precision \
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv &
fi
pids+=($!)
done

# Wait for all evaluation processes to complete for this model
error_occurred=false
for pid in "${pids[@]}"; do
if ! wait $pid; then
echo "ERROR: Evaluation process (PID: $pid) failed"
error_occurred=true
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix array membership test (shellcheck) and quote all args

  • Use glob match with ${array[*]} for membership; satisfies SC2199/SC2076 and avoids regex pitfalls.
  • Quote all path/vars in evaluate.py calls to prevent word splitting.

Apply:

-        echo "Starting evaluation of $model_name for mode: $quant_mode"
-        if [[ " ${latency_models[@]} " =~ " $model_name " ]]; then
-            python evaluate.py \
-                --onnx_path=$eval_model_path \
-                --engine_path=$engine_path \
-                --model_name="${timm_model_name[$model_name]}" \
-                --engine_precision=$precision \
-                --results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv
+        echo "Starting evaluation of $model_name for mode: $quant_mode"
+        if [[ " ${latency_models[*]} " == *" $model_name "* ]]; then
+            python evaluate.py \
+                --onnx_path="$eval_model_path" \
+                --engine_path="$engine_path" \
+                --model_name="${timm_model_name[$model_name]}" \
+                --engine_precision="$precision" \
+                --results_path="$model_dir/$quant_mode/${model_name}_${quant_mode}.csv"
         else
-            python evaluate.py \
-                --onnx_path=$eval_model_path \
-                --engine_path=$engine_path \
-                --imagenet_path=$imagenet_path \
-                --eval_data_size=$calib_size \
-                --batch_size $batch_size \
-                --model_name="${timm_model_name[$model_name]}" \
-                --engine_precision=$precision \
-                --results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv
+            python evaluate.py \
+                --onnx_path="$eval_model_path" \
+                --engine_path="$engine_path" \
+                --imagenet_path="$imagenet_path" \
+                --eval_data_size="$calib_size" \
+                --batch_size "$batch_size" \
+                --model_name="${timm_model_name[$model_name]}" \
+                --engine_precision="$precision" \
+                --results_path="$model_dir/$quant_mode/${model_name}_${quant_mode}.csv"

Based on Shellcheck hints.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
echo "Starting evaluation of $model_name for mode: $quant_mode"
if [[ " ${latency_models[@]} " =~ " $model_name " ]]; then
CUDA_VISIBLE_DEVICES=$gpu_id python evaluate.py \
python evaluate.py \
--onnx_path=$eval_model_path \
--engine_path=$engine_path \
--model_name="${timm_model_name[$model_name]}" \
--engine_precision=$precision \
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv &
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv
else
CUDA_VISIBLE_DEVICES=$gpu_id python evaluate.py \
python evaluate.py \
--onnx_path=$eval_model_path \
--engine_path=$engine_path \
--imagenet_path=$imagenet_path \
--eval_data_size=$calib_size \
--batch_size $batch_size \
--model_name="${timm_model_name[$model_name]}" \
--engine_precision=$precision \
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv &
fi
pids+=($!)
done
# Wait for all evaluation processes to complete for this model
error_occurred=false
for pid in "${pids[@]}"; do
if ! wait $pid; then
echo "ERROR: Evaluation process (PID: $pid) failed"
error_occurred=true
--results_path=$model_dir/$quant_mode/${model_name}_${quant_mode}.csv
fi
echo "Starting evaluation of $model_name for mode: $quant_mode"
if [[ " ${latency_models[*]} " == *" $model_name "* ]]; then
python evaluate.py \
--onnx_path="$eval_model_path" \
--engine_path="$engine_path" \
--model_name="${timm_model_name[$model_name]}" \
--engine_precision="$precision" \
--results_path="$model_dir/$quant_mode/${model_name}_${quant_mode}.csv"
else
python evaluate.py \
--onnx_path="$eval_model_path" \
--engine_path="$engine_path" \
--imagenet_path="$imagenet_path" \
--eval_data_size="$calib_size" \
--batch_size "$batch_size" \
--model_name="${timm_model_name[$model_name]}" \
--engine_precision="$precision" \
--results_path="$model_dir/$quant_mode/${model_name}_${quant_mode}.csv"
fi
🧰 Tools
🪛 Shellcheck (0.11.0)

[error] 181-181: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[warning] 181-181: Remove quotes from right-hand side of =~ to match as a regex rather than literally.

(SC2076)

🤖 Prompt for AI Agents
In tests/examples/test_onnx_ptq.sh around lines 180-198, the array membership
test and unquoted arguments are unsafe; replace the current if-condition with a
glob-style check using the array expansion e.g. [[ " ${latency_models[*]} " ==
*" $model_name "* ]] to satisfy ShellCheck (SC2199/SC2076), and quote all
variables passed to python evaluate.py (e.g. "$eval_model_path", "$engine_path",
"$imagenet_path", "$calib_size", "$batch_size",
"${timm_model_name[$model_name]}", "$precision",
"$model_dir/$quant_mode/${model_name}_${quant_mode}.csv") so none are word-split
or subject to globbing.

done
if [ "$error_occurred" = true ]; then
echo "Stopping execution due to evaluation failure for model: $model_name"
exit 1
fi

echo "Completed evaluation of all modes for model: $model_name"
done
Expand Down