Skip to content

Instantly share code, notes, and snippets.

@mwakaba2
Last active January 1, 2022 23:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwakaba2/205b5b587429df628159117aa6df8fad to your computer and use it in GitHub Desktop.
Save mwakaba2/205b5b587429df628159117aa6df8fad to your computer and use it in GitHub Desktop.
Bash script to execute Bert Base Uncased Model benchmark tests in GCP (single thread)
#!/bin/bash
BENCHMARK_SCRIPT="onnxruntime/onnxruntime/python/tools/transformers/benchmark.py"
ITERATIONS=100
BATCH_SIZE=1
SEQUENCE_LENGTHS="8 16 128"
MODEL_NAME="bert-base-uncased"
MODEL_PATH="bert-base-uncased/"
NUM_THREADS=1
TIMESTAMP=$(date "+%Y.%m.%d-%H.%M.%S")
for SEQ_LEN in $SEQUENCE_LENGTHS; do
# Onnx Runtime Pytorch Model (fp32/int8)
python "${BENCHMARK_SCRIPT}" -m "${MODEL_NAME}" --model-path "${MODEL_PATH}" -v -i 1 --overwrite -b "${BATCH_SIZE}" -s "${SEQ_LEN}" -t "${ITERATIONS}" -f fusion.csv -r result.csv -d detail.csv -c ./cache_models --onnx_dir ./onnx_models --num_threads "${NUM_THREADS}" -o
python "${BENCHMARK_SCRIPT}" -m "${MODEL_NAME}" --model-path "${MODEL_PATH}" -v -i 1 --overwrite -b "${BATCH_SIZE}" -s "${SEQ_LEN}" -t "${ITERATIONS}" -f fusion.csv -r result.csv -d detail.csv -c ./cache_models --onnx_dir ./onnx_models --num_threads "${NUM_THREADS}" -o -p int8
# Onnx Runtime TF Model (fp32/int8)
python "${BENCHMARK_SCRIPT}" -m "${MODEL_NAME}" --model-path "${MODEL_PATH}" -v -i 1 --overwrite -b "${BATCH_SIZE}" -s "${SEQ_LEN}" -t "${ITERATIONS}" -f fusion.csv -r result.csv -d detail.csv -c ./cache_models --onnx_dir ./onnx_models --num_threads "${NUM_THREADS}" --model_source tf -o
python "${BENCHMARK_SCRIPT}" -m "${MODEL_NAME}" --model-path "${MODEL_PATH}" -v -i 1 --overwrite -b "${BATCH_SIZE}" -s "${SEQ_LEN}" -t "${ITERATIONS}" -f fusion.csv -r result.csv -d detail.csv -c ./cache_models --onnx_dir ./onnx_models --num_threads "${NUM_THREADS}" --model_source tf -o -p int8
# Pytorch Model (fp32/int8)
python "${BENCHMARK_SCRIPT}" -e torch -m "${MODEL_NAME}" --model-path "${MODEL_PATH}" -v -i 1 --overwrite -b "${BATCH_SIZE}" -s "${SEQ_LEN}" -t "${ITERATIONS}" -f fusion.csv -r result.csv -d detail.csv -c ./cache_models --onnx_dir ./onnx_models --num_threads "${NUM_THREADS}" -o
python "${BENCHMARK_SCRIPT}" -e torch -m "${MODEL_NAME}" --model-path "${MODEL_PATH}" -v -i 1 --overwrite -b "${BATCH_SIZE}" -s "${SEQ_LEN}" -t "${ITERATIONS}" -f fusion.csv -r result.csv -d detail.csv -c ./cache_models --onnx_dir ./onnx_models --num_threads "${NUM_THREADS}" -o -p int8
# Torchscript Model (fp32/int8)
python "${BENCHMARK_SCRIPT}" -e torchscript -m "${MODEL_NAME}" --model-path "${MODEL_PATH}" -v -i 1 --overwrite -b "${BATCH_SIZE}" -s "${SEQ_LEN}" -t "${ITERATIONS}" -f fusion.csv -r result.csv -d detail.csv -c ./cache_models --onnx_dir ./onnx_models --num_threads "${NUM_THREADS}" -o
python "${BENCHMARK_SCRIPT}" -e torchscript -m "${MODEL_NAME}" --model-path "${MODEL_PATH}" -v -i 1 --overwrite -b "${BATCH_SIZE}" -s "${SEQ_LEN}" -t "${ITERATIONS}" -f fusion.csv -r result.csv -d detail.csv -c ./cache_models --onnx_dir ./onnx_models --num_threads "${NUM_THREADS}" -o -p int8
# Tensorflow Model (fp32/int8)
python "${BENCHMARK_SCRIPT}" -e tensorflow -m "${MODEL_NAME}" --model-path "${MODEL_PATH}" -v -i 1 --overwrite -b "${BATCH_SIZE}" -s "${SEQ_LEN}" -t "${ITERATIONS}" -f fusion.csv -r result.csv -d detail.csv -c ./cache_models --onnx_dir ./onnx_models --num_threads "${NUM_THREADS}" -o
python "${BENCHMARK_SCRIPT}" -e tensorflow -m "${MODEL_NAME}" --model-path "${MODEL_PATH}" -v -i 1 --overwrite -b "${BATCH_SIZE}" -s "${SEQ_LEN}" -t "${ITERATIONS}" -f fusion.csv -r result.csv -d detail.csv -c ./cache_models --onnx_dir ./onnx_models --num_threads "${NUM_THREADS}" -o -p int8
awk '!x[$0]++' ./result.csv > "summary_result_openmp_seq_len_${SEQ_LEN}_${TIMESTAMP}.csv"
awk '!x[$0]++' ./fusion.csv > "summary_fusion_openmp_seq_len_${SEQ_LEN}_${TIMESTAMP}.csv"
awk '!x[$0]++' ./detail.csv > "summary_detail_openmp_seq_len_${SEQ_LEN}_${TIMESTAMP}.csv"
done
# Upload results to GCS bucket
gsutil cp "summary*" gs://bert-inference-results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment