run.sh 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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 -DGGML_METAL_USE_BF16=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_SYCL} ]; then
  59. if [ -z ${ONEAPI_ROOT} ]; then
  60. echo "Not detected ONEAPI_ROOT, please install oneAPI base toolkit and enable it by:"
  61. echo "source /opt/intel/oneapi/setvars.sh"
  62. exit 1
  63. fi
  64. # Use only main GPU
  65. export ONEAPI_DEVICE_SELECTOR="level_zero:0"
  66. # Enable sysman for correct memory reporting
  67. export ZES_ENABLE_SYSMAN=1
  68. # to circumvent precision issues on CPY operations
  69. export SYCL_PROGRAM_COMPILE_OPTIONS="-cl-fp32-correctly-rounded-divide-sqrt"
  70. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_SYCL=1 -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON"
  71. fi
  72. if [ ! -z ${GG_BUILD_VULKAN} ]; then
  73. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_VULKAN=1"
  74. fi
  75. if [ ! -z ${GG_BUILD_WEBGPU} ]; then
  76. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_WEBGPU=1"
  77. fi
  78. if [ ! -z ${GG_BUILD_MUSA} ]; then
  79. # Use qy1 by default (MTT S80)
  80. MUSA_ARCH=${MUSA_ARCH:-21}
  81. CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_MUSA=ON -DMUSA_ARCHITECTURES=${MUSA_ARCH}"
  82. fi
  83. ## helpers
  84. # download a file if it does not exist or if it is outdated
  85. function gg_wget {
  86. local out=$1
  87. local url=$2
  88. local cwd=`pwd`
  89. mkdir -p $out
  90. cd $out
  91. # should not re-download if file is the same
  92. wget -nv -N $url
  93. cd $cwd
  94. }
  95. function gg_printf {
  96. printf -- "$@" >> $OUT/README.md
  97. }
  98. function gg_run {
  99. ci=$1
  100. set -o pipefail
  101. set -x
  102. gg_run_$ci | tee $OUT/$ci.log
  103. cur=$?
  104. echo "$cur" > $OUT/$ci.exit
  105. set +x
  106. set +o pipefail
  107. gg_sum_$ci
  108. ret=$((ret | cur))
  109. }
  110. ## ci
  111. # ctest_debug
  112. function gg_run_ctest_debug {
  113. cd ${SRC}
  114. rm -rf build-ci-debug && mkdir build-ci-debug && cd build-ci-debug
  115. set -e
  116. # Check cmake, make and ctest are installed
  117. gg_check_build_requirements
  118. (time cmake -DCMAKE_BUILD_TYPE=Debug ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  119. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  120. (time ctest --output-on-failure -L main -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  121. set +e
  122. }
  123. function gg_sum_ctest_debug {
  124. gg_printf '### %s\n\n' "${ci}"
  125. gg_printf 'Runs ctest in debug mode\n'
  126. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  127. gg_printf '```\n'
  128. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  129. gg_printf '```\n'
  130. gg_printf '\n'
  131. }
  132. # ctest_release
  133. function gg_run_ctest_release {
  134. cd ${SRC}
  135. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  136. set -e
  137. # Check cmake, make and ctest are installed
  138. gg_check_build_requirements
  139. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  140. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  141. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  142. (time ctest --output-on-failure -L main ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  143. else
  144. (time ctest --output-on-failure -L main -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  145. fi
  146. set +e
  147. }
  148. function gg_sum_ctest_release {
  149. gg_printf '### %s\n\n' "${ci}"
  150. gg_printf 'Runs ctest in release mode\n'
  151. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  152. gg_printf '```\n'
  153. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  154. gg_printf '```\n'
  155. }
  156. # test_scripts_debug
  157. function gg_run_test_scripts_debug {
  158. cd ${SRC}
  159. set -e
  160. (cd ./tools/gguf-split && time bash tests.sh "$SRC/build-ci-debug/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  161. (cd ./tools/quantize && time bash tests.sh "$SRC/build-ci-debug/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  162. set +e
  163. }
  164. function gg_sum_test_scripts_debug {
  165. gg_printf '### %s\n\n' "${ci}"
  166. gg_printf 'Runs test scripts in debug mode\n'
  167. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  168. gg_printf '```\n'
  169. gg_printf '%s\n' "$(cat $OUT/${ci}-scripts.log)"
  170. gg_printf '```\n'
  171. gg_printf '\n'
  172. }
  173. # test_scripts_release
  174. function gg_run_test_scripts_release {
  175. cd ${SRC}
  176. set -e
  177. (cd ./tools/gguf-split && time bash tests.sh "$SRC/build-ci-release/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  178. (cd ./tools/quantize && time bash tests.sh "$SRC/build-ci-release/bin" "$MNT/models") 2>&1 | tee -a $OUT/${ci}-scripts.log
  179. set +e
  180. }
  181. function gg_sum_test_scripts_release {
  182. gg_printf '### %s\n\n' "${ci}"
  183. gg_printf 'Runs test scripts in release mode\n'
  184. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  185. gg_printf '```\n'
  186. gg_printf '%s\n' "$(cat $OUT/${ci}-scripts.log)"
  187. gg_printf '```\n'
  188. gg_printf '\n'
  189. }
  190. function gg_get_model {
  191. local gguf_0="$MNT/models/pythia/1.4B/ggml-model-f16.gguf"
  192. local gguf_1="$MNT/models/pythia/2.8B/ggml-model-f16.gguf"
  193. local gguf_2="$MNT/models/open-llama/7B-v2/ggml-model-f16.gguf"
  194. if [[ -s $gguf_0 ]]; then
  195. echo -n "$gguf_0"
  196. elif [[ -s $gguf_1 ]]; then
  197. echo -n "$gguf_1"
  198. elif [[ -s $gguf_2 ]]; then
  199. echo -n "$gguf_2"
  200. else
  201. echo >&2 "No model found. Can't run gg_run_ctest_with_model."
  202. exit 1
  203. fi
  204. }
  205. function gg_run_ctest_with_model_debug {
  206. cd ${SRC}
  207. local model; model=$(gg_get_model)
  208. cd build-ci-debug
  209. set -e
  210. (LLAMACPP_TEST_MODELFILE="$model" time ctest --output-on-failure -L model) 2>&1 | tee -a $OUT/${ci}-ctest.log
  211. set +e
  212. cd ..
  213. }
  214. function gg_run_ctest_with_model_release {
  215. cd ${SRC}
  216. local model; model=$(gg_get_model)
  217. cd build-ci-release
  218. set -e
  219. (LLAMACPP_TEST_MODELFILE="$model" time ctest --output-on-failure -L model) 2>&1 | tee -a $OUT/${ci}-ctest.log
  220. set +e
  221. cd ..
  222. }
  223. function gg_sum_ctest_with_model_debug {
  224. gg_printf '### %s\n\n' "${ci}"
  225. gg_printf 'Runs ctest with model files in debug mode\n'
  226. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  227. gg_printf '```\n'
  228. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  229. gg_printf '```\n'
  230. }
  231. function gg_sum_ctest_with_model_release {
  232. gg_printf '### %s\n\n' "${ci}"
  233. gg_printf 'Runs ctest with model files in release mode\n'
  234. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  235. gg_printf '```\n'
  236. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  237. gg_printf '```\n'
  238. }
  239. # open_llama_7b_v2
  240. function gg_run_open_llama_7b_v2 {
  241. cd ${SRC}
  242. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/config.json
  243. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/resolve/main/tokenizer.model
  244. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/tokenizer_config.json
  245. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/special_tokens_map.json
  246. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/pytorch_model.bin.index.json
  247. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/resolve/main/pytorch_model-00001-of-00002.bin
  248. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/resolve/main/pytorch_model-00002-of-00002.bin
  249. gg_wget models-mnt/open-llama/7B-v2/ https://huggingface.co/openlm-research/open_llama_7b_v2/raw/main/generation_config.json
  250. gg_wget models-mnt/wikitext/ https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip
  251. unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
  252. path_models="../models-mnt/open-llama/7B-v2"
  253. path_wiki="../models-mnt/wikitext/wikitext-2-raw"
  254. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  255. set -e
  256. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  257. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  258. python3 ../examples/convert_legacy_llama.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  259. model_f16="${path_models}/ggml-model-f16.gguf"
  260. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  261. model_q4_0="${path_models}/ggml-model-q4_0.gguf"
  262. model_q4_1="${path_models}/ggml-model-q4_1.gguf"
  263. model_q5_0="${path_models}/ggml-model-q5_0.gguf"
  264. model_q5_1="${path_models}/ggml-model-q5_1.gguf"
  265. model_q2_k="${path_models}/ggml-model-q2_k.gguf"
  266. model_q3_k="${path_models}/ggml-model-q3_k.gguf"
  267. model_q4_k="${path_models}/ggml-model-q4_k.gguf"
  268. model_q5_k="${path_models}/ggml-model-q5_k.gguf"
  269. model_q6_k="${path_models}/ggml-model-q6_k.gguf"
  270. wiki_test="${path_wiki}/wiki.test.raw"
  271. ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0
  272. ./bin/llama-quantize ${model_f16} ${model_q4_0} q4_0
  273. ./bin/llama-quantize ${model_f16} ${model_q4_1} q4_1
  274. ./bin/llama-quantize ${model_f16} ${model_q5_0} q5_0
  275. ./bin/llama-quantize ${model_f16} ${model_q5_1} q5_1
  276. ./bin/llama-quantize ${model_f16} ${model_q2_k} q2_k
  277. ./bin/llama-quantize ${model_f16} ${model_q3_k} q3_k
  278. ./bin/llama-quantize ${model_f16} ${model_q4_k} q4_k
  279. ./bin/llama-quantize ${model_f16} ${model_q5_k} q5_k
  280. ./bin/llama-quantize ${model_f16} ${model_q6_k} q6_k
  281. (time ./bin/llama-cli -no-cnv --model ${model_f16} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  282. (time ./bin/llama-cli -no-cnv --model ${model_q8_0} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  283. (time ./bin/llama-cli -no-cnv --model ${model_q4_0} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  284. (time ./bin/llama-cli -no-cnv --model ${model_q4_1} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  285. (time ./bin/llama-cli -no-cnv --model ${model_q5_0} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  286. (time ./bin/llama-cli -no-cnv --model ${model_q5_1} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  287. (time ./bin/llama-cli -no-cnv --model ${model_q2_k} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  288. (time ./bin/llama-cli -no-cnv --model ${model_q3_k} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  289. (time ./bin/llama-cli -no-cnv --model ${model_q4_k} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  290. (time ./bin/llama-cli -no-cnv --model ${model_q5_k} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  291. (time ./bin/llama-cli -no-cnv --model ${model_q6_k} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  292. (time ./bin/llama-perplexity --model ${model_f16} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  293. (time ./bin/llama-perplexity --model ${model_q8_0} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  294. (time ./bin/llama-perplexity --model ${model_q4_0} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  295. (time ./bin/llama-perplexity --model ${model_q4_1} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  296. (time ./bin/llama-perplexity --model ${model_q5_0} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  297. (time ./bin/llama-perplexity --model ${model_q5_1} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  298. (time ./bin/llama-perplexity --model ${model_q2_k} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  299. (time ./bin/llama-perplexity --model ${model_q3_k} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  300. (time ./bin/llama-perplexity --model ${model_q4_k} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  301. (time ./bin/llama-perplexity --model ${model_q5_k} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  302. (time ./bin/llama-perplexity --model ${model_q6_k} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  303. (time ./bin/llama-imatrix --model ${model_f16} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log
  304. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 10 -c 0 ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  305. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 10 -c 0 -fa ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  306. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 99 -c 0 ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  307. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 99 -c 0 -fa ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  308. function check_ppl {
  309. qnt="$1"
  310. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  311. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  312. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  313. return 20
  314. fi
  315. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  316. return 0
  317. }
  318. check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  319. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  320. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  321. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  322. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  323. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  324. check_ppl "q2_k" "$(cat $OUT/${ci}-tg-q2_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  325. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  326. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  327. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  328. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  329. cat $OUT/${ci}-imatrix.log | grep "Final" >> $OUT/${ci}-imatrix-sum.log
  330. set +e
  331. }
  332. function gg_sum_open_llama_7b_v2 {
  333. gg_printf '### %s\n\n' "${ci}"
  334. gg_printf 'OpenLLaMA 7B-v2:\n'
  335. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  336. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  337. gg_printf '- imatrix:\n```\n%s\n```\n' "$(cat $OUT/${ci}-imatrix-sum.log)"
  338. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  339. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  340. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  341. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  342. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  343. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  344. gg_printf '- q2_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q2_k.log)"
  345. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  346. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  347. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  348. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  349. gg_printf '- save-load-state: \n```\n%s\n```\n' "$(cat $OUT/${ci}-save-load-state.log)"
  350. }
  351. # pythia_1.4b
  352. function gg_run_pythia_1_4b {
  353. cd ${SRC}
  354. gg_wget models-mnt/pythia/1.4B/ https://huggingface.co/EleutherAI/pythia-1.4b/raw/main/config.json
  355. gg_wget models-mnt/pythia/1.4B/ https://huggingface.co/EleutherAI/pythia-1.4b/raw/main/tokenizer.json
  356. gg_wget models-mnt/pythia/1.4B/ https://huggingface.co/EleutherAI/pythia-1.4b/raw/main/tokenizer_config.json
  357. gg_wget models-mnt/pythia/1.4B/ https://huggingface.co/EleutherAI/pythia-1.4b/raw/main/special_tokens_map.json
  358. gg_wget models-mnt/pythia/1.4B/ https://huggingface.co/EleutherAI/pythia-1.4b/resolve/main/pytorch_model.bin
  359. gg_wget models-mnt/wikitext/ https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip
  360. unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
  361. head -n 60 models-mnt/wikitext/wikitext-2-raw/wiki.test.raw > models-mnt/wikitext/wikitext-2-raw/wiki.test-60.raw
  362. path_models="../models-mnt/pythia/1.4B"
  363. path_wiki="../models-mnt/wikitext/wikitext-2-raw"
  364. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  365. set -e
  366. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  367. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  368. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  369. model_f16="${path_models}/ggml-model-f16.gguf"
  370. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  371. model_q4_0="${path_models}/ggml-model-q4_0.gguf"
  372. model_q4_1="${path_models}/ggml-model-q4_1.gguf"
  373. model_q5_0="${path_models}/ggml-model-q5_0.gguf"
  374. model_q5_1="${path_models}/ggml-model-q5_1.gguf"
  375. model_q2_k="${path_models}/ggml-model-q2_k.gguf"
  376. model_q3_k="${path_models}/ggml-model-q3_k.gguf"
  377. model_q4_k="${path_models}/ggml-model-q4_k.gguf"
  378. model_q5_k="${path_models}/ggml-model-q5_k.gguf"
  379. model_q6_k="${path_models}/ggml-model-q6_k.gguf"
  380. wiki_test_60="${path_wiki}/wiki.test-60.raw"
  381. ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0
  382. ./bin/llama-quantize ${model_f16} ${model_q4_0} q4_0
  383. ./bin/llama-quantize ${model_f16} ${model_q4_1} q4_1
  384. ./bin/llama-quantize ${model_f16} ${model_q5_0} q5_0
  385. ./bin/llama-quantize ${model_f16} ${model_q5_1} q5_1
  386. ./bin/llama-quantize ${model_f16} ${model_q2_k} q2_k
  387. ./bin/llama-quantize ${model_f16} ${model_q3_k} q3_k
  388. ./bin/llama-quantize ${model_f16} ${model_q4_k} q4_k
  389. ./bin/llama-quantize ${model_f16} ${model_q5_k} q5_k
  390. ./bin/llama-quantize ${model_f16} ${model_q6_k} q6_k
  391. (time ./bin/llama-cli -no-cnv --model ${model_f16} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  392. (time ./bin/llama-cli -no-cnv --model ${model_q8_0} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  393. (time ./bin/llama-cli -no-cnv --model ${model_q4_0} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  394. (time ./bin/llama-cli -no-cnv --model ${model_q4_1} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  395. (time ./bin/llama-cli -no-cnv --model ${model_q5_0} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  396. (time ./bin/llama-cli -no-cnv --model ${model_q5_1} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  397. (time ./bin/llama-cli -no-cnv --model ${model_q2_k} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  398. (time ./bin/llama-cli -no-cnv --model ${model_q3_k} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  399. (time ./bin/llama-cli -no-cnv --model ${model_q4_k} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  400. (time ./bin/llama-cli -no-cnv --model ${model_q5_k} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  401. (time ./bin/llama-cli -no-cnv --model ${model_q6_k} -ngl 99 -c 0 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  402. (time ./bin/llama-perplexity --model ${model_f16} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  403. (time ./bin/llama-perplexity --model ${model_q8_0} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  404. (time ./bin/llama-perplexity --model ${model_q4_0} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  405. (time ./bin/llama-perplexity --model ${model_q4_1} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  406. (time ./bin/llama-perplexity --model ${model_q5_0} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  407. (time ./bin/llama-perplexity --model ${model_q5_1} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  408. (time ./bin/llama-perplexity --model ${model_q2_k} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  409. (time ./bin/llama-perplexity --model ${model_q3_k} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  410. (time ./bin/llama-perplexity --model ${model_q4_k} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  411. (time ./bin/llama-perplexity --model ${model_q5_k} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  412. (time ./bin/llama-perplexity --model ${model_q6_k} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  413. (time ./bin/llama-imatrix --model ${model_f16} -f ${wiki_test_60} -ngl 99 -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log
  414. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 99 -c 0 ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  415. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 99 -c 0 -fa ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  416. function check_ppl {
  417. qnt="$1"
  418. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  419. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  420. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  421. return 20
  422. fi
  423. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  424. return 0
  425. }
  426. check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  427. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  428. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  429. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  430. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  431. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  432. #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
  433. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  434. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  435. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  436. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  437. cat $OUT/${ci}-imatrix.log | grep "Final" >> $OUT/${ci}-imatrix-sum.log
  438. set +e
  439. }
  440. function gg_sum_pythia_1_4b {
  441. gg_printf '### %s\n\n' "${ci}"
  442. gg_printf 'Pythia 1.4B:\n'
  443. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  444. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  445. gg_printf '- imatrix:\n```\n%s\n```\n' "$(cat $OUT/${ci}-imatrix-sum.log)"
  446. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  447. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  448. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  449. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  450. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  451. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  452. gg_printf '- q2_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q2_k.log)"
  453. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  454. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  455. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  456. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  457. gg_printf '- save-load-state: \n```\n%s\n```\n' "$(cat $OUT/${ci}-save-load-state.log)"
  458. }
  459. # pythia_2_8b
  460. function gg_run_pythia_2_8b {
  461. cd ${SRC}
  462. gg_wget models-mnt/pythia/2.8B/ https://huggingface.co/EleutherAI/pythia-2.8b/raw/main/config.json
  463. gg_wget models-mnt/pythia/2.8B/ https://huggingface.co/EleutherAI/pythia-2.8b/raw/main/tokenizer.json
  464. gg_wget models-mnt/pythia/2.8B/ https://huggingface.co/EleutherAI/pythia-2.8b/raw/main/tokenizer_config.json
  465. gg_wget models-mnt/pythia/2.8B/ https://huggingface.co/EleutherAI/pythia-2.8b/raw/main/special_tokens_map.json
  466. gg_wget models-mnt/pythia/2.8B/ https://huggingface.co/EleutherAI/pythia-2.8b/resolve/main/pytorch_model.bin
  467. gg_wget models-mnt/wikitext/ https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip
  468. unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
  469. path_models="../models-mnt/pythia/2.8B"
  470. path_wiki="../models-mnt/wikitext/wikitext-2-raw"
  471. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  472. set -e
  473. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  474. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  475. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  476. model_f16="${path_models}/ggml-model-f16.gguf"
  477. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  478. model_q4_0="${path_models}/ggml-model-q4_0.gguf"
  479. model_q4_1="${path_models}/ggml-model-q4_1.gguf"
  480. model_q5_0="${path_models}/ggml-model-q5_0.gguf"
  481. model_q5_1="${path_models}/ggml-model-q5_1.gguf"
  482. model_q2_k="${path_models}/ggml-model-q2_k.gguf"
  483. model_q3_k="${path_models}/ggml-model-q3_k.gguf"
  484. model_q4_k="${path_models}/ggml-model-q4_k.gguf"
  485. model_q5_k="${path_models}/ggml-model-q5_k.gguf"
  486. model_q6_k="${path_models}/ggml-model-q6_k.gguf"
  487. wiki_test="${path_wiki}/wiki.test.raw"
  488. ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0
  489. ./bin/llama-quantize ${model_f16} ${model_q4_0} q4_0
  490. ./bin/llama-quantize ${model_f16} ${model_q4_1} q4_1
  491. ./bin/llama-quantize ${model_f16} ${model_q5_0} q5_0
  492. ./bin/llama-quantize ${model_f16} ${model_q5_1} q5_1
  493. ./bin/llama-quantize ${model_f16} ${model_q2_k} q2_k
  494. ./bin/llama-quantize ${model_f16} ${model_q3_k} q3_k
  495. ./bin/llama-quantize ${model_f16} ${model_q4_k} q4_k
  496. ./bin/llama-quantize ${model_f16} ${model_q5_k} q5_k
  497. ./bin/llama-quantize ${model_f16} ${model_q6_k} q6_k
  498. (time ./bin/llama-cli -no-cnv --model ${model_f16} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  499. (time ./bin/llama-cli -no-cnv --model ${model_q8_0} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  500. (time ./bin/llama-cli -no-cnv --model ${model_q4_0} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  501. (time ./bin/llama-cli -no-cnv --model ${model_q4_1} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  502. (time ./bin/llama-cli -no-cnv --model ${model_q5_0} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  503. (time ./bin/llama-cli -no-cnv --model ${model_q5_1} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  504. (time ./bin/llama-cli -no-cnv --model ${model_q2_k} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  505. (time ./bin/llama-cli -no-cnv --model ${model_q3_k} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  506. (time ./bin/llama-cli -no-cnv --model ${model_q4_k} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  507. (time ./bin/llama-cli -no-cnv --model ${model_q5_k} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  508. (time ./bin/llama-cli -no-cnv --model ${model_q6_k} -t 1 -ngl 99 -c 0 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  509. (time ./bin/llama-perplexity --model ${model_f16} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log
  510. (time ./bin/llama-perplexity --model ${model_q8_0} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log
  511. (time ./bin/llama-perplexity --model ${model_q4_0} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log
  512. (time ./bin/llama-perplexity --model ${model_q4_1} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log
  513. (time ./bin/llama-perplexity --model ${model_q5_0} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log
  514. (time ./bin/llama-perplexity --model ${model_q5_1} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log
  515. (time ./bin/llama-perplexity --model ${model_q2_k} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log
  516. (time ./bin/llama-perplexity --model ${model_q3_k} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log
  517. (time ./bin/llama-perplexity --model ${model_q4_k} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log
  518. (time ./bin/llama-perplexity --model ${model_q5_k} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log
  519. (time ./bin/llama-perplexity --model ${model_q6_k} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log
  520. (time ./bin/llama-imatrix --model ${model_f16} -f ${wiki_test} -t 1 -ngl 99 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log
  521. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 10 -c 0 ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  522. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 10 -c 0 -fa ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  523. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 99 -c 0 ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  524. (time ./bin/llama-save-load-state --model ${model_q4_0} -ngl 99 -c 0 -fa ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log
  525. function check_ppl {
  526. qnt="$1"
  527. ppl=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  528. if [ $(echo "$ppl > 20.0" | bc) -eq 1 ]; then
  529. printf ' - %s @ %s (FAIL: ppl > 20.0)\n' "$qnt" "$ppl"
  530. return 20
  531. fi
  532. printf ' - %s @ %s OK\n' "$qnt" "$ppl"
  533. return 0
  534. }
  535. check_ppl "f16" "$(cat $OUT/${ci}-tg-f16.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  536. check_ppl "q8_0" "$(cat $OUT/${ci}-tg-q8_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  537. check_ppl "q4_0" "$(cat $OUT/${ci}-tg-q4_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  538. check_ppl "q4_1" "$(cat $OUT/${ci}-tg-q4_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  539. check_ppl "q5_0" "$(cat $OUT/${ci}-tg-q5_0.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  540. check_ppl "q5_1" "$(cat $OUT/${ci}-tg-q5_1.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  541. #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
  542. check_ppl "q3_k" "$(cat $OUT/${ci}-tg-q3_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  543. check_ppl "q4_k" "$(cat $OUT/${ci}-tg-q4_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  544. check_ppl "q5_k" "$(cat $OUT/${ci}-tg-q5_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  545. check_ppl "q6_k" "$(cat $OUT/${ci}-tg-q6_k.log | grep "^\[1\]")" | tee -a $OUT/${ci}-ppl.log
  546. cat $OUT/${ci}-imatrix.log | grep "Final" >> $OUT/${ci}-imatrix-sum.log
  547. set +e
  548. }
  549. function gg_sum_pythia_2_8b {
  550. gg_printf '### %s\n\n' "${ci}"
  551. gg_printf 'Pythia 2.8B:\n'
  552. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  553. gg_printf '- perplexity:\n%s\n' "$(cat $OUT/${ci}-ppl.log)"
  554. gg_printf '- imatrix:\n```\n%s\n```\n' "$(cat $OUT/${ci}-imatrix-sum.log)"
  555. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  556. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  557. gg_printf '- q4_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_0.log)"
  558. gg_printf '- q4_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_1.log)"
  559. gg_printf '- q5_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_0.log)"
  560. gg_printf '- q5_1:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_1.log)"
  561. gg_printf '- q2_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q2_k.log)"
  562. gg_printf '- q3_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q3_k.log)"
  563. gg_printf '- q4_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q4_k.log)"
  564. gg_printf '- q5_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q5_k.log)"
  565. gg_printf '- q6_k:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q6_k.log)"
  566. gg_printf '- save-load-state: \n```\n%s\n```\n' "$(cat $OUT/${ci}-save-load-state.log)"
  567. }
  568. # bge-small
  569. function gg_run_embd_bge_small {
  570. cd ${SRC}
  571. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json
  572. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer.json
  573. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer_config.json
  574. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/special_tokens_map.json
  575. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/resolve/main/pytorch_model.bin
  576. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/sentence_bert_config.json
  577. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/vocab.txt
  578. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/modules.json
  579. gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json
  580. gg_wget models-mnt/bge-small/1_Pooling https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/1_Pooling/config.json
  581. path_models="../models-mnt/bge-small"
  582. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  583. set -e
  584. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  585. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  586. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  587. model_f16="${path_models}/ggml-model-f16.gguf"
  588. model_q8_0="${path_models}/ggml-model-q8_0.gguf"
  589. ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0
  590. (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
  591. (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
  592. set +e
  593. }
  594. function gg_sum_embd_bge_small {
  595. gg_printf '### %s\n\n' "${ci}"
  596. gg_printf 'BGE Small (BERT):\n'
  597. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  598. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
  599. gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
  600. }
  601. # rerank_tiny
  602. function gg_run_rerank_tiny {
  603. cd ${SRC}
  604. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json
  605. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer.json
  606. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer_config.json
  607. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/special_tokens_map.json
  608. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/resolve/main/pytorch_model.bin
  609. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/sentence_bert_config.json
  610. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/vocab.txt
  611. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/modules.json
  612. gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json
  613. gg_wget models-mnt/rerank-tiny/1_Pooling https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/1_Pooling/config.json
  614. path_models="../models-mnt/rerank-tiny"
  615. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  616. set -e
  617. (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  618. (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
  619. python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
  620. model_f16="${path_models}/ggml-model-f16.gguf"
  621. # for this model, the SEP token is "</s>"
  622. (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
  623. # sample output
  624. # rerank score 0: 0.029
  625. # rerank score 1: 0.029
  626. # rerank score 2: 0.135
  627. # check that the score is in the range [$3, $4]
  628. function check_score {
  629. qnt="$1"
  630. score=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
  631. if [ $(echo "$score < $3" | bc) -eq 1 ] || [ $(echo "$score > $4" | bc) -eq 1 ]; then
  632. printf ' - %s @ %s (FAIL: score not in range [%s, %s])\n' "$qnt" "$score" "$3" "$4"
  633. return 20
  634. fi
  635. printf ' - %s @ %s OK\n' "$qnt" "$score"
  636. return 0
  637. }
  638. 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
  639. 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
  640. 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
  641. set +e
  642. }
  643. function gg_sum_rerank_tiny {
  644. gg_printf '### %s\n\n' "${ci}"
  645. gg_printf 'Rerank Tiny (Jina):\n'
  646. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  647. gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-rk-f16.log)"
  648. }
  649. function gg_check_build_requirements {
  650. if ! command -v cmake &> /dev/null; then
  651. gg_printf 'cmake not found, please install'
  652. fi
  653. if ! command -v make &> /dev/null; then
  654. gg_printf 'make not found, please install'
  655. fi
  656. if ! command -v ctest &> /dev/null; then
  657. gg_printf 'ctest not found, please install'
  658. fi
  659. }
  660. ## main
  661. export LLAMA_LOG_PREFIX=1
  662. export LLAMA_LOG_TIMESTAMPS=1
  663. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  664. # Create symlink: ./llama.cpp/models-mnt -> $MNT/models
  665. rm -rf ${SRC}/models-mnt
  666. mnt_models=${MNT}/models
  667. mkdir -p ${mnt_models}
  668. ln -sfn ${mnt_models} ${SRC}/models-mnt
  669. # Create a fresh python3 venv and enter it
  670. if ! python3 -m venv "$MNT/venv"; then
  671. echo "Error: Failed to create Python virtual environment at $MNT/venv."
  672. exit 1
  673. fi
  674. source "$MNT/venv/bin/activate"
  675. pip install -r ${SRC}/requirements.txt --disable-pip-version-check
  676. pip install --editable gguf-py --disable-pip-version-check
  677. fi
  678. ret=0
  679. if [ -z ${GG_BUILD_SYCL} ]; then
  680. # SYCL build breaks with debug build flags
  681. test $ret -eq 0 && gg_run ctest_debug
  682. fi
  683. test $ret -eq 0 && gg_run ctest_release
  684. if [ -z ${GG_BUILD_LOW_PERF} ]; then
  685. test $ret -eq 0 && gg_run embd_bge_small
  686. test $ret -eq 0 && gg_run rerank_tiny
  687. if [ -z ${GG_BUILD_CLOUD} ] || [ ${GG_BUILD_EXTRA_TESTS_0} ]; then
  688. if [ -z ${GG_BUILD_SYCL} ]; then
  689. test $ret -eq 0 && gg_run test_scripts_debug
  690. fi
  691. test $ret -eq 0 && gg_run test_scripts_release
  692. fi
  693. if [ -z ${GG_BUILD_VRAM_GB} ] || [ ${GG_BUILD_VRAM_GB} -ge 8 ]; then
  694. if [ -z ${GG_BUILD_CUDA} ] && [ -z ${GG_BUILD_VULKAN} ]; then
  695. test $ret -eq 0 && gg_run pythia_1_4b
  696. else
  697. test $ret -eq 0 && gg_run pythia_2_8b
  698. #test $ret -eq 0 && gg_run open_llama_7b_v2
  699. fi
  700. if [ -z ${GG_BUILD_SYCL} ]; then
  701. test $ret -eq 0 && gg_run ctest_with_model_debug
  702. fi
  703. test $ret -eq 0 && gg_run ctest_with_model_release
  704. fi
  705. fi
  706. exit $ret