run.sh 34 KB

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