run.sh 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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_ROCM} ]; then
  59. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_HIP=ON"
  60. if [ -z ${GG_BUILD_AMDGPU_TARGETS} ]; then
  61. echo "Missing GG_BUILD_AMDGPU_TARGETS, please set it to your GPU architecture (e.g. gfx90a, gfx1100, etc.)"
  62. exit 1
  63. fi
  64. CMAKE_EXTRA="${CMAKE_EXTRA} -DAMDGPU_TARGETS=${GG_BUILD_AMDGPU_TARGETS}"
  65. fi
  66. if [ ! -z ${GG_BUILD_SYCL} ]; then
  67. if [ -z ${ONEAPI_ROOT} ]; then
  68. echo "Not detected ONEAPI_ROOT, please install oneAPI base toolkit and enable it by:"
  69. echo "source /opt/intel/oneapi/setvars.sh"
  70. exit 1
  71. fi
  72. # Use only main GPU
  73. export ONEAPI_DEVICE_SELECTOR="level_zero:0"
  74. # Enable sysman for correct memory reporting
  75. export ZES_ENABLE_SYSMAN=1
  76. # to circumvent precision issues on CPY operations
  77. export SYCL_PROGRAM_COMPILE_OPTIONS="-cl-fp32-correctly-rounded-divide-sqrt"
  78. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_SYCL=1 -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON"
  79. fi
  80. if [ ! -z ${GG_BUILD_VULKAN} ]; then
  81. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_VULKAN=1"
  82. fi
  83. if [ ! -z ${GG_BUILD_WEBGPU} ]; then
  84. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_WEBGPU=1"
  85. fi
  86. if [ ! -z ${GG_BUILD_MUSA} ]; then
  87. # Use qy1 by default (MTT S80)
  88. MUSA_ARCH=${MUSA_ARCH:-21}
  89. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_MUSA=ON -DMUSA_ARCHITECTURES=${MUSA_ARCH}"
  90. fi
  91. ## helpers
  92. # download a file if it does not exist or if it is outdated
  93. function gg_wget {
  94. local out=$1
  95. local url=$2
  96. local cwd=`pwd`
  97. mkdir -p $out
  98. cd $out
  99. # should not re-download if file is the same
  100. wget -nv -c -N $url
  101. cd $cwd
  102. }
  103. function gg_printf {
  104. printf -- "$@" >> $OUT/README.md
  105. }
  106. function gg_run {
  107. ci=$1
  108. set -o pipefail
  109. set -x
  110. gg_run_$ci | tee $OUT/$ci.log
  111. cur=$?
  112. echo "$cur" > $OUT/$ci.exit
  113. set +x
  114. set +o pipefail
  115. gg_sum_$ci
  116. ret=$((ret | cur))
  117. }
  118. ## ci
  119. # ctest_debug
  120. function gg_run_ctest_debug {
  121. cd ${SRC}
  122. rm -rf build-ci-debug && mkdir build-ci-debug && cd build-ci-debug
  123. set -e
  124. # Check cmake, make and ctest are installed
  125. gg_check_build_requirements
  126. (time cmake -DCMAKE_BUILD_TYPE=Debug ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  127. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  128. (time ctest --output-on-failure -L main -E "test-opt|test-backend-ops" ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  129. set +e
  130. }
  131. function gg_sum_ctest_debug {
  132. gg_printf '### %s\n\n' "${ci}"
  133. gg_printf 'Runs ctest in debug mode\n'
  134. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  135. gg_printf '```\n'
  136. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  137. gg_printf '```\n'
  138. gg_printf '\n'
  139. }
  140. # ctest_release
  141. function gg_run_ctest_release {
  142. cd ${SRC}
  143. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  144. set -e
  145. # Check cmake, make and ctest are installed
  146. gg_check_build_requirements
  147. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  148. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  149. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  150. (time ctest --output-on-failure -L main ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  151. else
  152. (time ctest --output-on-failure -L main -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  153. fi
  154. set +e
  155. }
  156. function gg_sum_ctest_release {
  157. gg_printf '### %s\n\n' "${ci}"
  158. gg_printf 'Runs ctest in release mode\n'
  159. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  160. gg_printf '```\n'
  161. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  162. gg_printf '```\n'
  163. }
  164. # test_scripts_debug
  165. function gg_run_test_scripts_debug {
  166. cd ${SRC}
  167. set -e
  168. (cd ./tools/gguf-split && time bash tests.sh "$SRC/build-ci-debug/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  169. (cd ./tools/quantize && time bash tests.sh "$SRC/build-ci-debug/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  170. set +e
  171. }
  172. function gg_sum_test_scripts_debug {
  173. gg_printf '### %s\n\n' "${ci}"
  174. gg_printf 'Runs test scripts in debug mode\n'
  175. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  176. gg_printf '```\n'
  177. gg_printf '%s\n' "$(cat $OUT/${ci}-scripts.log)"
  178. gg_printf '```\n'
  179. gg_printf '\n'
  180. }
  181. # test_scripts_release
  182. function gg_run_test_scripts_release {
  183. cd ${SRC}
  184. set -e
  185. (cd ./tools/gguf-split && time bash tests.sh "$SRC/build-ci-release/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  186. (cd ./tools/quantize && time bash tests.sh "$SRC/build-ci-release/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  187. set +e
  188. }
  189. function gg_sum_test_scripts_release {
  190. gg_printf '### %s\n\n' "${ci}"
  191. gg_printf 'Runs test scripts in release mode\n'
  192. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  193. gg_printf '```\n'
  194. gg_printf '%s\n' "$(cat $OUT/${ci}-scripts.log)"
  195. gg_printf '```\n'
  196. gg_printf '\n'
  197. }
  198. function gg_get_model {
  199. local gguf_0="$MNT/models/qwen3/0.6B/ggml-model-bf16.gguf"
  200. if [[ -s $gguf_0 ]]; then
  201. echo -n "$gguf_0"
  202. else
  203. echo >&2 "No model found. Can't run gg_run_ctest_with_model."
  204. exit 1
  205. fi
  206. }
  207. function gg_run_ctest_with_model_debug {
  208. cd ${SRC}
  209. local model; model=$(gg_get_model)
  210. cd build-ci-debug
  211. set -e
  212. (LLAMACPP_TEST_MODELFILE="$model" time ctest --output-on-failure -L model) 2>&1 | tee -a $OUT/${ci}-ctest.log
  213. set +e
  214. cd ..
  215. }
  216. function gg_run_ctest_with_model_release {
  217. cd ${SRC}
  218. local model; model=$(gg_get_model)
  219. cd build-ci-release
  220. set -e
  221. (LLAMACPP_TEST_MODELFILE="$model" time ctest --output-on-failure -L model) 2>&1 | tee -a $OUT/${ci}-ctest.log
  222. # test memory leaks
  223. #if [[ ! -z ${GG_BUILD_METAL} ]]; then
  224. # # TODO: this hangs for some reason ...
  225. # (time leaks -quiet -atExit -- ./bin/test-thread-safety -m $model --parallel 2 -t 2 -p "hello") 2>&1 | tee -a $OUT/${ci}-leaks.log
  226. #fi
  227. set +e
  228. cd ..
  229. }
  230. function gg_sum_ctest_with_model_debug {
  231. gg_printf '### %s\n\n' "${ci}"
  232. gg_printf 'Runs ctest with model files in debug mode\n'
  233. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  234. gg_printf '```\n'
  235. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  236. gg_printf '```\n'
  237. }
  238. function gg_sum_ctest_with_model_release {
  239. gg_printf '### %s\n\n' "${ci}"
  240. gg_printf 'Runs ctest with model files in release mode\n'
  241. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  242. gg_printf '```\n'
  243. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  244. gg_printf '```\n'
  245. }
  246. # qwen3_0_6b
  247. function gg_run_qwen3_0_6b {
  248. cd ${SRC}
  249. gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/config.json
  250. gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/tokenizer.json
  251. gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/tokenizer_config.json
  252. #gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/special_tokens_map.json
  253. gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/resolve/main/model.safetensors
  254. gg_wget models-mnt/wikitext/ https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip
  255. unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
  256. path_models="../models-mnt/qwen3/0.6B"
  257. path_wiki="../models-mnt/wikitext/wikitext-2-raw"
  258. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  259. set -e
  260. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  261. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  262. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-bf16.gguf --outtype bf16
  263. model_bf16="${path_models}/ggml-model-bf16.gguf"
  264. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  265. model_q4_0="${path_models}/ggml-model-q4_0.gguf"
  266. model_q4_1="${path_models}/ggml-model-q4_1.gguf"
  267. model_q5_0="${path_models}/ggml-model-q5_0.gguf"
  268. model_q5_1="${path_models}/ggml-model-q5_1.gguf"
  269. model_q2_k="${path_models}/ggml-model-q2_k.gguf"
  270. model_q3_k="${path_models}/ggml-model-q3_k.gguf"
  271. model_q4_k="${path_models}/ggml-model-q4_k.gguf"
  272. model_q5_k="${path_models}/ggml-model-q5_k.gguf"
  273. model_q6_k="${path_models}/ggml-model-q6_k.gguf"
  274. wiki_test="${path_wiki}/wiki.test.raw"
  275. ./bin/llama-quantize ${model_bf16} ${model_q8_0} q8_0
  276. ./bin/llama-quantize ${model_bf16} ${model_q4_0} q4_0
  277. ./bin/llama-quantize ${model_bf16} ${model_q4_1} q4_1
  278. ./bin/llama-quantize ${model_bf16} ${model_q5_0} q5_0
  279. ./bin/llama-quantize ${model_bf16} ${model_q5_1} q5_1
  280. ./bin/llama-quantize ${model_bf16} ${model_q2_k} q2_k
  281. ./bin/llama-quantize ${model_bf16} ${model_q3_k} q3_k
  282. ./bin/llama-quantize ${model_bf16} ${model_q4_k} q4_k
  283. ./bin/llama-quantize ${model_bf16} ${model_q5_k} q5_k
  284. ./bin/llama-quantize ${model_bf16} ${model_q6_k} q6_k
  285. (time ./bin/llama-cli -no-cnv --model ${model_bf16} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-bf16.log
  286. (time ./bin/llama-cli -no-cnv --model ${model_q8_0} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  287. (time ./bin/llama-cli -no-cnv --model ${model_q4_0} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  288. (time ./bin/llama-cli -no-cnv --model ${model_q4_1} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  289. (time ./bin/llama-cli -no-cnv --model ${model_q5_0} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  290. (time ./bin/llama-cli -no-cnv --model ${model_q5_1} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  291. (time ./bin/llama-cli -no-cnv --model ${model_q2_k} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  292. (time ./bin/llama-cli -no-cnv --model ${model_q3_k} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  293. (time ./bin/llama-cli -no-cnv --model ${model_q4_k} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  294. (time ./bin/llama-cli -no-cnv --model ${model_q5_k} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  295. (time ./bin/llama-cli -no-cnv --model ${model_q6_k} -t 1 -ngl 99 -c 2048 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  296. (time ./bin/llama-perplexity --model ${model_bf16} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-bf16.log
  297. (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
  298. (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
  299. (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
  300. (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
  301. (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
  302. (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
  303. (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
  304. (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
  305. (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
  306. (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
  307. (time ./bin/llama-imatrix --model ${model_bf16} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log
  308. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 10 -c 2048 -fa off ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  309. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 10 -c 2048 -fa on ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  310. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 99 -c 2048 -fa off ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  311. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 99 -c 2048 -fa on ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  312. function check_ppl {
  313. qnt="$1"
  314. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  315. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  316. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  317. return 20
  318. fi
  319. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  320. return 0
  321. }
  322. check_ppl "bf16" "$(cat $OUT/${ci}-tg-bf16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  323. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  324. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  325. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  326. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  327. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  328. #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
  329. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  330. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  331. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  332. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  333. cat $OUT/${ci}-imatrix.log | grep "Final" >> $OUT/${ci}-imatrix-sum.log
  334. set +e
  335. }
  336. function gg_sum_qwen3_0_6b {
  337. gg_printf '### %s\n\n' "${ci}"
  338. gg_printf 'Pythia 2.8B:\n'
  339. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  340. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  341. gg_printf '- imatrix:\n```\n%s\n```\n' "$(cat $OUT/${ci}-imatrix-sum.log)"
  342. gg_printf '- bf16:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-bf16.log)"
  343. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  344. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  345. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  346. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  347. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  348. gg_printf '- q2_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q2_k.log)"
  349. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  350. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  351. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  352. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  353. gg_printf '- save-load-state: \n```\n%s\n```\n' "$(cat $OUT/${ci}-save-load-state.log)"
  354. }
  355. # bge-small
  356. function gg_run_embd_bge_small {
  357. cd ${SRC}
  358. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json
  359. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer.json
  360. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer_config.json
  361. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/special_tokens_map.json
  362. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/resolve/main/pytorch_model.bin
  363. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/sentence_bert_config.json
  364. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/vocab.txt
  365. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/modules.json
  366. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json
  367. gg_wget models-mnt/bge-small/1_Pooling https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/1_Pooling/config.json
  368. path_models="../models-mnt/bge-small"
  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. ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0
  377. (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
  378. (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
  379. set +e
  380. }
  381. function gg_sum_embd_bge_small {
  382. gg_printf '### %s\n\n' "${ci}"
  383. gg_printf 'BGE Small (BERT):\n'
  384. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  385. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  386. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  387. }
  388. # rerank_tiny
  389. function gg_run_rerank_tiny {
  390. cd ${SRC}
  391. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json
  392. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer.json
  393. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer_config.json
  394. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/special_tokens_map.json
  395. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/resolve/main/pytorch_model.bin
  396. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/sentence_bert_config.json
  397. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/vocab.txt
  398. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/modules.json
  399. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json
  400. gg_wget models-mnt/rerank-tiny/1_Pooling https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/1_Pooling/config.json
  401. path_models="../models-mnt/rerank-tiny"
  402. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  403. set -e
  404. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  405. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  406. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  407. model_f16="${path_models}/ggml-model-f16.gguf"
  408. # for this model, the SEP token is "</s>"
  409. (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
  410. # sample output
  411. # rerank score 0: 0.029
  412. # rerank score 1: 0.029
  413. # rerank score 2: 0.135
  414. # check that the score is in the range [$3, $4]
  415. function check_score {
  416. qnt="$1"
  417. score=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  418. if [ $(echo "$score < $3" | bc) -eq 1 ] || [ $(echo "$score > $4" | bc) -eq 1 ]; then
  419. printf ' - %s @ %s (FAIL: score not in range [%s, %s])\n' "$qnt" "$score" "$3" "$4"
  420. return 20
  421. fi
  422. printf ' - %s @ %s OK\n' "$qnt" "$score"
  423. return 0
  424. }
  425. 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
  426. 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
  427. 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
  428. set +e
  429. }
  430. function gg_sum_rerank_tiny {
  431. gg_printf '### %s\n\n' "${ci}"
  432. gg_printf 'Rerank Tiny (Jina):\n'
  433. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  434. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-rk-f16.log)"
  435. }
  436. function gg_check_build_requirements {
  437. if ! command -v cmake &> /dev/null; then
  438. gg_printf 'cmake not found, please install'
  439. fi
  440. if ! command -v make &> /dev/null; then
  441. gg_printf 'make not found, please install'
  442. fi
  443. if ! command -v ctest &> /dev/null; then
  444. gg_printf 'ctest not found, please install'
  445. fi
  446. }
  447. ## main
  448. export LLAMA_LOG_PREFIX=1
  449. export LLAMA_LOG_TIMESTAMPS=1
  450. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  451. # Create symlink: ./llama.cpp/models-mnt -> $MNT/models
  452. rm -rf ${SRC}/models-mnt
  453. mnt_models=${MNT}/models
  454. mkdir -p ${mnt_models}
  455. ln -sfn ${mnt_models} ${SRC}/models-mnt
  456. # Create a fresh python3 venv and enter it
  457. if ! python3 -m venv "$MNT/venv"; then
  458. echo "Error: Failed to create Python virtual environment at $MNT/venv."
  459. exit 1
  460. fi
  461. source "$MNT/venv/bin/activate"
  462. pip install -r ${SRC}/requirements.txt --disable-pip-version-check
  463. pip install --editable gguf-py --disable-pip-version-check
  464. fi
  465. ret=0
  466. test $ret -eq 0 && gg_run ctest_debug
  467. test $ret -eq 0 && gg_run ctest_release
  468. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  469. test $ret -eq 0 && gg_run embd_bge_small
  470. test $ret -eq 0 && gg_run rerank_tiny
  471. if [ -z ${GG_BUILD_CLOUD} ] || [ ${GG_BUILD_EXTRA_TESTS_0} ]; then
  472. test $ret -eq 0 && gg_run test_scripts_debug
  473. test $ret -eq 0 && gg_run test_scripts_release
  474. fi
  475. test $ret -eq 0 && gg_run qwen3_0_6b
  476. test $ret -eq 0 && gg_run ctest_with_model_debug
  477. test $ret -eq 0 && gg_run ctest_with_model_release
  478. fi
  479. exit $ret