forked from mikepapadim/llama2.tornadovm.java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·79 lines (70 loc) · 2.55 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
#!/bin/bash
# Print usage information
usage() {
echo "Usage:"
echo "TornadoVM Execution: $0 [-n <workgroup size> -v <-Dllama2.Vector[Float4|Float8|Float16]=true>] <.bin file>"
echo "Java Execution: $0 -j java <.bin file>"
exit 1
}
# Execute Llama2 with TornadoVM
execute_command() {
if [ -n "$java" ]; then
echo "Running Llama2 with pure Java"
tornado --jvm=" -Dllama2.Java=true " -cp target/tornadovm-llama-gpu-1.0-SNAPSHOT.jar io.github.mikepapadim.Llama2 $token_file
elif [ -n "$workgroup_size" ]; then
if [ -n "$vector_mode" ]; then
echo "Running Llama2 with TornadoVM: workgroup size=$workgroup_size, token file=$token_file, vector mode=$vector_mode"
tornado --jvm=" -Ds0.t0.local.workgroup.size=$workgroup_size $vector_mode" -cp target/tornadovm-llama-gpu-1.0-SNAPSHOT.jar io.github.mikepapadim.Llama2 $token_file
else
echo "Running Llama2 with TornadoVM: workgroup size=$workgroup_size, token file=$token_file"
tornado --jvm=" -Ds0.t0.local.workgroup.size=$workgroup_size " -cp target/tornadovm-llama-gpu-1.0-SNAPSHOT.jar io.github.mikepapadim.Llama2 $token_file
fi
else
if [ -n "$vector_mode" ]; then
echo "Running Llama2 with TornadoVM: default workgroup size=64, token file=$token_file, vector mode=$vector_mode"
tornado --jvm=" -Ds0.t0.local.workgroup.size=64 $vector_mode" -cp target/tornadovm-llama-gpu-1.0-SNAPSHOT.jar io.github.mikepapadim.Llama2 $token_file
else
echo "Running Llama2 with TornadoVM: default workgroup size=64, token file=$token_file"
tornado --jvm=" -Ds0.t0.local.workgroup.size=64 " -cp target/tornadovm-llama-gpu-1.0-SNAPSHOT.jar io.github.mikepapadim.Llama2 $token_file
fi
fi
}
# Parse command line options to identify arguments for the workgroup size, the vector type, or the java execution mode, if provided
parse_options() {
while getopts ":n:v:j:" opt; do
case $opt in
n)
workgroup_size="$OPTARG"
;;
v)
vector_mode="$OPTARG"
;;
j)
java="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
}
# Main function
main() {
# Parse command line options
parse_options "$@"
# Shift to get the input token file, which is a mandatory input
shift $((OPTIND - 1))
# Check if the token file argument was provided
if [ $# -eq 0 ]; then
echo "Error: Missing token file argument." >&2
usage
fi
token_file="$1"
execute_command
}
main "$@"