-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·139 lines (119 loc) · 3.7 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# Check if configuration file is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <conf_file>"
exit 1
fi
CONF_FILE=$1
# Check if configuration file exists
if [ ! -f "$CONF_FILE" ]; then
echo "Error: Configuration file '$CONF_FILE' not found"
exit 1
fi
# Initialize variables
URL=""
MODEL=""
MODES=()
BATCH_SIZES=()
CONCURRENCIES=()
NUM_REQUESTS=1000 # Default value
# Parse configuration file
while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines and comments
if [[ -z "$line" || "$line" =~ ^# ]]; then
continue
fi
# Extract key and value
key=$(echo "$line" | cut -d= -f1 | tr -d ' ')
value=$(echo "$line" | cut -d= -f2-)
case "$key" in
URL)
URL="$value"
;;
MODEL)
MODEL="$value"
;;
MODE)
# Convert space-separated string to array
# First trim leading/trailing whitespace, then split on spaces
trimmed_value=$(echo "$value" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
IFS=' ' read -r -a MODES <<< "$trimmed_value"
;;
BATCH_SIZE)
# Convert space-separated string to array
# First trim leading/trailing whitespace, then split on spaces
trimmed_value=$(echo "$value" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
IFS=' ' read -r -a BATCH_SIZES <<< "$trimmed_value"
;;
CONCURRENCY)
# Convert space-separated string to array
# First trim leading/trailing whitespace, then split on spaces
trimmed_value=$(echo "$value" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
IFS=' ' read -r -a CONCURRENCIES <<< "$trimmed_value"
;;
NUM_REQUESTS)
NUM_REQUESTS=$(echo "$value" | tr -d ' ')
;;
*)
echo "Warning: Unknown setting '$key' in configuration file"
;;
esac
done < "$CONF_FILE"
if [ -z "$URL" ]; then
echo "Error: URL is not set in configuration file"
exit 1
fi
if [ -z "$MODEL" ]; then
echo "Error: MODEL is not set in configuration file"
exit 1
fi
# Use default values if arrays are empty
if [ ${#MODES[@]} -eq 0 ]; then
MODES=("query" "passage")
fi
if [ ${#BATCH_SIZES[@]} -eq 0 ]; then
BATCH_SIZES=(1 16 32 64)
fi
if [ ${#CONCURRENCIES[@]} -eq 0 ]; then
CONCURRENCIES=(1 4 8 16)
fi
echo "Starting benchmark suite with:"
echo " URL: $URL"
echo " Model: $MODEL"
echo " Modes: ${MODES[*]} (${#MODES[@]} modes)"
echo " Batch Sizes: ${BATCH_SIZES[*]} (${#BATCH_SIZES[@]} sizes)"
echo " Concurrencies: ${CONCURRENCIES[*]} (${#CONCURRENCIES[@]} concurrencies)"
echo " Number of Requests: $NUM_REQUESTS"
echo "----------------------------------------"
# Function to run a single benchmark
run_benchmark() {
local mode=$1
local batch_size=$2
local concurrency=$3
echo "Running benchmark with mode='$mode', batchSize='$batch_size', concurrency='$concurrency', numRequests='$NUM_REQUESTS'"
npm run bench -- --url "$URL" --model "$MODEL" --mode "$mode" --batchSize "$batch_size" --concurrency "$concurrency" --numRequests "$NUM_REQUESTS"
# Check if benchmark was successful
if [ $? -eq 0 ]; then
echo "SUCCESS"
else
echo "FAILED"
fi
}
# Run benchmarks for all combinations
TOTAL_RUNS=$((${#MODES[@]} * ${#BATCH_SIZES[@]} * ${#CONCURRENCIES[@]}))
CURRENT_RUN=0
echo "Total benchmark combinations to run: $TOTAL_RUNS"
echo "----------------------------------------"
for mode in "${MODES[@]}"; do
for batch_size in "${BATCH_SIZES[@]}"; do
for concurrency in "${CONCURRENCIES[@]}"; do
CURRENT_RUN=$((CURRENT_RUN + 1))
echo ""
echo "----------------------------------------"
echo "Run $CURRENT_RUN of $TOTAL_RUNS"
run_benchmark "$mode" "$batch_size" "$concurrency"
done
done
done
echo "----------------------------------------"
echo "Benchmark suite completed!"