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" == '--finetune' || "$arg1" == '-f' ]]; then 17 ./llama-finetune "$@" 18 elif [[ "$arg1" == '--all-in-one' || "$arg1" == '-a' ]]; then 19 echo "Converting PTH to GGML..." 20 for i in `ls $1/$2/ggml-model-f16.bin*`; do 21 if [ -f "${i/f16/q4_0}" ]; then 22 echo "Skip model quantization, it already exists: ${i/f16/q4_0}" 23 else 24 echo "Converting PTH to GGML: $i into ${i/f16/q4_0}..." 25 ./llama-quantize "$i" "${i/f16/q4_0}" q4_0 26 fi 27 done 28 elif [[ "$arg1" == '--server' || "$arg1" == '-s' ]]; then 29 ./llama-server "$@" 30 else 31 echo "Unknown command: $arg1" 32 echo "Available commands: " 33 echo " --run (-r): Run a model previously converted into ggml" 34 echo " ex: -m /models/7B/ggml-model-q4_0.bin -p \"Building a website can be done in 10 simple steps:\" -n 512" 35 echo " --convert (-c): Convert a llama model into ggml" 36 echo " ex: --outtype f16 \"/models/7B/\" " 37 echo " --quantize (-q): Optimize with quantization process ggml" 38 echo " ex: \"/models/7B/ggml-model-f16.bin\" \"/models/7B/ggml-model-q4_0.bin\" 2" 39 echo " --finetune (-f): Run finetune command to create a lora finetune of the model" 40 echo " See documentation for finetune for command-line parameters" 41 echo " --all-in-one (-a): Execute --convert & --quantize" 42 echo " ex: \"/models/\" 7B" 43 echo " --server (-s): Run a model on the server" 44 echo " ex: -m /models/7B/ggml-model-q4_0.bin -c 2048 -ngl 43 -mg 1 --port 8080" 45 fi