ollama-test, enhance to me like pv-test with the parameter looping, also fix some variables being set via env and add QUIET to suppress all but the table.

This commit is contained in:
me committed 2026-10-24 20:41:38 -07:00
1 parent 933e00556c
commit f3da185fb6
1 file changed
+68 -67
+68 -67
View File
@@ -1566,10 +1566,21 @@ alias ollama-cpu="ollama_threads "
function ollama_benchmark_usage() { function ollama_benchmark_usage() {
cat <<- EOF cat <<- EOF
USAGE: ollama-benchmark CONTEXT [THREADS] [iGPU] [MODEL] [-h | --help] USAGE: ollama-benchmark CONTEXTS [THREADS] [IGPUS] [MODELS] [-h | --help]
Tests installed models at a certain context, thread count, and iGPU setting. Tests installed models at a certain context, thread count, and iGPU setting.
PARAMETERS
CONTEXTS
Sent as num_ctx to ollama. No default.
THREADS
Sent as num_threads to ollama. Defaults to 0.
IGPUS
Values to set OLLAMA_IGPU_ENABLE to. Defaults to 1.
MODELS
Model names to test. Defaults to all of `ollama ls`.
EXAMPLES: EXAMPLES:
Test models with at a context of 32000, default threads, and iGPU enabled. Test models with at a context of 32000, default threads, and iGPU enabled.
@@ -1585,6 +1596,11 @@ function ollama_benchmark_usage() {
context=64000 igpu=0 ollama-benchmark context=64000 igpu=0 ollama-benchmark
context=64000 model=qwen3.5:4b ollama-benchmark context=64000 model=qwen3.5:4b ollama-benchmark
The parameters can also act as arrays to cause extra looping.
ollama-benchmark "32000 64000 128000 256000" "4 7 0" "0 1" \
"qwen3.8:27b qwen3.6:35b qwen3.6:27b qwen3.5:35b qwen3.5:27b"
Aliases: Aliases:
ollama-test ollama-test
@@ -1599,50 +1615,40 @@ function ollama_benchmark() {
return 0 return 0
fi fi
typeset -i context contexts="${1:-$contexts}"
if [[ -z $context || $context == 0 ]]; then if [[ -z "$contexts" ]]; then
context="$1"
fi
if [[ -z "$context" ]]; then
echo " ERROR: Context is required." echo " ERROR: Context is required."
ollama_benchmark_usage ollama_benchmark_usage
return 1 return 1
fi fi
typeset -i threads threads="${2:-$threads}"
if [[ -z $threads ]]; then
threads="$2"
fi
if [[ -z $threads ]]; then if [[ -z $threads ]]; then
threads=0 threads=0
fi fi
declare igpu igpus="${3:-$igpus}"
if [[ -z "$igpu" ]] ; then if [[ -z "$igpus" ]] ; then
igpu="$3" igpus=1
fi
if [[ -z "$igpu" ]] ; then
igpu=1
fi
export OLLAMA_IGPU_ENABLE=$igpu
export OLLAMA_VULKAN=$igpu
declare model
if [[ -z "$model" ]] ; then
model="$4"
fi fi
echo -e "\n Sharing run parameters..." models="${4:-$models}"
cat <<- EOF if [[ -z "$models" ]]; then
models="`ollama ls | grep -v NAME | awk '{print $1}'`"
fi
DEBUG="${DEBUG}"
QUIET="${QUIET}"
[[ -z "$QUIET" ]] && echo -e "\n Sharing run parameters..."
[[ -z "$QUIET" ]] && cat <<- EOF
DEBUG=$DEBUG DEBUG=$DEBUG
QUIET=$QUIET
context=$context context=$context
threads=$threads threads=$threads
igpu=$igpu igpu=$igpu
OLLAMA_IGPU_ENABLE=$OLLAMA_IGPU_ENABLE
OLLAMA_VULKAN=$OLLAMA_IGPU_ENABLE
model=$model model=$model
EOF EOF
echo " Done!" [[ -z "$QUIET" ]] && echo " Done!"
# Variables # Variables
@@ -1651,11 +1657,13 @@ function ollama_benchmark() {
col_ctx=8 col_ctx=8
col_ram=6 col_ram=6
col_thr=7 col_thr=7
col_gpu=4
col_cpu=9 col_cpu=9
col_spd=11 col_spd_round=2 col_spd=11 col_spd_round=2
col_tim=8 col_tim=8
log_file="ollama_benchmark.log.txt" log_file="ollama_benchmark.log.txt"
[[ -z "$QUIET" ]] && echo -e "\n Logging ollama to '$log_file'..."
declare champ_{speed,time}_{model,num} declare champ_{speed,time}_{model,num}
@@ -1670,49 +1678,39 @@ function ollama_benchmark() {
# Main # Main
if [[ ! -d /sdcard && -d /etc/sv ]]; then if [[ ! -d /sdcard && -d /etc/sv ]]; then
echo -e "\n Stopping ollama runit service..." [[ -z "$QUIET" ]] && echo -e "\n Stopping ollama runit service..."
sudo sv disable ollama sudo sv disable ollama >/dev/null 2>&1
sudo sv stop ollama sudo sv stop ollama >/dev/null 2>&1
sleep 5 sleep 5
echo " Done!" [[ -z "$QUIET" ]] && echo " Done!"
fi fi
echo -e "\n Stopping any ollama processes..." [[ -z "$QUIET" ]] && echo -e "\n Starting main loop... \n"
killall ollama
sleep 5
echo " Done!"
echo -e "\n Starting background ollama service, logging to '$log_file'..." printf "| %-${col_mdl}s | %${col_hdd}s | %${col_ctx}s | %${col_ram}s | %${col_thr}s | %${col_gpu}s | %${col_cpu}s | %${col_spd}s | %${col_tim}s |\n" \
"Model" "HDD" "Context" "RAM" "Threads" "iGPU" "Processor" "Speed (t/s)" "Time (s)"
printf "| %-${col_mdl}s | %${col_hdd}s | %${col_ctx}s | %${col_ram}s | %${col_thr}s | %${col_gpu}s | %${col_cpu}s | %${col_spd}s | %${col_tim}s |\n" \
":------------------------" "-----:" "-------:" "-----:" "---:" "------:" "--------:" "----------:" "-------:"
for model in $models; do
for context in $contexts; do
for thread in $threads; do
for igpu in $igpus; do
(killall ollama >/dev/null 2>&1)
sleep 5
export OLLAMA_IGPU_ENABLE=$igpu
export OLLAMA_VULKAN=$igpu
(ollama serve >$log_file 2>&1 &) (ollama serve >$log_file 2>&1 &)
wait_for_ollama wait_for_ollama
echo " Done!"
echo -e "\n Starting main loop... \n"
printf "| %-${col_mdl}s | %${col_hdd}s | %${col_ctx}s | %${col_ram}s | %${col_thr}s | %${col_cpu}s | %${col_spd}s | %${col_tim}s |\n" \
"Model @ CTX=$context" "HDD" "Context" "RAM" "Threads" "Processor" "Speed (t/s)" "Time (s)"
printf "| %-${col_mdl}s | %${col_hdd}s | %${col_ctx}s | %${col_ram}s | %${col_thr}s | %${col_cpu}s | %${col_spd}s | %${col_tim}s |\n" \
":------------------------" "-----:" "-------:" "-----:" "------:" "--------:" "----------:" "-------:"
model_focus="$model"
unset model
for model in `ollama ls | grep -v NAME | awk '{print $1}'`; do
# If a model was specified then only focus on it.
if [[ -n "$model_focus" ]]; then
if [[ "$model" != "$model_focus" ]]; then
continue;
fi
fi
hdd="`ollama ls | grep $model | awk '{print $3 $4}'`" hdd="`ollama ls | grep $model | awk '{print $3 $4}'`"
printf "| %-${col_mdl}s | %${col_hdd}s | " "$model" "$hdd" printf "| %-${col_mdl}s | %${col_hdd}s | " "$model" "$hdd"
# Start the model and store the response. # Start the model and store the response.
start=$SECONDS start=$SECONDS
speed_json=$(curl -s http://localhost:11434/api/generate \ speed_json=$(curl -s http://localhost:11434/api/generate \
-d '{"model":"'$model'","prompt":"Hello","stream":false,"keep_alive":"1m","options":{"num_ctx":'$context',"num_thread":'$threads'}}' \ -d '{"model":"'$model'","prompt":"Hello","stream":false,"keep_alive":"1m","options":{"num_ctx":'$context',"num_thread":'$thread'}}' \
2>/dev/null 2>/dev/null
) )
status_ollama=$? status_ollama=$?
@@ -1775,8 +1773,8 @@ function ollama_benchmark() {
fi fi
fi fi
printf "%${col_ctx}s | %${col_ram}s | %${col_thr}s | %${col_cpu}s | %${col_spd}.${col_spd_round}f | %${col_tim}s |\n" \ printf "%${col_ctx}s | %${col_ram}s | %${col_thr}s | %${col_gpu}s | %${col_cpu}s | %${col_spd}.${col_spd_round}f | %${col_tim}s |\n" \
"$ctx" "$ram" "$threads" "$cpu" "$speed" "$time" "$ctx" "$ram" "$thread" "$igpu" "$cpu" "$speed" "$time"
ollama stop $model >/dev/null 2>&1 ollama stop $model >/dev/null 2>&1
while ollama ps | grep "$model"; do while ollama ps | grep "$model"; do
@@ -1784,27 +1782,30 @@ function ollama_benchmark() {
sleep 1 sleep 1
done done
done done
done
done
done
echo -e "\n Done!! :D \n" [[ -z "$QUIET" ]] && echo -e "\n Done!! :D \n"
cat <<- EOF [[ -z "$QUIET" ]] && cat <<- EOF
Speed Champion: $champ_speed_model with a tokens/seconds of ${champ_speed_num}! Speed Champion: $champ_speed_model with a tokens/seconds of ${champ_speed_num}!
Time Champion: $champ_time_model with a time of ${champ_time_num}! Time Champion: $champ_time_model with a time of ${champ_time_num}!
EOF EOF
# Finish # Finish
echo -e "\n Killing local ollama serve..." [[ -z "$QUIET" ]] && echo -e "\n Killing local ollama serve..."
killall ollama killall ollama
echo " Done!" [[ -z "$QUIET" ]] && echo " Done!"
if [[ ! -d /sdcard && -d /etc/sv ]]; then if [[ ! -d /sdcard && -d /etc/sv ]]; then
echo -e "\n Restarting runit service..." [[ -z "$QUIET" ]] && echo -e "\n Restarting runit service..."
sudo sv enable ollama sudo sv enable ollama
sudo sv start ollama sudo sv start ollama
echo " Done!" [[ -z "$QUIET" ]] && echo " Done!"
fi fi
echo -e "\n Done!!! :)" [[ -z "$QUIET" ]] && echo -e "\n Done!!! :)"
} }
alias ollama-benchmark="ollama_benchmark " alias ollama-benchmark="ollama_benchmark "
alias ollama-test="ollama_benchmark " alias ollama-test="ollama_benchmark "