run.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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-f16.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-f16.gguf --outtype f16
  263. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-bf16.gguf --outtype bf16
  264. model_f16="${path_models}/ggml-model-f16.gguf"
  265. model_bf16="${path_models}/ggml-model-bf16.gguf"
  266. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  267. model_q4_0="${path_models}/ggml-model-q4_0.gguf"
  268. model_q4_1="${path_models}/ggml-model-q4_1.gguf"
  269. model_q5_0="${path_models}/ggml-model-q5_0.gguf"
  270. model_q5_1="${path_models}/ggml-model-q5_1.gguf"
  271. model_q2_k="${path_models}/ggml-model-q2_k.gguf"
  272. model_q3_k="${path_models}/ggml-model-q3_k.gguf"
  273. model_q4_k="${path_models}/ggml-model-q4_k.gguf"
  274. model_q5_k="${path_models}/ggml-model-q5_k.gguf"
  275. model_q6_k="${path_models}/ggml-model-q6_k.gguf"
  276. wiki_test="${path_wiki}/wiki.test.raw"
  277. ./bin/llama-quantize ${model_bf16} ${model_q8_0} q8_0
  278. ./bin/llama-quantize ${model_bf16} ${model_q4_0} q4_0
  279. ./bin/llama-quantize ${model_bf16} ${model_q4_1} q4_1
  280. ./bin/llama-quantize ${model_bf16} ${model_q5_0} q5_0
  281. ./bin/llama-quantize ${model_bf16} ${model_q5_1} q5_1
  282. ./bin/llama-quantize ${model_bf16} ${model_q2_k} q2_k
  283. ./bin/llama-quantize ${model_bf16} ${model_q3_k} q3_k
  284. ./bin/llama-quantize ${model_bf16} ${model_q4_k} q4_k
  285. ./bin/llama-quantize ${model_bf16} ${model_q5_k} q5_k
  286. ./bin/llama-quantize ${model_bf16} ${model_q6_k} q6_k
  287. (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
  288. (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
  289. (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
  290. (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
  291. (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
  292. (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
  293. (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
  294. (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
  295. (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
  296. (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
  297. (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
  298. (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
  299. (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
  300. if [ -z ${GG_BUILD_NO_BF16} ]; then
  301. (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
  302. fi
  303. (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
  304. (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
  305. (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
  306. (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
  307. (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
  308. (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
  309. (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
  310. (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
  311. (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
  312. (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
  313. (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
  314. (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
  315. (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
  316. (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
  317. (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
  318. function check_ppl {
  319. qnt="$1"
  320. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  321. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  322. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  323. return 20
  324. fi
  325. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  326. return 0
  327. }
  328. check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  329. if [ -z ${GG_BUILD_NO_BF16} ]; then
  330. check_ppl "bf16" "$(cat $OUT/${ci}-tg-bf16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  331. fi
  332. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  333. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  334. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  335. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  336. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  337. #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
  338. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  339. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  340. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  341. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  342. cat $OUT/${ci}-imatrix.log | grep "Final" >> $OUT/${ci}-imatrix-sum.log
  343. set +e
  344. }
  345. function gg_sum_qwen3_0_6b {
  346. gg_printf '### %s\n\n' "${ci}"
  347. gg_printf 'Pythia 2.8B:\n'
  348. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  349. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  350. gg_printf '- imatrix:\n```\n%s\n```\n' "$(cat $OUT/${ci}-imatrix-sum.log)"
  351. gg_printf '- f16:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  352. if [ -z ${GG_BUILD_NO_BF16} ]; then
  353. gg_printf '- bf16:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-bf16.log)"
  354. fi
  355. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  356. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  357. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  358. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  359. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  360. gg_printf '- q2_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q2_k.log)"
  361. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  362. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  363. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  364. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  365. gg_printf '- save-load-state: \n```\n%s\n```\n' "$(cat $OUT/${ci}-save-load-state.log)"
  366. }
  367. # bge-small
  368. function gg_run_embd_bge_small {
  369. cd ${SRC}
  370. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json
  371. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer.json
  372. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer_config.json
  373. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/special_tokens_map.json
  374. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/resolve/main/pytorch_model.bin
  375. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/sentence_bert_config.json
  376. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/vocab.txt
  377. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/modules.json
  378. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json
  379. gg_wget models-mnt/bge-small/1_Pooling https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/1_Pooling/config.json
  380. path_models="../models-mnt/bge-small"
  381. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  382. set -e
  383. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  384. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  385. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  386. model_f16="${path_models}/ggml-model-f16.gguf"
  387. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  388. ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0
  389. (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
  390. (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
  391. set +e
  392. }
  393. function gg_sum_embd_bge_small {
  394. gg_printf '### %s\n\n' "${ci}"
  395. gg_printf 'BGE Small (BERT):\n'
  396. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  397. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  398. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  399. }
  400. # rerank_tiny
  401. function gg_run_rerank_tiny {
  402. cd ${SRC}
  403. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json
  404. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer.json
  405. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer_config.json
  406. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/special_tokens_map.json
  407. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/resolve/main/pytorch_model.bin
  408. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/sentence_bert_config.json
  409. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/vocab.txt
  410. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/modules.json
  411. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json
  412. gg_wget models-mnt/rerank-tiny/1_Pooling https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/1_Pooling/config.json
  413. path_models="../models-mnt/rerank-tiny"
  414. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  415. set -e
  416. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  417. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  418. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  419. model_f16="${path_models}/ggml-model-f16.gguf"
  420. # for this model, the SEP token is "</s>"
  421. (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
  422. # sample output
  423. # rerank score 0: 0.029
  424. # rerank score 1: 0.029
  425. # rerank score 2: 0.135
  426. # check that the score is in the range [$3, $4]
  427. function check_score {
  428. qnt="$1"
  429. score=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  430. if [ $(echo "$score < $3" | bc) -eq 1 ] || [ $(echo "$score > $4" | bc) -eq 1 ]; then
  431. printf ' - %s @ %s (FAIL: score not in range [%s, %s])\n' "$qnt" "$score" "$3" "$4"
  432. return 20
  433. fi
  434. printf ' - %s @ %s OK\n' "$qnt" "$score"
  435. return 0
  436. }
  437. 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
  438. 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
  439. 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
  440. set +e
  441. }
  442. function gg_sum_rerank_tiny {
  443. gg_printf '### %s\n\n' "${ci}"
  444. gg_printf 'Rerank Tiny (Jina):\n'
  445. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  446. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-rk-f16.log)"
  447. }
  448. function gg_check_build_requirements {
  449. if ! command -v cmake &> /dev/null; then
  450. gg_printf 'cmake not found, please install'
  451. fi
  452. if ! command -v make &> /dev/null; then
  453. gg_printf 'make not found, please install'
  454. fi
  455. if ! command -v ctest &> /dev/null; then
  456. gg_printf 'ctest not found, please install'
  457. fi
  458. }
  459. ## main
  460. export LLAMA_LOG_PREFIX=1
  461. export LLAMA_LOG_TIMESTAMPS=1
  462. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  463. # Create symlink: ./llama.cpp/models-mnt -> $MNT/models
  464. rm -rf ${SRC}/models-mnt
  465. mnt_models=${MNT}/models
  466. mkdir -p ${mnt_models}
  467. ln -sfn ${mnt_models} ${SRC}/models-mnt
  468. # Create a fresh python3 venv and enter it
  469. if ! python3 -m venv "$MNT/venv"; then
  470. echo "Error: Failed to create Python virtual environment at $MNT/venv."
  471. exit 1
  472. fi
  473. source "$MNT/venv/bin/activate"
  474. pip install -r ${SRC}/requirements.txt --disable-pip-version-check
  475. pip install --editable gguf-py --disable-pip-version-check
  476. fi
  477. ret=0
  478. test $ret -eq 0 && gg_run ctest_debug
  479. test $ret -eq 0 && gg_run ctest_release
  480. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  481. test $ret -eq 0 && gg_run embd_bge_small
  482. test $ret -eq 0 && gg_run rerank_tiny
  483. if [ -z ${GG_BUILD_CLOUD} ] || [ ${GG_BUILD_EXTRA_TESTS_0} ]; then
  484. test $ret -eq 0 && gg_run test_scripts_debug
  485. test $ret -eq 0 && gg_run test_scripts_release
  486. fi
  487. test $ret -eq 0 && gg_run qwen3_0_6b
  488. test $ret -eq 0 && gg_run ctest_with_model_debug
  489. test $ret -eq 0 && gg_run ctest_with_model_release
  490. fi
  491. exit $ret