comparemodels.sh 1.86 KB
Newer Older
1
#! /usr/bin/env bash
Matt Williams's avatar
Matt Williams committed
2
3
# Compare multiple models by running them with the same questions

4
5
6
7
NUMBEROFCHOICES=4
SELECTIONS=()
declare -a SUMS=()

Matt Williams's avatar
Matt Williams committed
8
9
10
11
# Get the list of models
CHOICES=$(ollama list | awk '{print $1}')

# Select which models to run as a comparison
12
13
14
15
16
17
18
19
20
21
22
23
24
25
echo "Select $NUMBEROFCHOICES models to compare:"
select ITEM in $CHOICES; do
    if [[ -n $ITEM ]]; then
        echo "You have selected $ITEM"
        SELECTIONS+=("$ITEM")
        ((COUNT++))
        if [[ $COUNT -eq $NUMBEROFCHOICES ]]; then
            break
        fi
    else
        echo "Invalid selection"
    fi
done

Matt Williams's avatar
Matt Williams committed
26
# Loop through each of the selected models
27
28
29
30
31
32
33
34
for ITEM in "${SELECTIONS[@]}"; do
    echo "--------------------------------------------------------------"
    echo "Loading the model $ITEM into memory"
    ollama run "$ITEM" ""
    echo "--------------------------------------------------------------"
    echo "Running the questions through the model $ITEM"
    COMMAND_OUTPUT=$(ollama run "$ITEM" --verbose < sourcequestions 2>&1| tee /dev/stderr)

Matt Williams's avatar
Matt Williams committed
35
36
    # eval duration is sometimes listed in seconds and sometimes in milliseconds. 
    # Add up the values for each model
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
    SUM=$(echo "$COMMAND_OUTPUT" | awk '
    /eval duration:/ {
        value = $3
        if (index(value, "ms") > 0) {
            gsub("ms", "", value)
            value /= 1000
        } else {
            gsub("s", "", value)
        }
        sum += value
    }
    END { print sum }')


    SUMS+=("All questions for $ITEM completed in $SUM seconds")
done

echo ""
echo "--------------------------------------------------------------"
echo -e "Sums of eval durations for each run:"
for val in "${SUMS[@]}"; do
    echo "$val"
done

echo "--------------------------------------------------------------"
echo "Comparison complete. Now you can decide"
echo "which model is best."
echo "--------------------------------------------------------------"