run.sh 27 KB

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