run.sh 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. # # with SYCL support
  14. # GG_BUILD_SYCL=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt
  15. #
  16. if [ -z "$2" ]; then
  17. echo "usage: $0 <output-dir> <mnt-dir>"
  18. exit 1
  19. fi
  20. mkdir -p "$1"
  21. mkdir -p "$2"
  22. OUT=$(realpath "$1")
  23. MNT=$(realpath "$2")
  24. rm -f "$OUT/*.log"
  25. rm -f "$OUT/*.exit"
  26. rm -f "$OUT/*.md"
  27. sd=`dirname $0`
  28. cd $sd/../
  29. SRC=`pwd`
  30. CMAKE_EXTRA="-DLLAMA_FATAL_WARNINGS=ON"
  31. if [ ! -z ${GG_BUILD_METAL} ]; then
  32. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_METAL=ON"
  33. fi
  34. if [ ! -z ${GG_BUILD_CUDA} ]; then
  35. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_CUDA=1"
  36. fi
  37. if [ ! -z ${GG_BUILD_SYCL} ]; then
  38. if [ -z ${ONEAPI_ROOT} ]; then
  39. echo "Not detected ONEAPI_ROOT, please install oneAPI base toolkit and enable it by:"
  40. echo "source /opt/intel/oneapi/setvars.sh"
  41. exit 1
  42. fi
  43. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_SYCL=1 DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON"
  44. fi
  45. ## helpers
  46. # download a file if it does not exist or if it is outdated
  47. function gg_wget {
  48. local out=$1
  49. local url=$2
  50. local cwd=`pwd`
  51. mkdir -p $out
  52. cd $out
  53. # should not re-download if file is the same
  54. wget -nv -N $url
  55. cd $cwd
  56. }
  57. function gg_printf {
  58. printf -- "$@" >> $OUT/README.md
  59. }
  60. function gg_run {
  61. ci=$1
  62. set -o pipefail
  63. set -x
  64. gg_run_$ci | tee $OUT/$ci.log
  65. cur=$?
  66. echo "$cur" > $OUT/$ci.exit
  67. set +x
  68. set +o pipefail
  69. gg_sum_$ci
  70. ret=$((ret | cur))
  71. }
  72. ## ci
  73. # ctest_debug
  74. function gg_run_ctest_debug {
  75. cd ${SRC}
  76. rm -rf build-ci-debug && mkdir build-ci-debug && cd build-ci-debug
  77. set -e
  78. # Check cmake, make and ctest are installed
  79. gg_check_build_requirements
  80. (time cmake -DCMAKE_BUILD_TYPE=Debug ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  81. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  82. (time ctest --output-on-failure -L main -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  83. set +e
  84. }
  85. function gg_sum_ctest_debug {
  86. gg_printf '### %s\n\n' "${ci}"
  87. gg_printf 'Runs ctest in debug mode\n'
  88. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  89. gg_printf '```\n'
  90. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  91. gg_printf '```\n'
  92. gg_printf '\n'
  93. }
  94. # ctest_release
  95. function gg_run_ctest_release {
  96. cd ${SRC}
  97. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  98. set -e
  99. # Check cmake, make and ctest are installed
  100. gg_check_build_requirements
  101. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  102. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  103. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  104. (time ctest --output-on-failure -L main ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  105. else
  106. (time ctest --output-on-failure -L main -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  107. fi
  108. set +e
  109. }
  110. function gg_sum_ctest_release {
  111. gg_printf '### %s\n\n' "${ci}"
  112. gg_printf 'Runs ctest in release mode\n'
  113. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  114. gg_printf '```\n'
  115. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  116. gg_printf '```\n'
  117. }
  118. # test_scripts_debug
  119. function gg_run_test_scripts_debug {
  120. cd ${SRC}
  121. set -e
  122. (cd ./examples/gguf-split && time bash tests.sh "$SRC/build-ci-debug/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  123. (cd ./examples/quantize && time bash tests.sh "$SRC/build-ci-debug/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  124. set +e
  125. }
  126. function gg_sum_test_scripts_debug {
  127. gg_printf '### %s\n\n' "${ci}"
  128. gg_printf 'Runs test scripts in debug mode\n'
  129. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  130. gg_printf '```\n'
  131. gg_printf '%s\n' "$(cat $OUT/${ci}-scripts.log)"
  132. gg_printf '```\n'
  133. gg_printf '\n'
  134. }
  135. # test_scripts_release
  136. function gg_run_test_scripts_release {
  137. cd ${SRC}
  138. set -e
  139. (cd ./examples/gguf-split && time bash tests.sh "$SRC/build-ci-release/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  140. (cd ./examples/quantize && time bash tests.sh "$SRC/build-ci-release/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  141. set +e
  142. }
  143. function gg_sum_test_scripts_release {
  144. gg_printf '### %s\n\n' "${ci}"
  145. gg_printf 'Runs test scripts in release mode\n'
  146. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  147. gg_printf '```\n'
  148. gg_printf '%s\n' "$(cat $OUT/${ci}-scripts.log)"
  149. gg_printf '```\n'
  150. gg_printf '\n'
  151. }
  152. function gg_get_model {
  153. local gguf_0="$MNT/models/pythia/1.4B/ggml-model-f16.gguf"
  154. local gguf_1="$MNT/models/pythia/2.8B/ggml-model-f16.gguf"
  155. local gguf_2="$MNT/models/open-llama/7B-v2/ggml-model-f16.gguf"
  156. if [[ -s $gguf_0 ]]; then
  157. echo -n "$gguf_0"
  158. elif [[ -s $gguf_1 ]]; then
  159. echo -n "$gguf_1"
  160. elif [[ -s $gguf_2 ]]; then
  161. echo -n "$gguf_2"
  162. else
  163. echo >&2 "No model found. Can't run gg_run_ctest_with_model."
  164. exit 1
  165. fi
  166. }
  167. function gg_run_ctest_with_model_debug {
  168. cd ${SRC}
  169. local model; model=$(gg_get_model)
  170. cd build-ci-debug
  171. set -e
  172. (LLAMACPP_TEST_MODELFILE="$model" time ctest --output-on-failure -L model) 2>&1 | tee -a $OUT/${ci}-ctest.log
  173. set +e
  174. cd ..
  175. }
  176. function gg_run_ctest_with_model_release {
  177. cd ${SRC}
  178. local model; model=$(gg_get_model)
  179. cd build-ci-release
  180. set -e
  181. (LLAMACPP_TEST_MODELFILE="$model" time ctest --output-on-failure -L model) 2>&1 | tee -a $OUT/${ci}-ctest.log
  182. set +e
  183. cd ..
  184. }
  185. function gg_sum_ctest_with_model_debug {
  186. gg_printf '### %s\n\n' "${ci}"
  187. gg_printf 'Runs ctest with model files in debug mode\n'
  188. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  189. gg_printf '```\n'
  190. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  191. gg_printf '```\n'
  192. }
  193. function gg_sum_ctest_with_model_release {
  194. gg_printf '### %s\n\n' "${ci}"
  195. gg_printf 'Runs ctest with model files in release mode\n'
  196. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  197. gg_printf '```\n'
  198. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  199. gg_printf '```\n'
  200. }
  201. # open_llama_7b_v2
  202. # requires: GG_BUILD_CUDA
  203. function gg_run_open_llama_7b_v2 {
  204. cd ${SRC}
  205. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/config.json
  206. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/resolve/main/tokenizer.model
  207. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/tokenizer_config.json
  208. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/special_tokens_map.json
  209. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/pytorch_model.bin.index.json
  210. 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
  211. 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
  212. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/generation_config.json
  213. gg_wget models-mnt/wikitext/ https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip
  214. unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
  215. path_models="../models-mnt/open-llama/7B-v2"
  216. path_wiki="../models-mnt/wikitext/wikitext-2-raw"
  217. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  218. set -e
  219. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} -DGGML_CUDA=1 .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  220. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  221. python3 ../examples/convert_legacy_llama.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  222. model_f16="${path_models}/ggml-model-f16.gguf"
  223. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  224. model_q4_0="${path_models}/ggml-model-q4_0.gguf"
  225. model_q4_1="${path_models}/ggml-model-q4_1.gguf"
  226. model_q5_0="${path_models}/ggml-model-q5_0.gguf"
  227. model_q5_1="${path_models}/ggml-model-q5_1.gguf"
  228. model_q2_k="${path_models}/ggml-model-q2_k.gguf"
  229. model_q3_k="${path_models}/ggml-model-q3_k.gguf"
  230. model_q4_k="${path_models}/ggml-model-q4_k.gguf"
  231. model_q5_k="${path_models}/ggml-model-q5_k.gguf"
  232. model_q6_k="${path_models}/ggml-model-q6_k.gguf"
  233. wiki_test="${path_wiki}/wiki.test.raw"
  234. ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0
  235. ./bin/llama-quantize ${model_f16} ${model_q4_0} q4_0
  236. ./bin/llama-quantize ${model_f16} ${model_q4_1} q4_1
  237. ./bin/llama-quantize ${model_f16} ${model_q5_0} q5_0
  238. ./bin/llama-quantize ${model_f16} ${model_q5_1} q5_1
  239. ./bin/llama-quantize ${model_f16} ${model_q2_k} q2_k
  240. ./bin/llama-quantize ${model_f16} ${model_q3_k} q3_k
  241. ./bin/llama-quantize ${model_f16} ${model_q4_k} q4_k
  242. ./bin/llama-quantize ${model_f16} ${model_q5_k} q5_k
  243. ./bin/llama-quantize ${model_f16} ${model_q6_k} q6_k
  244. (time ./bin/llama-cli --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
  245. (time ./bin/llama-cli --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
  246. (time ./bin/llama-cli --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
  247. (time ./bin/llama-cli --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
  248. (time ./bin/llama-cli --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
  249. (time ./bin/llama-cli --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
  250. (time ./bin/llama-cli --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
  251. (time ./bin/llama-cli --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
  252. (time ./bin/llama-cli --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
  253. (time ./bin/llama-cli --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
  254. (time ./bin/llama-cli --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
  255. (time ./bin/llama-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
  256. (time ./bin/llama-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
  257. (time ./bin/llama-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
  258. (time ./bin/llama-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
  259. (time ./bin/llama-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
  260. (time ./bin/llama-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
  261. (time ./bin/llama-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
  262. (time ./bin/llama-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
  263. (time ./bin/llama-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
  264. (time ./bin/llama-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
  265. (time ./bin/llama-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
  266. (time ./bin/llama-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
  267. (time ./bin/llama-save-load-state -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  268. (time ./bin/llama-save-load-state -fa -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  269. (time ./bin/llama-save-load-state -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  270. (time ./bin/llama-save-load-state -fa -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  271. function check_ppl {
  272. qnt="$1"
  273. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  274. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  275. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  276. return 20
  277. fi
  278. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  279. return 0
  280. }
  281. check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  282. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  283. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  284. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  285. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  286. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  287. check_ppl "q2_k" "$(cat $OUT/${ci}-tg-q2_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  288. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  289. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  290. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  291. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  292. cat $OUT/${ci}-imatrix.log | grep "Final" >> $OUT/${ci}-imatrix-sum.log
  293. set +e
  294. }
  295. function gg_sum_open_llama_7b_v2 {
  296. gg_printf '### %s\n\n' "${ci}"
  297. gg_printf 'OpenLLaMA 7B-v2:\n'
  298. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  299. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  300. gg_printf '- imatrix:\n```\n%s\n```\n' "$(cat $OUT/${ci}-imatrix-sum.log)"
  301. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  302. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  303. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  304. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  305. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  306. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  307. gg_printf '- q2_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q2_k.log)"
  308. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  309. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  310. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  311. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  312. gg_printf '- save-load-state: \n```\n%s\n```\n' "$(cat $OUT/${ci}-save-load-state.log)"
  313. }
  314. # pythia_1.4b
  315. function gg_run_pythia_1_4b {
  316. cd ${SRC}
  317. gg_wget models-mnt/pythia/1.4B/ https://huggingface.co/EleutherAI/pythia-1.4b/raw/main/config.json
  318. gg_wget models-mnt/pythia/1.4B/ https://huggingface.co/EleutherAI/pythia-1.4b/raw/main/tokenizer.json
  319. gg_wget models-mnt/pythia/1.4B/ https://huggingface.co/EleutherAI/pythia-1.4b/raw/main/tokenizer_config.json
  320. gg_wget models-mnt/pythia/1.4B/ https://huggingface.co/EleutherAI/pythia-1.4b/raw/main/special_tokens_map.json
  321. gg_wget models-mnt/pythia/1.4B/ https://huggingface.co/EleutherAI/pythia-1.4b/resolve/main/pytorch_model.bin
  322. gg_wget models-mnt/wikitext/ https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip
  323. unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
  324. head -n 60 models-mnt/wikitext/wikitext-2-raw/wiki.test.raw > models-mnt/wikitext/wikitext-2-raw/wiki.test-60.raw
  325. path_models="../models-mnt/pythia/1.4B"
  326. path_wiki="../models-mnt/wikitext/wikitext-2-raw"
  327. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  328. set -e
  329. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  330. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  331. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  332. model_f16="${path_models}/ggml-model-f16.gguf"
  333. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  334. model_q4_0="${path_models}/ggml-model-q4_0.gguf"
  335. model_q4_1="${path_models}/ggml-model-q4_1.gguf"
  336. model_q5_0="${path_models}/ggml-model-q5_0.gguf"
  337. model_q5_1="${path_models}/ggml-model-q5_1.gguf"
  338. model_q2_k="${path_models}/ggml-model-q2_k.gguf"
  339. model_q3_k="${path_models}/ggml-model-q3_k.gguf"
  340. model_q4_k="${path_models}/ggml-model-q4_k.gguf"
  341. model_q5_k="${path_models}/ggml-model-q5_k.gguf"
  342. model_q6_k="${path_models}/ggml-model-q6_k.gguf"
  343. wiki_test_60="${path_wiki}/wiki.test-60.raw"
  344. ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0
  345. ./bin/llama-quantize ${model_f16} ${model_q4_0} q4_0
  346. ./bin/llama-quantize ${model_f16} ${model_q4_1} q4_1
  347. ./bin/llama-quantize ${model_f16} ${model_q5_0} q5_0
  348. ./bin/llama-quantize ${model_f16} ${model_q5_1} q5_1
  349. ./bin/llama-quantize ${model_f16} ${model_q2_k} q2_k
  350. ./bin/llama-quantize ${model_f16} ${model_q3_k} q3_k
  351. ./bin/llama-quantize ${model_f16} ${model_q4_k} q4_k
  352. ./bin/llama-quantize ${model_f16} ${model_q5_k} q5_k
  353. ./bin/llama-quantize ${model_f16} ${model_q6_k} q6_k
  354. (time ./bin/llama-cli --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
  355. (time ./bin/llama-cli --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
  356. (time ./bin/llama-cli --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
  357. (time ./bin/llama-cli --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
  358. (time ./bin/llama-cli --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
  359. (time ./bin/llama-cli --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
  360. (time ./bin/llama-cli --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
  361. (time ./bin/llama-cli --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
  362. (time ./bin/llama-cli --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
  363. (time ./bin/llama-cli --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
  364. (time ./bin/llama-cli --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
  365. (time ./bin/llama-perplexity --model ${model_f16} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  366. (time ./bin/llama-perplexity --model ${model_q8_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  367. (time ./bin/llama-perplexity --model ${model_q4_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  368. (time ./bin/llama-perplexity --model ${model_q4_1} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  369. (time ./bin/llama-perplexity --model ${model_q5_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  370. (time ./bin/llama-perplexity --model ${model_q5_1} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  371. (time ./bin/llama-perplexity --model ${model_q2_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  372. (time ./bin/llama-perplexity --model ${model_q3_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  373. (time ./bin/llama-perplexity --model ${model_q4_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  374. (time ./bin/llama-perplexity --model ${model_q5_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  375. (time ./bin/llama-perplexity --model ${model_q6_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  376. (time ./bin/llama-imatrix --model ${model_f16} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log
  377. (time ./bin/llama-save-load-state --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  378. (time ./bin/llama-save-load-state -fa --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  379. function check_ppl {
  380. qnt="$1"
  381. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  382. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  383. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  384. return 20
  385. fi
  386. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  387. return 0
  388. }
  389. check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  390. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  391. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  392. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  393. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  394. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  395. #check_ppl "q2_k" "$(cat $OUT/${ci}-tg-q2_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log # note: ppl > 20.0 for this quant and model
  396. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  397. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  398. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  399. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  400. cat $OUT/${ci}-imatrix.log | grep "Final" >> $OUT/${ci}-imatrix-sum.log
  401. set +e
  402. }
  403. function gg_sum_pythia_1_4b {
  404. gg_printf '### %s\n\n' "${ci}"
  405. gg_printf 'Pythia 1.4B:\n'
  406. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  407. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  408. gg_printf '- imatrix:\n```\n%s\n```\n' "$(cat $OUT/${ci}-imatrix-sum.log)"
  409. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  410. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  411. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  412. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  413. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  414. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  415. gg_printf '- q2_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q2_k.log)"
  416. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  417. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  418. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  419. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  420. gg_printf '- save-load-state: \n```\n%s\n```\n' "$(cat $OUT/${ci}-save-load-state.log)"
  421. }
  422. # pythia_2_8b
  423. # requires: GG_BUILD_CUDA
  424. function gg_run_pythia_2_8b {
  425. cd ${SRC}
  426. gg_wget models-mnt/pythia/2.8B/ https://huggingface.co/EleutherAI/pythia-2.8b/raw/main/config.json
  427. gg_wget models-mnt/pythia/2.8B/ https://huggingface.co/EleutherAI/pythia-2.8b/raw/main/tokenizer.json
  428. gg_wget models-mnt/pythia/2.8B/ https://huggingface.co/EleutherAI/pythia-2.8b/raw/main/tokenizer_config.json
  429. gg_wget models-mnt/pythia/2.8B/ https://huggingface.co/EleutherAI/pythia-2.8b/raw/main/special_tokens_map.json
  430. gg_wget models-mnt/pythia/2.8B/ https://huggingface.co/EleutherAI/pythia-2.8b/resolve/main/pytorch_model.bin
  431. gg_wget models-mnt/wikitext/ https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip
  432. unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
  433. path_models="../models-mnt/pythia/2.8B"
  434. path_wiki="../models-mnt/wikitext/wikitext-2-raw"
  435. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  436. set -e
  437. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} -DGGML_CUDA=1 .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  438. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  439. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  440. model_f16="${path_models}/ggml-model-f16.gguf"
  441. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  442. model_q4_0="${path_models}/ggml-model-q4_0.gguf"
  443. model_q4_1="${path_models}/ggml-model-q4_1.gguf"
  444. model_q5_0="${path_models}/ggml-model-q5_0.gguf"
  445. model_q5_1="${path_models}/ggml-model-q5_1.gguf"
  446. model_q2_k="${path_models}/ggml-model-q2_k.gguf"
  447. model_q3_k="${path_models}/ggml-model-q3_k.gguf"
  448. model_q4_k="${path_models}/ggml-model-q4_k.gguf"
  449. model_q5_k="${path_models}/ggml-model-q5_k.gguf"
  450. model_q6_k="${path_models}/ggml-model-q6_k.gguf"
  451. wiki_test="${path_wiki}/wiki.test.raw"
  452. ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0
  453. ./bin/llama-quantize ${model_f16} ${model_q4_0} q4_0
  454. ./bin/llama-quantize ${model_f16} ${model_q4_1} q4_1
  455. ./bin/llama-quantize ${model_f16} ${model_q5_0} q5_0
  456. ./bin/llama-quantize ${model_f16} ${model_q5_1} q5_1
  457. ./bin/llama-quantize ${model_f16} ${model_q2_k} q2_k
  458. ./bin/llama-quantize ${model_f16} ${model_q3_k} q3_k
  459. ./bin/llama-quantize ${model_f16} ${model_q4_k} q4_k
  460. ./bin/llama-quantize ${model_f16} ${model_q5_k} q5_k
  461. ./bin/llama-quantize ${model_f16} ${model_q6_k} q6_k
  462. (time ./bin/llama-cli --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
  463. (time ./bin/llama-cli --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
  464. (time ./bin/llama-cli --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
  465. (time ./bin/llama-cli --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
  466. (time ./bin/llama-cli --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
  467. (time ./bin/llama-cli --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
  468. (time ./bin/llama-cli --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
  469. (time ./bin/llama-cli --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
  470. (time ./bin/llama-cli --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
  471. (time ./bin/llama-cli --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
  472. (time ./bin/llama-cli --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
  473. (time ./bin/llama-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
  474. (time ./bin/llama-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
  475. (time ./bin/llama-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
  476. (time ./bin/llama-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
  477. (time ./bin/llama-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
  478. (time ./bin/llama-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
  479. (time ./bin/llama-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
  480. (time ./bin/llama-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
  481. (time ./bin/llama-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
  482. (time ./bin/llama-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
  483. (time ./bin/llama-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
  484. (time ./bin/llama-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
  485. (time ./bin/llama-save-load-state -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  486. (time ./bin/llama-save-load-state -fa -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  487. (time ./bin/llama-save-load-state -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  488. (time ./bin/llama-save-load-state -fa -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  489. function check_ppl {
  490. qnt="$1"
  491. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  492. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  493. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  494. return 20
  495. fi
  496. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  497. return 0
  498. }
  499. check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  500. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  501. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  502. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  503. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  504. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  505. #check_ppl "q2_k" "$(cat $OUT/${ci}-tg-q2_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log # note: ppl > 20.0 for this quant and model
  506. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  507. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  508. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  509. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  510. cat $OUT/${ci}-imatrix.log | grep "Final" >> $OUT/${ci}-imatrix-sum.log
  511. set +e
  512. }
  513. function gg_sum_pythia_2_8b {
  514. gg_printf '### %s\n\n' "${ci}"
  515. gg_printf 'Pythia 2.8B:\n'
  516. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  517. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  518. gg_printf '- imatrix:\n```\n%s\n```\n' "$(cat $OUT/${ci}-imatrix-sum.log)"
  519. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  520. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  521. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  522. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  523. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  524. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  525. gg_printf '- q2_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q2_k.log)"
  526. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  527. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  528. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  529. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  530. gg_printf '- save-load-state: \n```\n%s\n```\n' "$(cat $OUT/${ci}-save-load-state.log)"
  531. }
  532. # bge-small
  533. function gg_run_embd_bge_small {
  534. cd ${SRC}
  535. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json
  536. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer.json
  537. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer_config.json
  538. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/special_tokens_map.json
  539. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/resolve/main/pytorch_model.bin
  540. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/sentence_bert_config.json
  541. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/vocab.txt
  542. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/modules.json
  543. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json
  544. gg_wget models-mnt/bge-small/1_Pooling https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/1_Pooling/config.json
  545. path_models="../models-mnt/bge-small"
  546. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  547. set -e
  548. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  549. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  550. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  551. model_f16="${path_models}/ggml-model-f16.gguf"
  552. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  553. ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0
  554. (time ./bin/llama-embedding --model ${model_f16} -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  555. (time ./bin/llama-embedding --model ${model_q8_0} -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  556. set +e
  557. }
  558. function gg_check_build_requirements {
  559. if ! command -v cmake &> /dev/null; then
  560. gg_printf 'cmake not found, please install'
  561. fi
  562. if ! command -v make &> /dev/null; then
  563. gg_printf 'make not found, please install'
  564. fi
  565. if ! command -v ctest &> /dev/null; then
  566. gg_printf 'ctest not found, please install'
  567. fi
  568. }
  569. function gg_sum_embd_bge_small {
  570. gg_printf '### %s\n\n' "${ci}"
  571. gg_printf 'BGE Small (BERT):\n'
  572. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  573. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  574. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  575. }
  576. ## main
  577. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  578. # Create symlink: ./llama.cpp/models-mnt -> $MNT/models/models-mnt
  579. rm -rf ${SRC}/models-mnt
  580. mnt_models=${MNT}/models
  581. mkdir -p ${mnt_models}
  582. ln -sfn ${mnt_models} ${SRC}/models-mnt
  583. # Create a fresh python3 venv and enter it
  584. python3 -m venv "$MNT/venv"
  585. source "$MNT/venv/bin/activate"
  586. pip install -r ${SRC}/requirements.txt --disable-pip-version-check
  587. pip install --editable gguf-py --disable-pip-version-check
  588. fi
  589. ret=0
  590. test $ret -eq 0 && gg_run ctest_debug
  591. test $ret -eq 0 && gg_run ctest_release
  592. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  593. test $ret -eq 0 && gg_run embd_bge_small
  594. if [ -z ${GG_BUILD_CLOUD} ] || [ ${GG_BUILD_EXTRA_TESTS_0} ]; then
  595. test $ret -eq 0 && gg_run test_scripts_debug
  596. test $ret -eq 0 && gg_run test_scripts_release
  597. fi
  598. if [ -z ${GG_BUILD_VRAM_GB} ] || [ ${GG_BUILD_VRAM_GB} -ge 8 ]; then
  599. if [ -z ${GG_BUILD_CUDA} ]; then
  600. test $ret -eq 0 && gg_run pythia_1_4b
  601. else
  602. test $ret -eq 0 && gg_run pythia_2_8b
  603. #test $ret -eq 0 && gg_run open_llama_7b_v2
  604. fi
  605. test $ret -eq 0 && gg_run ctest_with_model_debug
  606. test $ret -eq 0 && gg_run ctest_with_model_release
  607. fi
  608. fi
  609. exit $ret