run.sh 43 KB

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