run.sh 25 KB

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