run.sh 43 KB

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