1
0

tools.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env 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. if [[ "$arg1" == '--convert' || "$arg1" == '-c' ]]; then
  8. exec python3 ./convert_hf_to_gguf.py "$@"
  9. elif [[ "$arg1" == '--quantize' || "$arg1" == '-q' ]]; then
  10. exec ./llama-quantize "$@"
  11. elif [[ "$arg1" == '--run' || "$arg1" == '-r' ]]; then
  12. exec ./llama-cli "$@"
  13. elif [[ "$arg1" == '--run-legacy' || "$arg1" == '-l' ]]; then
  14. exec ./llama-completion "$@"
  15. elif [[ "$arg1" == '--bench' || "$arg1" == '-b' ]]; then
  16. exec ./llama-bench "$@"
  17. elif [[ "$arg1" == '--perplexity' || "$arg1" == '-p' ]]; then
  18. exec ./llama-perplexity "$@"
  19. elif [[ "$arg1" == '--all-in-one' || "$arg1" == '-a' ]]; then
  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. exec ./llama-quantize "$i" "${i/f16/q4_0}" q4_0
  27. fi
  28. done
  29. elif [[ "$arg1" == '--server' || "$arg1" == '-s' ]]; then
  30. exec ./llama-server "$@"
  31. else
  32. echo "Unknown command: $arg1"
  33. echo "Available commands: "
  34. echo " --run (-r): Run a model (chat) previously converted into ggml"
  35. echo " ex: -m /models/7B/ggml-model-q4_0.bin"
  36. echo " --run-legacy (-l): Run a model (legacy completion) previously converted into ggml"
  37. 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"
  38. echo " --bench (-b): Benchmark the performance of the inference for various parameters."
  39. echo " ex: -m model.gguf"
  40. echo " --perplexity (-p): Measure the perplexity of a model over a given text."
  41. echo " ex: -m model.gguf -f file.txt"
  42. echo " --convert (-c): Convert a llama model into ggml"
  43. echo " ex: --outtype f16 \"/models/7B/\" "
  44. echo " --quantize (-q): Optimize with quantization process ggml"
  45. echo " ex: \"/models/7B/ggml-model-f16.bin\" \"/models/7B/ggml-model-q4_0.bin\" 2"
  46. echo " --all-in-one (-a): Execute --convert & --quantize"
  47. echo " ex: \"/models/\" 7B"
  48. echo " --server (-s): Run a model on the server"
  49. echo " ex: -m /models/7B/ggml-model-q4_0.bin -c 2048 -ngl 43 -mg 1 --port 8080"
  50. fi