download-ggml-model.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/bash
  2. # This script downloads GPT-2 model files that have already been converted to ggml format.
  3. # This way you don't have to convert them yourself.
  4. #
  5. # If you want to download the original GPT-2 model files, use the "download-model.sh" script instead.
  6. #src="https://ggml.ggerganov.com"
  7. #pfx="ggml-model-gpt-2"
  8. src="https://huggingface.co/ggerganov/ggml"
  9. pfx="resolve/main/ggml-model-gpt-2"
  10. ggml_path=$(dirname $(realpath $0))
  11. # GPT-2 models
  12. models=( "117M" "345M" "774M" "1558M" )
  13. # list available models
  14. function list_models {
  15. printf "\n"
  16. printf " Available models:"
  17. for model in "${models[@]}"; do
  18. printf " $model"
  19. done
  20. printf "\n\n"
  21. }
  22. if [ "$#" -ne 1 ]; then
  23. printf "Usage: $0 <model>\n"
  24. list_models
  25. exit 1
  26. fi
  27. model=$1
  28. if [[ ! " ${models[@]} " =~ " ${model} " ]]; then
  29. printf "Invalid model: $model\n"
  30. list_models
  31. exit 1
  32. fi
  33. # download ggml model
  34. printf "Downloading ggml model $model ...\n"
  35. mkdir -p models/gpt-2-$model
  36. if [ -x "$(command -v wget)" ]; then
  37. wget --quiet --show-progress -O models/gpt-2-$model/ggml-model.bin $src/$pfx-$model.bin
  38. elif [ -x "$(command -v curl)" ]; then
  39. curl -L --output models/gpt-2-$model/ggml-model.bin $src/$pfx-$model.bin
  40. else
  41. printf "Either wget or curl is required to download models.\n"
  42. exit 1
  43. fi
  44. if [ $? -ne 0 ]; then
  45. printf "Failed to download ggml model $model \n"
  46. printf "Please try again later or download the original GPT-2 model files and convert them yourself.\n"
  47. exit 1
  48. fi
  49. printf "Done! Model '$model' saved in 'models/gpt-2-$model/ggml-model.bin'\n"
  50. printf "You can now use it like this:\n\n"
  51. printf " $ ./bin/gpt-2 -m models/gpt-2-$model/ggml-model.bin -p \"This is an example\"\n"
  52. printf "\n"