run.sh 29 KB

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