run.sh 25 KB

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