run.sh 25 KB

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