run.sh 42 KB

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