run.sh 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. #/bin/bash
  2. #
  3. # sample usage:
  4. #
  5. # mkdir tmp
  6. #
  7. # # CPU-only build
  8. # bash ./ci/run.sh ./tmp/results ./tmp/mnt
  9. #
  10. # # with CUDA support
  11. # GG_BUILD_CUDA=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt
  12. #
  13. if [ -z "$2" ]; then
  14. echo "usage: $0 <output-dir> <mnt-dir>"
  15. exit 1
  16. fi
  17. mkdir -p "$1"
  18. mkdir -p "$2"
  19. OUT=$(realpath "$1")
  20. MNT=$(realpath "$2")
  21. rm -v $OUT/*.log
  22. rm -v $OUT/*.exit
  23. rm -v $OUT/*.md
  24. sd=`dirname $0`
  25. cd $sd/../
  26. SRC=`pwd`
  27. ## helpers
  28. # download a file if it does not exist or if it is outdated
  29. function gg_wget {
  30. local out=$1
  31. local url=$2
  32. local cwd=`pwd`
  33. mkdir -p $out
  34. cd $out
  35. # should not re-download if file is the same
  36. wget -nv -N $url
  37. cd $cwd
  38. }
  39. function gg_printf {
  40. printf -- "$@" >> $OUT/README.md
  41. }
  42. function gg_run {
  43. ci=$1
  44. set -o pipefail
  45. set -x
  46. gg_run_$ci | tee $OUT/$ci.log
  47. cur=$?
  48. echo "$cur" > $OUT/$ci.exit
  49. set +x
  50. set +o pipefail
  51. gg_sum_$ci
  52. ret=$((ret | cur))
  53. }
  54. ## ci
  55. # ctest_debug
  56. function gg_run_ctest_debug {
  57. cd ${SRC}
  58. rm -rf build-ci-debug && mkdir build-ci-debug && cd build-ci-debug
  59. set -e
  60. (time cmake -DCMAKE_BUILD_TYPE=Debug .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  61. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  62. (time ctest --output-on-failure -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  63. set +e
  64. }
  65. function gg_sum_ctest_debug {
  66. gg_printf '### %s\n\n' "${ci}"
  67. gg_printf 'Runs ctest in debug mode\n'
  68. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  69. gg_printf '```\n'
  70. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  71. gg_printf '```\n'
  72. gg_printf '\n'
  73. }
  74. # ctest_release
  75. function gg_run_ctest_release {
  76. cd ${SRC}
  77. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  78. set -e
  79. (time cmake -DCMAKE_BUILD_TYPE=Release .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  80. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  81. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  82. (time ctest --output-on-failure ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  83. else
  84. (time ctest --output-on-failure -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  85. fi
  86. set +e
  87. }
  88. function gg_sum_ctest_release {
  89. gg_printf '### %s\n\n' "${ci}"
  90. gg_printf 'Runs ctest in release mode\n'
  91. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  92. gg_printf '```\n'
  93. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  94. gg_printf '```\n'
  95. }
  96. # open_llama_3b_v2
  97. function gg_run_open_llama_3b_v2 {
  98. cd ${SRC}
  99. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/raw/main/config.json
  100. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/resolve/main/tokenizer.model
  101. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/raw/main/tokenizer_config.json
  102. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/raw/main/special_tokens_map.json
  103. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/resolve/main/pytorch_model.bin
  104. gg_wget models-mnt/open-llama/3B-v2/ https://huggingface.co/openlm-research/open_llama_3b_v2/raw/main/generation_config.json
  105. gg_wget models-mnt/wikitext/ https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-raw-v1.zip
  106. unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
  107. head -n 60 models-mnt/wikitext/wikitext-2-raw/wiki.test.raw > models-mnt/wikitext/wikitext-2-raw/wiki.test-60.raw
  108. path_models="../models-mnt/open-llama/3B-v2"
  109. path_wiki="../models-mnt/wikitext/wikitext-2-raw"
  110. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  111. set -e
  112. (time cmake -DCMAKE_BUILD_TYPE=Release -DLLAMA_QKK_64=1 .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  113. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  114. python3 ../convert.py ${path_models}
  115. model_f16="${path_models}/ggml-model-f16.gguf"
  116. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  117. model_q4_0="${path_models}/ggml-model-q4_0.gguf"
  118. model_q4_1="${path_models}/ggml-model-q4_1.gguf"
  119. model_q5_0="${path_models}/ggml-model-q5_0.gguf"
  120. model_q5_1="${path_models}/ggml-model-q5_1.gguf"
  121. model_q2_k="${path_models}/ggml-model-q2_k.gguf"
  122. model_q3_k="${path_models}/ggml-model-q3_k.gguf"
  123. model_q4_k="${path_models}/ggml-model-q4_k.gguf"
  124. model_q5_k="${path_models}/ggml-model-q5_k.gguf"
  125. model_q6_k="${path_models}/ggml-model-q6_k.gguf"
  126. wiki_test_60="${path_wiki}/wiki.test-60.raw"
  127. ./bin/quantize ${model_f16} ${model_q8_0} q8_0
  128. ./bin/quantize ${model_f16} ${model_q4_0} q4_0
  129. ./bin/quantize ${model_f16} ${model_q4_1} q4_1
  130. ./bin/quantize ${model_f16} ${model_q5_0} q5_0
  131. ./bin/quantize ${model_f16} ${model_q5_1} q5_1
  132. ./bin/quantize ${model_f16} ${model_q2_k} q2_k
  133. ./bin/quantize ${model_f16} ${model_q3_k} q3_k
  134. ./bin/quantize ${model_f16} ${model_q4_k} q4_k
  135. ./bin/quantize ${model_f16} ${model_q5_k} q5_k
  136. ./bin/quantize ${model_f16} ${model_q6_k} q6_k
  137. (time ./bin/main --model ${model_f16} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  138. (time ./bin/main --model ${model_q8_0} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  139. (time ./bin/main --model ${model_q4_0} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  140. (time ./bin/main --model ${model_q4_1} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  141. (time ./bin/main --model ${model_q5_0} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  142. (time ./bin/main --model ${model_q5_1} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  143. (time ./bin/main --model ${model_q2_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  144. (time ./bin/main --model ${model_q3_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  145. (time ./bin/main --model ${model_q4_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  146. (time ./bin/main --model ${model_q5_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  147. (time ./bin/main --model ${model_q6_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  148. (time ./bin/perplexity --model ${model_f16} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  149. (time ./bin/perplexity --model ${model_q8_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  150. (time ./bin/perplexity --model ${model_q4_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  151. (time ./bin/perplexity --model ${model_q4_1} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  152. (time ./bin/perplexity --model ${model_q5_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  153. (time ./bin/perplexity --model ${model_q5_1} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  154. (time ./bin/perplexity --model ${model_q2_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  155. (time ./bin/perplexity --model ${model_q3_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  156. (time ./bin/perplexity --model ${model_q4_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  157. (time ./bin/perplexity --model ${model_q5_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  158. (time ./bin/perplexity --model ${model_q6_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  159. function check_ppl {
  160. qnt="$1"
  161. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  162. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  163. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  164. return 20
  165. fi
  166. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  167. return 0
  168. }
  169. check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  170. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  171. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  172. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  173. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  174. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  175. check_ppl "q2_k" "$(cat $OUT/${ci}-tg-q2_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  176. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  177. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  178. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  179. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  180. # lora
  181. function compare_ppl {
  182. qnt="$1"
  183. ppl1=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  184. ppl2=$(echo "$3" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  185. if [ $(echo "$ppl1 < $ppl2" | bc) -eq 1 ]; then
  186. printf ' - %s @ %s (FAIL: %s > %s)\n' "$qnt" "$ppl" "$ppl1" "$ppl2"
  187. return 20
  188. fi
  189. printf ' - %s @ %s %s OK\n' "$qnt" "$ppl1" "$ppl2"
  190. return 0
  191. }
  192. path_lora="../models-mnt/open-llama/3B-v2/lora"
  193. path_shakespeare="../models-mnt/shakespeare"
  194. shakespeare="${path_shakespeare}/shakespeare.txt"
  195. lora_shakespeare="${path_lora}/ggml-adapter-model.bin"
  196. gg_wget ${path_lora} https://huggingface.co/slaren/open_llama_3b_v2_shakespeare_lora/resolve/main/adapter_config.json
  197. gg_wget ${path_lora} https://huggingface.co/slaren/open_llama_3b_v2_shakespeare_lora/resolve/main/adapter_model.bin
  198. gg_wget ${path_shakespeare} https://huggingface.co/slaren/open_llama_3b_v2_shakespeare_lora/resolve/main/shakespeare.txt
  199. python3 ../convert-lora-to-ggml.py ${path_lora}
  200. # f16
  201. (time ./bin/perplexity --model ${model_f16} -f ${shakespeare} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-ppl-shakespeare-f16.log
  202. (time ./bin/perplexity --model ${model_f16} -f ${shakespeare} --lora ${lora_shakespeare} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-ppl-shakespeare-lora-f16.log
  203. compare_ppl "f16 shakespeare" "$(cat $OUT/${ci}-ppl-shakespeare-f16.log | grep "^\[1\]")" "$(cat $OUT/${ci}-ppl-shakespeare-lora-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-lora-ppl.log
  204. # q8_0
  205. (time ./bin/perplexity --model ${model_q8_0} -f ${shakespeare} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-ppl-shakespeare-q8_0.log
  206. (time ./bin/perplexity --model ${model_q8_0} -f ${shakespeare} --lora ${lora_shakespeare} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-ppl-shakespeare-lora-q8_0.log
  207. compare_ppl "q8_0 shakespeare" "$(cat $OUT/${ci}-ppl-shakespeare-q8_0.log | grep "^\[1\]")" "$(cat $OUT/${ci}-ppl-shakespeare-lora-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-lora-ppl.log
  208. # q8_0 + f16 lora-base
  209. (time ./bin/perplexity --model ${model_q8_0} -f ${shakespeare} --lora ${lora_shakespeare} --lora-base ${model_f16} -c 128 -b 128 --chunks 2 ) 2>&1 | tee -a $OUT/${ci}-ppl-shakespeare-lora-q8_0-f16.log
  210. compare_ppl "q8_0 / f16 base shakespeare" "$(cat $OUT/${ci}-ppl-shakespeare-q8_0.log | grep "^\[1\]")" "$(cat $OUT/${ci}-ppl-shakespeare-lora-q8_0-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-lora-ppl.log
  211. set +e
  212. }
  213. function gg_sum_open_llama_3b_v2 {
  214. gg_printf '### %s\n\n' "${ci}"
  215. gg_printf 'OpenLLaMA 3B-v2:\n'
  216. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  217. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  218. gg_printf '- lora:\n%s\n' "$(cat $OUT/${ci}-lora-ppl.log)"
  219. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  220. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  221. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  222. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  223. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  224. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  225. gg_printf '- q2_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q2_k.log)"
  226. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  227. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  228. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  229. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  230. gg_printf '- shakespeare (f16):\n```\n%s\n```\n' "$(cat $OUT/${ci}-ppl-shakespeare-f16.log)"
  231. gg_printf '- shakespeare (f16 lora):\n```\n%s\n```\n' "$(cat $OUT/${ci}-ppl-shakespeare-lora-f16.log)"
  232. gg_printf '- shakespeare (q8_0):\n```\n%s\n```\n' "$(cat $OUT/${ci}-ppl-shakespeare-q8_0.log)"
  233. gg_printf '- shakespeare (q8_0 lora):\n```\n%s\n```\n' "$(cat $OUT/${ci}-ppl-shakespeare-lora-q8_0.log)"
  234. gg_printf '- shakespeare (q8_0 / f16 base lora):\n```\n%s\n```\n' "$(cat $OUT/${ci}-ppl-shakespeare-lora-q8_0-f16.log)"
  235. }
  236. # open_llama_7b_v2
  237. # requires: GG_BUILD_CUDA
  238. function gg_run_open_llama_7b_v2 {
  239. cd ${SRC}
  240. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/config.json
  241. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/resolve/main/tokenizer.model
  242. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/tokenizer_config.json
  243. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/special_tokens_map.json
  244. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/pytorch_model.bin.index.json
  245. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/resolve/main/pytorch_model-00001-of-00002.bin
  246. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/resolve/main/pytorch_model-00002-of-00002.bin
  247. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/generation_config.json
  248. gg_wget models-mnt/wikitext/ https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-raw-v1.zip
  249. unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
  250. path_models="../models-mnt/open-llama/7B-v2"
  251. path_wiki="../models-mnt/wikitext/wikitext-2-raw"
  252. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  253. set -e
  254. (time cmake -DCMAKE_BUILD_TYPE=Release -DLLAMA_CUBLAS=1 .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  255. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  256. python3 ../convert.py ${path_models}
  257. model_f16="${path_models}/ggml-model-f16.gguf"
  258. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  259. model_q4_0="${path_models}/ggml-model-q4_0.gguf"
  260. model_q4_1="${path_models}/ggml-model-q4_1.gguf"
  261. model_q5_0="${path_models}/ggml-model-q5_0.gguf"
  262. model_q5_1="${path_models}/ggml-model-q5_1.gguf"
  263. model_q2_k="${path_models}/ggml-model-q2_k.gguf"
  264. model_q3_k="${path_models}/ggml-model-q3_k.gguf"
  265. model_q4_k="${path_models}/ggml-model-q4_k.gguf"
  266. model_q5_k="${path_models}/ggml-model-q5_k.gguf"
  267. model_q6_k="${path_models}/ggml-model-q6_k.gguf"
  268. wiki_test="${path_wiki}/wiki.test.raw"
  269. ./bin/quantize ${model_f16} ${model_q8_0} q8_0
  270. ./bin/quantize ${model_f16} ${model_q4_0} q4_0
  271. ./bin/quantize ${model_f16} ${model_q4_1} q4_1
  272. ./bin/quantize ${model_f16} ${model_q5_0} q5_0
  273. ./bin/quantize ${model_f16} ${model_q5_1} q5_1
  274. ./bin/quantize ${model_f16} ${model_q2_k} q2_k
  275. ./bin/quantize ${model_f16} ${model_q3_k} q3_k
  276. ./bin/quantize ${model_f16} ${model_q4_k} q4_k
  277. ./bin/quantize ${model_f16} ${model_q5_k} q5_k
  278. ./bin/quantize ${model_f16} ${model_q6_k} q6_k
  279. (time ./bin/main --model ${model_f16} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  280. (time ./bin/main --model ${model_q8_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  281. (time ./bin/main --model ${model_q4_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  282. (time ./bin/main --model ${model_q4_1} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  283. (time ./bin/main --model ${model_q5_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  284. (time ./bin/main --model ${model_q5_1} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  285. (time ./bin/main --model ${model_q2_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  286. (time ./bin/main --model ${model_q3_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  287. (time ./bin/main --model ${model_q4_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  288. (time ./bin/main --model ${model_q5_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  289. (time ./bin/main --model ${model_q6_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  290. (time ./bin/perplexity --model ${model_f16} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  291. (time ./bin/perplexity --model ${model_q8_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  292. (time ./bin/perplexity --model ${model_q4_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  293. (time ./bin/perplexity --model ${model_q4_1} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  294. (time ./bin/perplexity --model ${model_q5_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  295. (time ./bin/perplexity --model ${model_q5_1} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  296. (time ./bin/perplexity --model ${model_q2_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  297. (time ./bin/perplexity --model ${model_q3_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  298. (time ./bin/perplexity --model ${model_q4_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  299. (time ./bin/perplexity --model ${model_q5_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  300. (time ./bin/perplexity --model ${model_q6_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  301. function check_ppl {
  302. qnt="$1"
  303. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  304. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  305. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  306. return 20
  307. fi
  308. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  309. return 0
  310. }
  311. check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  312. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  313. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  314. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  315. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  316. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  317. check_ppl "q2_k" "$(cat $OUT/${ci}-tg-q2_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  318. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  319. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  320. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  321. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  322. # lora
  323. function compare_ppl {
  324. qnt="$1"
  325. ppl1=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  326. ppl2=$(echo "$3" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  327. if [ $(echo "$ppl1 < $ppl2" | bc) -eq 1 ]; then
  328. printf ' - %s @ %s (FAIL: %s > %s)\n' "$qnt" "$ppl" "$ppl1" "$ppl2"
  329. return 20
  330. fi
  331. printf ' - %s @ %s %s OK\n' "$qnt" "$ppl1" "$ppl2"
  332. return 0
  333. }
  334. path_lora="../models-mnt/open-llama/7B-v2/lora"
  335. path_shakespeare="../models-mnt/shakespeare"
  336. shakespeare="${path_shakespeare}/shakespeare.txt"
  337. lora_shakespeare="${path_lora}/ggml-adapter-model.bin"
  338. gg_wget ${path_lora} https://huggingface.co/slaren/open_llama_7b_v2_shakespeare_lora/resolve/main/adapter_config.json
  339. gg_wget ${path_lora} https://huggingface.co/slaren/open_llama_7b_v2_shakespeare_lora/resolve/main/adapter_model.bin
  340. gg_wget ${path_shakespeare} https://huggingface.co/slaren/open_llama_7b_v2_shakespeare_lora/resolve/main/shakespeare.txt
  341. python3 ../convert-lora-to-ggml.py ${path_lora}
  342. # f16
  343. (time ./bin/perplexity --model ${model_f16} -f ${shakespeare} -t 1 -ngl 999 -c 2048 -b 512 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-ppl-shakespeare-f16.log
  344. (time ./bin/perplexity --model ${model_f16} -f ${shakespeare} --lora ${lora_shakespeare} -t 1 -ngl 999 -c 2048 -b 512 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-ppl-shakespeare-lora-f16.log
  345. compare_ppl "f16 shakespeare" "$(cat $OUT/${ci}-ppl-shakespeare-f16.log | grep "^\[1\]")" "$(cat $OUT/${ci}-ppl-shakespeare-lora-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-lora-ppl.log
  346. # currently not supported by the CUDA backend
  347. # q8_0
  348. #(time ./bin/perplexity --model ${model_q8_0} -f ${shakespeare} -t 1 -ngl 999 -c 2048 -b 512 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-ppl-shakespeare-q8_0.log
  349. #(time ./bin/perplexity --model ${model_q8_0} -f ${shakespeare} --lora ${lora_shakespeare} -t 1 -ngl 999 -c 2048 -b 512 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-ppl-shakespeare-lora-q8_0.log
  350. #compare_ppl "q8_0 shakespeare" "$(cat $OUT/${ci}-ppl-shakespeare-q8_0.log | grep "^\[1\]")" "$(cat $OUT/${ci}-ppl-shakespeare-lora-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-lora-ppl.log
  351. # q8_0 + f16 lora-base
  352. #(time ./bin/perplexity --model ${model_q8_0} -f ${shakespeare} --lora ${lora_shakespeare} --lora-base ${model_f16} -t 1 -ngl 999 -c 2048 -b 512 --chunks 3 ) 2>&1 | tee -a $OUT/${ci}-ppl-shakespeare-lora-q8_0-f16.log
  353. #compare_ppl "q8_0 / f16 shakespeare" "$(cat $OUT/${ci}-ppl-shakespeare-q8_0.log | grep "^\[1\]")" "$(cat $OUT/${ci}-ppl-shakespeare-lora-q8_0-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-lora-ppl.log
  354. set +e
  355. }
  356. function gg_sum_open_llama_7b_v2 {
  357. gg_printf '### %s\n\n' "${ci}"
  358. gg_printf 'OpenLLaMA 7B-v2:\n'
  359. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  360. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  361. gg_printf '- lora:\n%s\n' "$(cat $OUT/${ci}-lora-ppl.log)"
  362. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  363. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  364. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  365. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  366. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  367. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  368. gg_printf '- q2_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q2_k.log)"
  369. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  370. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  371. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  372. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  373. gg_printf '- shakespeare (f16):\n```\n%s\n```\n' "$(cat $OUT/${ci}-ppl-shakespeare-f16.log)"
  374. gg_printf '- shakespeare (f16 lora):\n```\n%s\n```\n' "$(cat $OUT/${ci}-ppl-shakespeare-lora-f16.log)"
  375. #gg_printf '- shakespeare (q8_0):\n```\n%s\n```\n' "$(cat $OUT/${ci}-ppl-shakespeare-q8_0.log)"
  376. #gg_printf '- shakespeare (q8_0 lora):\n```\n%s\n```\n' "$(cat $OUT/${ci}-ppl-shakespeare-lora-q8_0.log)"
  377. #gg_printf '- shakespeare (q8_0 / f16 base lora):\n```\n%s\n```\n' "$(cat $OUT/${ci}-ppl-shakespeare-lora-q8_0-f16.log)"
  378. }
  379. ## main
  380. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  381. rm -rf ${SRC}/models-mnt
  382. mnt_models=${MNT}/models
  383. mkdir -p ${mnt_models}
  384. ln -sfn ${mnt_models} ${SRC}/models-mnt
  385. python3 -m pip install -r ${SRC}/requirements.txt
  386. python3 -m pip install --editable gguf-py
  387. fi
  388. ret=0
  389. test $ret -eq 0 && gg_run ctest_debug
  390. test $ret -eq 0 && gg_run ctest_release
  391. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  392. if [ -z ${GG_BUILD_CUDA} ]; then
  393. test $ret -eq 0 && gg_run open_llama_3b_v2
  394. else
  395. test $ret -eq 0 && gg_run open_llama_7b_v2
  396. fi
  397. fi
  398. exit $ret