1#!/usr/bin/env bash
2set -e
3
4# Read the first argument into a variable
5arg1="$1"
6
7# Shift the arguments to remove the first one
8shift
9
10if [[ "$arg1" == '--convert' || "$arg1" == '-c' ]]; then
11 exec python3 ./convert_hf_to_gguf.py "$@"
12elif [[ "$arg1" == '--quantize' || "$arg1" == '-q' ]]; then
13 exec ./llama-quantize "$@"
14elif [[ "$arg1" == '--run' || "$arg1" == '-r' ]]; then
15 exec ./llama-cli "$@"
16elif [[ "$arg1" == '--run-legacy' || "$arg1" == '-l' ]]; then
17 exec ./llama-completion "$@"
18elif [[ "$arg1" == '--bench' || "$arg1" == '-b' ]]; then
19 exec ./llama-bench "$@"
20elif [[ "$arg1" == '--perplexity' || "$arg1" == '-p' ]]; then
21 exec ./llama-perplexity "$@"
22elif [[ "$arg1" == '--all-in-one' || "$arg1" == '-a' ]]; then
23 echo "Converting PTH to GGML..."
24 for i in $(ls $1/$2/ggml-model-f16.bin*); do
25 if [ -f "${i/f16/q4_0}" ]; then
26 echo "Skip model quantization, it already exists: ${i/f16/q4_0}"
27 else
28 echo "Converting PTH to GGML: $i into ${i/f16/q4_0}..."
29 exec ./llama-quantize "$i" "${i/f16/q4_0}" q4_0
30 fi
31 done
32elif [[ "$arg1" == '--server' || "$arg1" == '-s' ]]; then
33 exec ./llama-server "$@"
34else
35 echo "Unknown command: $arg1"
36 echo "Available commands: "
37 echo " --run (-r): Run a model (chat) previously converted into ggml"
38 echo " ex: -m /models/7B/ggml-model-q4_0.bin"
39 echo " --run-legacy (-l): Run a model (legacy completion) previously converted into ggml"
40 echo " ex: -m /models/7B/ggml-model-q4_0.bin -no-cnv -p \"Building a website can be done in 10 simple steps:\" -n 512"
41 echo " --bench (-b): Benchmark the performance of the inference for various parameters."
42 echo " ex: -m model.gguf"
43 echo " --perplexity (-p): Measure the perplexity of a model over a given text."
44 echo " ex: -m model.gguf -f file.txt"
45 echo " --convert (-c): Convert a llama model into ggml"
46 echo " ex: --outtype f16 \"/models/7B/\" "
47 echo " --quantize (-q): Optimize with quantization process ggml"
48 echo " ex: \"/models/7B/ggml-model-f16.bin\" \"/models/7B/ggml-model-q4_0.bin\" 2"
49 echo " --all-in-one (-a): Execute --convert & --quantize"
50 echo " ex: \"/models/\" 7B"
51 echo " --server (-s): Run a model on the server"
52 echo " ex: -m /models/7B/ggml-model-q4_0.bin -c 2048 -ngl 43 -mg 1 --port 8080"
53fi