/ .devops / tools.sh
tools.sh
 1  #!/bin/bash
 2  set -e
 3  
 4  # Read the first argument into a variable
 5  arg1="$1"
 6  
 7  # Shift the arguments to remove the first one
 8  shift
 9  
10  if [[ "$arg1" == '--convert' || "$arg1" == '-c' ]]; then
11      python3 ./convert_hf_to_gguf.py "$@"
12  elif [[ "$arg1" == '--quantize' || "$arg1" == '-q' ]]; then
13      ./llama-quantize "$@"
14  elif [[ "$arg1" == '--run' || "$arg1" == '-r' ]]; then
15      ./llama-cli "$@"
16  elif [[ "$arg1" == '--all-in-one' || "$arg1" == '-a' ]]; then
17      echo "Converting PTH to GGML..."
18      for i in `ls $1/$2/ggml-model-f16.bin*`; do
19          if [ -f "${i/f16/q4_0}" ]; then
20              echo "Skip model quantization, it already exists: ${i/f16/q4_0}"
21          else
22              echo "Converting PTH to GGML: $i into ${i/f16/q4_0}..."
23              ./llama-quantize "$i" "${i/f16/q4_0}" q4_0
24          fi
25      done
26  elif [[ "$arg1" == '--server' || "$arg1" == '-s' ]]; then
27      ./llama-server "$@"
28  else
29      echo "Unknown command: $arg1"
30      echo "Available commands: "
31      echo "  --run (-r): Run a model previously converted into ggml"
32      echo "              ex: -m /models/7B/ggml-model-q4_0.bin -p \"Building a website can be done in 10 simple steps:\" -n 512"
33      echo "  --convert (-c): Convert a llama model into ggml"
34      echo "              ex: --outtype f16 \"/models/7B/\" "
35      echo "  --quantize (-q): Optimize with quantization process ggml"
36      echo "              ex: \"/models/7B/ggml-model-f16.bin\" \"/models/7B/ggml-model-q4_0.bin\" 2"
37      echo "  --all-in-one (-a): Execute --convert & --quantize"
38      echo "              ex: \"/models/\" 7B"
39      echo "  --server (-s): Run a model on the server"
40      echo "              ex: -m /models/7B/ggml-model-q4_0.bin -c 2048 -ngl 43 -mg 1 --port 8080"
41  fi