run.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #/bin/bash
  2. if [ -z "$2" ]; then
  3. echo "usage: $0 <output-dir> <mnt-dir>"
  4. exit 1
  5. fi
  6. mkdir -p "$1"
  7. mkdir -p "$2"
  8. OUT=$(realpath "$1")
  9. MNT=$(realpath "$2")
  10. rm -v $OUT/*.log
  11. rm -v $OUT/*.exit
  12. rm -v $OUT/*.md
  13. sd=`dirname $0`
  14. cd $sd/../
  15. SRC=`pwd`
  16. ## helpers
  17. # download a file if it does not exist or if it is outdated
  18. function gg_wget {
  19. local out=$1
  20. local url=$2
  21. local cwd=`pwd`
  22. mkdir -p $out
  23. cd $out
  24. # should not re-download if file is the same
  25. wget -nv -N $url
  26. cd $cwd
  27. }
  28. function gg_printf {
  29. printf -- "$@" >> $OUT/README.md
  30. }
  31. function gg_run {
  32. ci=$1
  33. set -o pipefail
  34. set -x
  35. gg_run_$ci | tee $OUT/$ci.log
  36. cur=$?
  37. echo "$cur" > $OUT/$ci.exit
  38. set +x
  39. set +o pipefail
  40. gg_sum_$ci
  41. ret=$((ret | cur))
  42. }
  43. ## ci
  44. # ctest_debug
  45. function gg_run_ctest_debug {
  46. cd ${SRC}
  47. rm -rf build-ci-debug && mkdir build-ci-debug && cd build-ci-debug
  48. set -e
  49. (time cmake -DCMAKE_BUILD_TYPE=Debug .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  50. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  51. (time ctest --output-on-failure -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  52. set +e
  53. }
  54. function gg_sum_ctest_debug {
  55. gg_printf '### %s\n\n' "${ci}"
  56. gg_printf 'Runs ctest in debug mode\n'
  57. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  58. gg_printf '```\n'
  59. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  60. gg_printf '```\n'
  61. gg_printf '\n'
  62. }
  63. # ctest_release
  64. function gg_run_ctest_release {
  65. cd ${SRC}
  66. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  67. set -e
  68. (time cmake -DCMAKE_BUILD_TYPE=Release .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  69. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  70. if [ -z $GG_BUILD_LOW_PERF ]; then
  71. (time ctest --output-on-failure ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  72. else
  73. (time ctest --output-on-failure -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  74. fi
  75. set +e
  76. }
  77. function gg_sum_ctest_release {
  78. gg_printf '### %s\n\n' "${ci}"
  79. gg_printf 'Runs ctest in release mode\n'
  80. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  81. gg_printf '```\n'
  82. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  83. gg_printf '```\n'
  84. }
  85. # open_llama_3b_v2
  86. function gg_run_open_llama_3b_v2 {
  87. cd ${SRC}
  88. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/raw/main/config.json
  89. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/resolve/main/tokenizer.model
  90. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/raw/main/tokenizer_config.json
  91. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/raw/main/special_tokens_map.json
  92. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/resolve/main/pytorch_model.bin
  93. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/raw/main/generation_config.json
  94. gg_wget models-mnt/wikitext/ https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-raw-v1.zip
  95. unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
  96. head -n 60 models-mnt/wikitext/wikitext-2-raw/wiki.test.raw > models-mnt/wikitext/wikitext-2-raw/wiki.test-60.raw
  97. path_models="../models-mnt/open-llama/3B-v2"
  98. path_wiki="../models-mnt/wikitext/wikitext-2-raw"
  99. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  100. set -e
  101. (time cmake -DCMAKE_BUILD_TYPE=Release -DLLAMA_QKK_64=1 .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  102. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  103. python3 ../convert.py ${path_models}
  104. model_f16="${path_models}/ggml-model-f16.bin"
  105. model_q8_0="${path_models}/ggml-model-q8_0.bin"
  106. model_q4_0="${path_models}/ggml-model-q4_0.bin"
  107. model_q4_1="${path_models}/ggml-model-q4_1.bin"
  108. model_q5_0="${path_models}/ggml-model-q5_0.bin"
  109. model_q5_1="${path_models}/ggml-model-q5_1.bin"
  110. model_q3_k="${path_models}/ggml-model-q3_k.bin"
  111. model_q4_k="${path_models}/ggml-model-q4_k.bin"
  112. model_q5_k="${path_models}/ggml-model-q5_k.bin"
  113. model_q6_k="${path_models}/ggml-model-q6_k.bin"
  114. wiki_test_60="${path_wiki}/wiki.test-60.raw"
  115. ./bin/quantize ${model_f16} ${model_q8_0} q8_0
  116. ./bin/quantize ${model_f16} ${model_q4_0} q4_0
  117. ./bin/quantize ${model_f16} ${model_q4_1} q4_1
  118. ./bin/quantize ${model_f16} ${model_q5_0} q5_0
  119. ./bin/quantize ${model_f16} ${model_q5_1} q5_1
  120. ./bin/quantize ${model_f16} ${model_q3_k} q3_k
  121. ./bin/quantize ${model_f16} ${model_q4_k} q4_k
  122. ./bin/quantize ${model_f16} ${model_q5_k} q5_k
  123. ./bin/quantize ${model_f16} ${model_q6_k} q6_k
  124. (time ./bin/main --model ${model_f16} -s 1234 -n 64 -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  125. (time ./bin/main --model ${model_q8_0} -s 1234 -n 64 -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  126. (time ./bin/main --model ${model_q4_0} -s 1234 -n 64 -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  127. (time ./bin/main --model ${model_q4_1} -s 1234 -n 64 -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  128. (time ./bin/main --model ${model_q5_0} -s 1234 -n 64 -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  129. (time ./bin/main --model ${model_q5_1} -s 1234 -n 64 -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  130. (time ./bin/main --model ${model_q3_k} -s 1234 -n 64 -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  131. (time ./bin/main --model ${model_q4_k} -s 1234 -n 64 -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  132. (time ./bin/main --model ${model_q5_k} -s 1234 -n 64 -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  133. (time ./bin/main --model ${model_q6_k} -s 1234 -n 64 -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  134. (time ./bin/perplexity --model ${model_f16} -f ${wiki_test_60} -c 128 -b 128 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  135. (time ./bin/perplexity --model ${model_q8_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  136. (time ./bin/perplexity --model ${model_q4_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  137. (time ./bin/perplexity --model ${model_q4_1} -f ${wiki_test_60} -c 128 -b 128 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  138. (time ./bin/perplexity --model ${model_q5_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  139. (time ./bin/perplexity --model ${model_q5_1} -f ${wiki_test_60} -c 128 -b 128 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  140. (time ./bin/perplexity --model ${model_q3_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  141. (time ./bin/perplexity --model ${model_q4_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  142. (time ./bin/perplexity --model ${model_q5_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  143. (time ./bin/perplexity --model ${model_q6_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  144. function check_ppl {
  145. qnt="$1"
  146. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  147. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  148. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  149. return 20
  150. fi
  151. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  152. return 0
  153. }
  154. check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  155. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  156. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  157. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  158. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  159. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  160. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  161. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  162. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  163. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  164. set +e
  165. }
  166. function gg_sum_open_llama_3b_v2 {
  167. gg_printf '### %s\n\n' "${ci}"
  168. gg_printf 'OpenLLaMA 3B-v2:\n'
  169. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  170. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  171. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  172. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  173. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  174. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  175. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  176. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  177. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  178. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  179. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  180. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  181. }
  182. ## main
  183. if [ -z $GG_BUILD_LOW_PERF ]; then
  184. rm -rf ${SRC}/models-mnt
  185. mnt_models=$(realpath ${MNT}/models)
  186. mkdir -p ${mnt_models}
  187. ln -sfn ${mnt_models} ${SRC}/models-mnt
  188. python3 -m pip install -r ${SRC}/requirements.txt
  189. fi
  190. ret=0
  191. #test $ret -eq 0 && gg_run ctest_debug
  192. #test $ret -eq 0 && gg_run ctest_release
  193. if [ -z $GG_BUILD_LOW_PERF ]; then
  194. test $ret -eq 0 && gg_run open_llama_3b_v2
  195. fi
  196. exit $ret