run.sh 43 KB

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