run.sh 42 KB

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