2
2
3
3
# #######################################################################################################
4
4
# Script: bench.sh
5
- # Description: This script runs benchmarks onnxruntime llama benchmark.
5
+ # Description: This script runs benchmarks ONNX Runtime Llama-2 benchmark.
6
6
#
7
7
# Usage: ./bench.sh [OPTIONS]
8
8
# 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 ')
13
13
# -lf, --log_file Logging file name.
14
14
# -md, --models_dir Models directory.
15
15
# -h, --help Show this help message
16
16
# #######################################################################################################
17
17
18
18
set -euo pipefail
19
19
20
+ CURRENT_DIR=" $( pwd) "
20
21
SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
21
22
22
23
print_usage () {
23
24
echo " Usage: $0 [OPTIONS]"
24
25
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 ')"
29
30
echo " -lf, --log_file Logging file name."
30
31
echo " -md, --models_dir Models directory."
31
32
echo " -h, --help Show this help message"
32
33
exit 1
33
34
}
34
-
35
35
check_cuda () {
36
36
if command -v nvcc & > /dev/null
37
37
then
@@ -57,16 +57,29 @@ check_platform() {
57
57
}
58
58
59
59
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"
63
64
else
64
- echo -e " \nPython does not exist ."
65
+ echo " Python is not installed ."
65
66
exit 1
66
67
fi
67
68
}
68
69
69
70
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
+
70
83
echo -e " \nSetting up with $SCRIPT_DIR /setup.sh..."
71
84
bash " $SCRIPT_DIR " /setup.sh " $1 "
72
85
}
@@ -82,7 +95,7 @@ run_benchmarks() {
82
95
# shellcheck disable=SC1091
83
96
source " $SCRIPT_DIR /venv/bin/activate"
84
97
85
- python " $SCRIPT_DIR " /bench.py \
98
+ " $PYTHON_CMD " " $SCRIPT_DIR " /bench.py \
86
99
--prompt " $PROMPT " \
87
100
--repetitions " $REPETITIONS " \
88
101
--max_tokens " $MAX_TOKENS " \
@@ -147,15 +160,18 @@ while [ "$#" -gt 0 ]; do
147
160
;;
148
161
esac
149
162
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
+
156
164
MODELS_DIR=" ${MODELS_DIR:- " ./models" } "
157
165
158
166
check_platform
159
167
check_python
160
168
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
+
161
177
run_benchmarks " $PROMPT " " $REPETITIONS " " $MAX_TOKENS " " $DEVICE " " $LOG_FILENAME " " $MODELS_DIR "
0 commit comments