Skip to content

Commit 1dbd21f

Browse files
author
Anindyadeep
committed
Added log in folder support, python alisas support and latest cli args
1 parent 6c2de48 commit 1dbd21f

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

bench_onnxruntime/bench.sh

+37-21
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@
22

33
########################################################################################################
44
# Script: bench.sh
5-
# Description: This script runs benchmarks onnxruntime llama benchmark.
5+
# Description: This script runs benchmarks ONNX Runtime Llama-2 benchmark.
66
#
77
# Usage: ./bench.sh [OPTIONS]
88
# OPTIONS:
9-
# -p, --prompt Prompt for benchmarks (default: 'Explain what is a transformer')
10-
# -r, --repetitions Number of repetitions for benchmarks (default: 2)
11-
# -m, --max_tokens Maximum number of tokens for benchmarks (default: 100)
12-
# -d, --device Device for benchmarks (possible values: 'metal', 'gpu', and 'cpu', default: 'cpu')
9+
# -p, --prompt Prompt for benchmarks (default: 'Write an essay about the transformer model architecture')
10+
# -r, --repetitions Number of repetitions for benchmarks (default: 10)
11+
# -m, --max_tokens Maximum number of tokens for benchmarks (default: 512)
12+
# -d, --device Device for benchmarks (possible values: 'metal', 'cuda', and 'cpu', default: 'cuda')
1313
# -lf, --log_file Logging file name.
1414
# -md, --models_dir Models directory.
1515
# -h, --help Show this help message
1616
########################################################################################################
1717

1818
set -euo pipefail
1919

20+
CURRENT_DIR="$(pwd)"
2021
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2122

2223
print_usage() {
2324
echo "Usage: $0 [OPTIONS]"
2425
echo "OPTIONS:"
25-
echo " -p, --prompt Prompt for benchmarks (default: 'Explain what is a transformer')"
26-
echo " -r, --repetitions Number of repetitions for benchmarks (default: 2)"
27-
echo " -m, --max_tokens Maximum number of tokens for benchmarks (default: 100)"
28-
echo " -d, --device Device for benchmarks (possible values: 'metal', 'gpu', and 'cpu', default: 'cpu')"
26+
echo " -p, --prompt Prompt for benchmarks (default: 'Write an essay about the transformer model architecture')"
27+
echo " -r, --repetitions Number of repetitions for benchmarks (default: 10)"
28+
echo " -m, --max_tokens Maximum number of tokens for benchmarks (default: 512)"
29+
echo " -d, --device Device for benchmarks (possible values: 'metal', 'cuda', and 'cpu', default: 'cuda')"
2930
echo " -lf, --log_file Logging file name."
3031
echo " -md, --models_dir Models directory."
3132
echo " -h, --help Show this help message"
3233
exit 1
3334
}
34-
3535
check_cuda() {
3636
if command -v nvcc &> /dev/null
3737
then
@@ -57,16 +57,29 @@ check_platform() {
5757
}
5858

5959
check_python() {
60-
if command -v python &> /dev/null
61-
then
62-
echo -e "\nUsing $(python --version)."
60+
if command -v python &> /dev/null; then
61+
PYTHON_CMD="python"
62+
elif command -v python3 &> /dev/null; then
63+
PYTHON_CMD="python3"
6364
else
64-
echo -e "\nPython does not exist."
65+
echo "Python is not installed."
6566
exit 1
6667
fi
6768
}
6869

6970
setup() {
71+
72+
# Check if Logs folder exists else Make the logs folder
73+
LOGS_FOLDER="$CURRENT_DIR/Logs"
74+
75+
if [ -d "$LOGS_FOLDER" ]; then
76+
echo "Folder '$LOGS_FOLDER' already exists. Skipping."
77+
else
78+
# Create the folder
79+
mkdir "$LOGS_FOLDER"
80+
echo "'$LOGS_FOLDER' created."
81+
fi
82+
7083
echo -e "\nSetting up with $SCRIPT_DIR/setup.sh..."
7184
bash "$SCRIPT_DIR"/setup.sh "$1"
7285
}
@@ -82,7 +95,7 @@ run_benchmarks() {
8295
# shellcheck disable=SC1091
8396
source "$SCRIPT_DIR/venv/bin/activate"
8497

85-
python "$SCRIPT_DIR"/bench.py \
98+
"$PYTHON_CMD" "$SCRIPT_DIR"/bench.py \
8699
--prompt "$PROMPT" \
87100
--repetitions "$REPETITIONS" \
88101
--max_tokens "$MAX_TOKENS" \
@@ -147,15 +160,18 @@ while [ "$#" -gt 0 ]; do
147160
;;
148161
esac
149162
done
150-
# Set default values if not provided
151-
PROMPT="${PROMPT:-"Explain what is a transformer"}"
152-
REPETITIONS="${REPETITIONS:-10}"
153-
MAX_TOKENS="${MAX_TOKENS:-100}"
154-
DEVICE="${DEVICE:-'cpu'}"
155-
LOG_FILENAME="${LOG_FILENAME:-"benchmark_$(date +'%Y%m%d%H%M%S').log"}"
163+
156164
MODELS_DIR="${MODELS_DIR:-"./models"}"
157165

158166
check_platform
159167
check_python
160168
setup "$MODELS_DIR"
169+
170+
# Set default values if not provided
171+
PROMPT="${PROMPT:-"Write an essay about the transformer model architecture"}"
172+
REPETITIONS="${REPETITIONS:-10}"
173+
MAX_TOKENS="${MAX_TOKENS:-512}"
174+
DEVICE="${DEVICE:-'cuda'}"
175+
LOG_FILENAME="${LOG_FILENAME:-"$LOGS_FOLDER/benchmark_onnx_$(date +'%Y%m%d%H%M%S').log"}"
176+
161177
run_benchmarks "$PROMPT" "$REPETITIONS" "$MAX_TOKENS" "$DEVICE" "$LOG_FILENAME" "$MODELS_DIR"

0 commit comments

Comments
 (0)