tools.sh 1.8 KB

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