run.sh 42 KB

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