char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
15d8f2d59
char/aliceai-t5-moe
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 ROCm support 14# GG_BUILD_ROCM=1 GG_BUILD_AMDGPU_TARGETS=gfx1151 bash ./ci/run.sh ./tmp/results ./tmp/mnt 15# 16# # with SYCL support 17# GG_BUILD_SYCL=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt 18# 19# # with VULKAN support 20# GG_BUILD_VULKAN=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt 21# 22# # with WebGPU support 23# GG_BUILD_WEBGPU=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt 24# 25# # with MUSA support 26# GG_BUILD_MUSA=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt 27# 28# # with KLEIDIAI support 29# GG_BUILD_KLEIDIAI=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt 30# 31# # with BLAS support 32# GG_BUILD_BLAS=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt 33# 34# with BLAS support (custom vendor) 35# GG_BUILD_BLAS=1 GG_BUILD_BLAS_VENDOR=Intel10_64lp bash ./ci/run.sh ./tmp/results ./tmp/mnt 36# 37# with OPENVINO support 38# GG_BUILD_OPENVINO=1 GG_BUILD_LOW_PERF=1 GGML_OPENVINO_DEVICE=CPU bash ./ci/run.sh ./tmp/results ./tmp/mnt 39# 40 41if [ -z" $ 2 " ];then 42echo "usage: $ 0 <output-dir> <mnt-dir>" 43exit 1 44fi 45 46mkdir -p " $ 1 " 47mkdir -p " $ 2 " 48 49OUT =$( realpath " $ 1 " ) 50MNT =$( realpath " $ 2 " ) 51 52# gpu-rocm self-hosted runner can't upload logs to blob; keep each run's logs in 53# their own dir keyed by the GitHub run id so an Actions run URL maps to its logs. 54if [ -n" ${ GG_BUILD_ROCM } " ]&& [ -n" ${ GITHUB_RUN_ID } " ];then 55OUT =" $ OUT /run- ${ GITHUB_RUN_ID } - ${ GITHUB_RUN_ATTEMPT :-1} " 56mkdir -p " $ OUT " 57echo "ci results dir: $ OUT " 58fi 59 60rm -f $ OUT /*.log 61 62sd =` dirname $ 0` 63cd $ sd /../ 64SRC =` pwd ` 65 66CMAKE_EXTRA ="-DLLAMA_FATAL_WARNINGS= ${ LLAMA_FATAL_WARNINGS :-ON} -DLLAMA_OPENSSL=OFF -DGGML_SCHED_NO_REALLOC=ON" 67CTEST_EXTRA ="" 68 69# Default to use make unless specified for compatibility 70CMAKE_GENERATOR ="Unix Makefiles" 71 72if [ ! -z" ${ GG_BUILD_NINJA } " ];then 73CMAKE_GENERATOR ="Ninja" 74fi 75 76if [ ! -z${ GG_BUILD_METAL } ];then 77CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_METAL=ON" 78else 79CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_METAL=OFF" 80fi 81 82if [ ! -z${ GG_BUILD_CUDA } ];then 83# TODO: Remove GGML_CUDA_CUB_3DOT2 flag once CCCL 3.2 is bundled within CTK and that CTK version is used in this project 84CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_CUDA=ON -DGGML_CUDA_CUB_3DOT2=ON" 85 86if command -v nvidia-smi> /dev/null2 >&1;then 87CUDA_ARCH =$( nvidia-smi --query-gpu=compute_cap --format=csv,noheader,nounits 2 > /dev/null | head -1 | tr -d '.' ) 88if [[ -n" $ CUDA_ARCH " && " $ CUDA_ARCH " =~ ^[0-9]+$ ]];then 89CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DCMAKE_CUDA_ARCHITECTURES= ${ CUDA_ARCH } " 90else 91echo "Warning: Using fallback CUDA architectures" 92CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DCMAKE_CUDA_ARCHITECTURES=61;70;75;80;86;89" 93fi 94else 95echo "Error: nvidia-smi not found, cannot build with CUDA" 96exit 1 97fi 98fi 99 100if [ ! -z${ GG_BUILD_ROCM } ];then 101CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DCMAKE_HIP_COMPILER= $( hipconfig -l ) /clang -DGGML_HIP=ON" 102if [ -z${ GG_BUILD_AMDGPU_TARGETS } ];then 103echo "Missing GG_BUILD_AMDGPU_TARGETS, please set it to your GPU architecture (e.g. gfx90a, gfx1100, etc.)" 104exit 1 105fi 106 107CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGPU_TARGETS= ${ GG_BUILD_AMDGPU_TARGETS } " 108fi 109 110if [ ! -z${ GG_BUILD_SYCL } ];then 111if [ -z${ ONEAPI_ROOT } ];then 112echo "Not detected ONEAPI_ROOT, please install oneAPI base toolkit and enable it by:" 113echo "source /opt/intel/oneapi/setvars.sh" 114exit 1 115fi 116# Use only main GPU 117export ONEAPI_DEVICE_SELECTOR ="level_zero:0" 118# Enable sysman for correct memory reporting 119export ZES_ENABLE_SYSMAN =1 120# to circumvent precision issues on CPY operations 121export SYCL_PROGRAM_COMPILE_OPTIONS ="-cl-fp32-correctly-rounded-divide-sqrt" 122CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_SYCL=1 -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON" 123fi 124 125if [ ! -z${ GG_BUILD_VULKAN } ];then 126CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_VULKAN=1" 127 128if [[" $ OSTYPE " =="darwin" * ]];then 129MACOS_RUNNER_CUSTOM_VULKAN_CMAKE_LOCATION ="/usr/local/lib/cmake/vulkan" 130MACOS_RUNNER_CUSTOM_SPIRV_HEADERS_LOCATION =" ${ MACOS_RUNNER_CUSTOM_VULKAN_CMAKE_LOCATION } /SPIRV-Headers/SPIRV-HeadersConfig.cmake" 131if [[ -f" ${ MACOS_RUNNER_CUSTOM_SPIRV_HEADERS_LOCATION } " || -h" ${ MACOS_RUNNER_CUSTOM_SPIRV_HEADERS_LOCATION } " ]];then 132CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DSPIRV-Headers_DIR= ${ MACOS_RUNNER_CUSTOM_VULKAN_CMAKE_LOCATION } /SPIRV-Headers" 133fi 134fi 135 136# Build shared libs on Windows 137# to reduce binary size and avoid errors in library loading unit tests 138if uname -s | grep -qi nt;then 139CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DBUILD_SHARED_LIBS=ON" 140fi 141fi 142 143if [ ! -z${ GG_BUILD_WEBGPU } ];then 144CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_WEBGPU=1" 145 146if [ ! -z" ${ GG_BUILD_WEBGPU_DAWN_PREFIX } " ];then 147if [ -z" ${ CMAKE_PREFIX_PATH } " ];then 148export CMAKE_PREFIX_PATH =" ${ GG_BUILD_WEBGPU_DAWN_PREFIX } " 149else 150export CMAKE_PREFIX_PATH =" ${ GG_BUILD_WEBGPU_DAWN_PREFIX } : ${ CMAKE_PREFIX_PATH } " 151fi 152fi 153 154# For some systems, Dawn_DIR needs to be set explicitly, e.g., the lib64 path 155if [ ! -z" ${ GG_BUILD_WEBGPU_DAWN_DIR } " ];then 156CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DDawn_DIR= ${ GG_BUILD_WEBGPU_DAWN_DIR } " 157fi 158fi 159 160if [ ! -z${ GG_BUILD_MUSA } ];then 161# Use qy1 by default (MTT S80) 162MUSA_ARCH =${ MUSA_ARCH :-21} 163CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_MUSA=ON -DMUSA_ARCHITECTURES= ${ MUSA_ARCH } " 164fi 165 166if [ ! -z${ GG_BUILD_NO_SVE } ];then 167# arm 9 and newer enables sve by default, adjust these flags depending on the cpu used 168CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_NATIVE=OFF -DGGML_CPU_ARM_ARCH=armv8.5-a+fp16+i8mm" 169fi 170 171if [ -n" ${ GG_BUILD_KLEIDIAI } " ];then 172echo ">>===== Enabling KleidiAI support" 173CMAKE_EXTRA =" ${ CMAKE_EXTRA :+ $ CMAKE_EXTRA } -DGGML_CPU_KLEIDIAI=ON" 174fi 175 176if [ ! -z${ GG_BUILD_BLAS } ];then 177CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_BLAS=ON -DGGML_BLAS_VENDOR= ${ GG_BUILD_BLAS_VENDOR :-OpenBLAS} " 178else 179CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_BLAS=OFF" 180fi 181 182if [ ! -z${ GG_BUILD_OPENVINO } ];then 183if [ -z${ OpenVINO_DIR } ];then 184echo "OpenVINO_DIR not found, please install OpenVINO via archives and enable it by:" 185echo "source /opt/intel/openvino/setupvars.sh" 186exit 1 187fi 188CMAKE_EXTRA =" ${ CMAKE_EXTRA } -DGGML_OPENVINO=ON" 189 190# TODO: fix failing tests on OpenVINO backend 191CTEST_EXTRA ="-E test-llama-archs|^test-recurrent-state-|test-save-load-state" 192fi 193 194## helpers 195 196# download a file if it does not exist or if it is outdated 197function gg_wget { 198 localout =$ 1 199 localurl =$ 2 200 201 localcwd =` pwd ` 202 203mkdir -p $ out 204cd $ out 205 206# should not re-download if file is the same 207wget -nv -c -N $ url 208 209cd $ cwd 210} 211 212function gg_run { 213ci =$ 1 214 215set -o pipefail 216set -x 217 218gg_run_ $ ci | tee $ OUT /$ ci.log 219cur =$ ? 220 221set +x 222set +o pipefail 223 224ret =$((ret | cur )) 225} 226 227## ci 228 229# ctest_debug 230 231function gg_run_ctest_debug { 232cd ${ SRC } 233 234rm -rf build-ci-debug&& mkdir build-ci-debug&& cd build-ci-debug 235 236set -e 237 238# Check required binaries are installed 239gg_check_build_requirements 240 241 (cmake -G " ${ CMAKE_GENERATOR } " -DCMAKE_BUILD_TYPE=Debug ${ CMAKE_EXTRA } .. )2 >&1| tee -a $ OUT /${ ci } -cmake.log 242 (time cmake--build .--config Debug-j $( nproc ) )2 >&1| tee -a $ OUT /${ ci } -make.log 243 244 (time ctest-C Debug--output-on-failure -L main-E "test-opt|test-llama-archs" ${ CTEST_EXTRA } )2 >&1| tee -a $ OUT /${ ci } -ctest.log 245 246set +e 247} 248 249# ctest_release 250 251function gg_run_ctest_release { 252cd ${ SRC } 253 254rm -rf build-ci-release&& mkdir build-ci-release&& cd build-ci-release 255 256set -e 257 258# Check required binaries are installed 259gg_check_build_requirements 260 261 (cmake -G " ${ CMAKE_GENERATOR } " -DCMAKE_BUILD_TYPE=Release ${ CMAKE_EXTRA } .. )2 >&1| tee -a $ OUT /${ ci } -cmake.log 262 (time cmake--build .--config Release-j $( nproc ) )2 >&1| tee -a $ OUT /${ ci } -make.log 263 264if [ -z${ GG_BUILD_LOW_PERF } ];then 265 (time ctest-C Release--output-on-failure -L 'main|python' ${ CTEST_EXTRA } )2 >&1| tee -a $ OUT /${ ci } -ctest.log 266else 267 (time ctest-C Release--output-on-failure -L main-E test-opt${ CTEST_EXTRA } )2 >&1| tee -a $ OUT /${ ci } -ctest.log 268fi 269 270set +e 271} 272 273# test_llama_archs_tensor_split 274 275function gg_run_test_llama_archs_tensor_split { 276cd ${ SRC } 277 278set -e 279 280if [ ! -z${ GG_BUILD_CUDA } ];then 281GGML_CUDA_DEVICES =1./build-ci-release/bin/test-llama-archs -s 12 >&1 282GGML_CUDA_DEVICES =2./build-ci-release/bin/test-llama-archs -s 12 >&1 283GGML_CUDA_DEVICES =3./build-ci-release/bin/test-llama-archs -s 12 >&1 284GGML_CUDA_DEVICES =4./build-ci-release/bin/test-llama-archs -s 12 >&1 285fi 286 287if [ ! -z${ GG_BUILD_METAL } ];then 288GGML_METAL_DEVICES =1./build-ci-release/bin/test-llama-archs -s 12 >&1 289GGML_METAL_DEVICES =2./build-ci-release/bin/test-llama-archs -s 12 >&1 290GGML_METAL_DEVICES =3./build-ci-release/bin/test-llama-archs -s 12 >&1 291GGML_METAL_DEVICES =4./build-ci-release/bin/test-llama-archs -s 12 >&1 292fi 293 294set +e 295} 296 297# test_llama_archs_models 298 299function gg_run_test_llama_archs_models { 300cd ${ SRC } 301 302set -e 303 304# TODO: fix and re-enable `test-llama-archs` on OpenVINO 305# TODO: the `test-llama-archs` currently does not build on Windows, so we check if the binary exists 306if [ -z${ GG_BUILD_OPENVINO } ]&& [ -f ./build-ci-release/bin/test-llama-archs ];then 307rm -rf build-ci-models&& mkdir -p build-ci-models 308 309# generate the dummy models used by the model-dependent tests 310./build-ci-release/bin/test-llama-archs -o build-ci-models2 >&1 311fi 312 313set +e 314} 315 316# test_scripts 317 318function gg_run_test_scripts { 319cd ${ SRC } 320 321set -e 322 323 (cd ./tools/gguf-split&& time bash tests.sh" $ SRC /build-ci-release/bin" " $ MNT /models" )2 >&1| tee -a $ OUT /${ ci } -scripts.log 324 (cd ./tools/quantize&& time bash tests.sh" $ SRC /build-ci-release/bin" " $ MNT /models" )2 >&1| tee -a $ OUT /${ ci } -scripts.log 325 326set +e 327} 328 329function gg_get_model { 330#local gguf_0="$MNT/models/qwen3/0.6B/ggml-model-f16.gguf" 331 localgguf_0 =" $ MNT /models/qwen3/0.6B/ggml-model-q4_0.gguf" 332if [[ -s$ gguf_0 ]];then 333echo -n " $ gguf_0 " 334else 335echo >&2"No model found. Can't run gg_run_ctest_with_model." 336exit 1 337fi 338} 339 340function gg_run_ctest_with_model_debug { 341cd ${ SRC } 342 343 localmodel ;model =$( gg_get_model ) 344cd build-ci-debug 345set -e 346 347 (LLAMACPP_TEST_MODELFILE =" $ model " time ctest-C Debug--output-on-failure -L model)2 >&1| tee -a $ OUT /${ ci } -ctest.log 348 349set +e 350cd .. 351} 352 353function gg_run_ctest_with_model_release { 354cd ${ SRC } 355 356 localmodel ;model =$( gg_get_model ) 357cd build-ci-release 358set -e 359 360 (LLAMACPP_TEST_MODELFILE =" $ model " time ctest-C Release--output-on-failure -L model)2 >&1| tee -a $ OUT /${ ci } -ctest.log 361 362# test memory leaks 363#if [[ ! -z ${GG_BUILD_METAL} ]]; then 364# # TODO: this hangs for some reason ... 365# (time leaks -quiet -atExit -- ./bin/test-thread-safety -m $model --parallel 2 -t 2 -p "hello") 2>&1 | tee -a $OUT/${ci}-leaks.log 366#fi 367 368set +e 369cd .. 370} 371 372# qwen3_0_6b 373 374function gg_run_qwen3_0_6b { 375cd ${ SRC } 376 377gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/config.json 378gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/tokenizer.json 379gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/tokenizer_config.json 380#gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/special_tokens_map.json 381gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/resolve/main/model.safetensors 382 383 384gg_wget models-mnt/wikitext/ https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip 385unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip-d models-mnt/wikitext/ 386 387path_models ="../models-mnt/qwen3/0.6B" 388path_wiki ="../models-mnt/wikitext/wikitext-2-raw" 389 390rm -rf build-ci-release&& mkdir build-ci-release&& cd build-ci-release 391 392set -e 393 394 (cmake -G " ${ CMAKE_GENERATOR } " -DCMAKE_BUILD_TYPE=Release ${ CMAKE_EXTRA } .. )2 >&1| tee -a $ OUT /${ ci } -cmake.log 395 (time cmake--build .--config Release-j $( nproc ) )2 >&1| tee -a $ OUT /${ ci } -make.log 396 397python3 ../convert_hf_to_gguf.py${ path_models } --outfile ${ path_models } /ggml-model-f16.gguf--outtype f16 398python3 ../convert_hf_to_gguf.py${ path_models } --outfile ${ path_models } /ggml-model-bf16.gguf--outtype bf16 399 400model_f16 =" ${ path_models } /ggml-model-f16.gguf" 401model_bf16 =" ${ path_models } /ggml-model-bf16.gguf" 402model_q8_0 =" ${ path_models } /ggml-model-q8_0.gguf" 403model_q4_0 =" ${ path_models } /ggml-model-q4_0.gguf" 404model_q4_1 =" ${ path_models } /ggml-model-q4_1.gguf" 405model_q5_0 =" ${ path_models } /ggml-model-q5_0.gguf" 406model_q5_1 =" ${ path_models } /ggml-model-q5_1.gguf" 407model_q2_k =" ${ path_models } /ggml-model-q2_k.gguf" 408model_q3_k =" ${ path_models } /ggml-model-q3_k.gguf" 409model_q4_k =" ${ path_models } /ggml-model-q4_k.gguf" 410model_q5_k =" ${ path_models } /ggml-model-q5_k.gguf" 411model_q6_k =" ${ path_models } /ggml-model-q6_k.gguf" 412 413wiki_test =" ${ path_wiki } /wiki.test.raw" 414 415./bin/llama-quantize ${ model_bf16 } ${ model_q8_0 } q8_0$( nproc ) 416./bin/llama-quantize ${ model_bf16 } ${ model_q4_0 } q4_0$( nproc ) 417./bin/llama-quantize ${ model_bf16 } ${ model_q4_1 } q4_1$( nproc ) 418./bin/llama-quantize ${ model_bf16 } ${ model_q5_0 } q5_0$( nproc ) 419./bin/llama-quantize ${ model_bf16 } ${ model_q5_1 } q5_1$( nproc ) 420./bin/llama-quantize ${ model_bf16 } ${ model_q2_k } q2_k$( nproc ) 421./bin/llama-quantize ${ model_bf16 } ${ model_q3_k } q3_k$( nproc ) 422./bin/llama-quantize ${ model_bf16 } ${ model_q4_k } q4_k$( nproc ) 423./bin/llama-quantize ${ model_bf16 } ${ model_q5_k } q5_k$( nproc ) 424./bin/llama-quantize ${ model_bf16 } ${ model_q6_k } q6_k$( nproc ) 425 426 (time ./bin/llama-fit-params--model ${ model_f16 } 2 >&1| tee -a $ OUT /${ ci } -fp-f16.log) 427 428 (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 429 (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 430 (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 431 (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 432 (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 433 (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 434 (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 435 (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 436 (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 437 (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 438 (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 439 (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 440 441 (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 442if [ -z${ GG_BUILD_NO_BF16 } ];then 443 (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 444fi 445 (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 446 (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 447 (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 448 (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 449 (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 450 (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 451 (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 452 (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 453 (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 454 (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 455 456 (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 457 458 (time ./bin/test-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 459 (time ./bin/test-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 460 (time ./bin/test-save-load-state--model ${ model_q4_0 } -ngl 99-c 1024-fa off )2 >&1| tee -a $ OUT /${ ci } -save-load-state.log 461 (time ./bin/test-save-load-state--model ${ model_q4_0 } -ngl 99-c 1024-fa on )2 >&1| tee -a $ OUT /${ ci } -save-load-state.log 462 463function check_ppl { 464qnt =" $ 1 " 465ppl =$( echo " $ 2 " | grep -oE "[0-9]+\.[0-9]+" | tail -n 1) 466 467if [$( echo " $ ppl > 20.0" | bc ) -eq 1 ];then 468printf ' - %s @ %s (FAIL: ppl > 20.0)\n' " $ qnt " " $ ppl " 469return 20 470fi 471 472printf ' - %s @ %s OK\n' " $ qnt " " $ ppl " 473return 0 474 } 475 476check_ppl "f16" " $( cat $ OUT /${ ci }-tg-f16.log | grep "^\[1\]" ) " 477if [ -z${ GG_BUILD_NO_BF16 } ];then 478check_ppl "bf16" " $( cat $ OUT /${ ci }-tg-bf16.log | grep "^\[1\]" ) " 479fi 480check_ppl "q8_0" " $( cat $ OUT /${ ci }-tg-q8_0.log | grep "^\[1\]" ) " 481check_ppl "q4_0" " $( cat $ OUT /${ ci }-tg-q4_0.log | grep "^\[1\]" ) " 482check_ppl "q4_1" " $( cat $ OUT /${ ci }-tg-q4_1.log | grep "^\[1\]" ) " 483check_ppl "q5_0" " $( cat $ OUT /${ ci }-tg-q5_0.log | grep "^\[1\]" ) " 484check_ppl "q5_1" " $( cat $ OUT /${ ci }-tg-q5_1.log | grep "^\[1\]" ) " 485#check_ppl "q2_k" "$(cat $OUT/${ci}-tg-q2_k.log | grep "^\[1\]")" # note: ppl > 20.0 for this quant and model 486check_ppl "q3_k" " $( cat $ OUT /${ ci }-tg-q3_k.log | grep "^\[1\]" ) " 487check_ppl "q4_k" " $( cat $ OUT /${ ci }-tg-q4_k.log | grep "^\[1\]" ) " 488check_ppl "q5_k" " $( cat $ OUT /${ ci }-tg-q5_k.log | grep "^\[1\]" ) " 489check_ppl "q6_k" " $( cat $ OUT /${ ci }-tg-q6_k.log | grep "^\[1\]" ) " 490 491set +e 492} 493 494# bge-small 495 496function gg_run_embd_bge_small { 497cd ${ SRC } 498 499gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json 500gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer.json 501gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer_config.json 502gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/special_tokens_map.json 503gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/resolve/main/pytorch_model.bin 504gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/sentence_bert_config.json 505gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/vocab.txt 506gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/modules.json 507gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json 508 509gg_wget models-mnt/bge-small/1_Pooling https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/1_Pooling/config.json 510 511path_models ="../models-mnt/bge-small" 512 513rm -rf build-ci-release&& mkdir build-ci-release&& cd build-ci-release 514 515set -e 516 517 (cmake -G " ${ CMAKE_GENERATOR } " -DCMAKE_BUILD_TYPE=Release ${ CMAKE_EXTRA } .. )2 >&1| tee -a $ OUT /${ ci } -cmake.log 518 (time cmake--build .--config Release-j $( nproc ) )2 >&1| tee -a $ OUT /${ ci } -make.log 519 520python3 ../convert_hf_to_gguf.py${ path_models } --outfile ${ path_models } /ggml-model-f16.gguf 521 522model_f16 =" ${ path_models } /ggml-model-f16.gguf" 523model_q8_0 =" ${ path_models } /ggml-model-q8_0.gguf" 524 525./bin/llama-quantize ${ model_f16 } ${ model_q8_0 } q8_0 526 527 (time ./bin/llama-fit-params--model ${ model_f16 } 2 >&1| tee -a $ OUT /${ ci } -fp-f16.log) 528 529 (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 530 (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 531 532set +e 533} 534 535# rerank_tiny 536 537function gg_run_rerank_tiny { 538cd ${ SRC } 539 540gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json 541gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer.json 542gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer_config.json 543gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/special_tokens_map.json 544gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/resolve/main/pytorch_model.bin 545gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/vocab.json 546 547path_models ="../models-mnt/rerank-tiny" 548 549rm -rf build-ci-release&& mkdir build-ci-release&& cd build-ci-release 550 551set -e 552 553 (cmake -G " ${ CMAKE_GENERATOR } " -DCMAKE_BUILD_TYPE=Release ${ CMAKE_EXTRA } .. )2 >&1| tee -a $ OUT /${ ci } -cmake.log 554 (time cmake--build .--config Release-j $( nproc ) )2 >&1| tee -a $ OUT /${ ci } -make.log 555 556python3 ../convert_hf_to_gguf.py${ path_models } --outfile ${ path_models } /ggml-model-f16.gguf 557 558model_f16 =" ${ path_models } /ggml-model-f16.gguf" 559 560 (time ./bin/llama-fit-params--model ${ model_f16 } 2 >&1| tee -a $ OUT /${ ci } -fp-f16.log) 561 562# for this model, the SEP token is "</s>" 563 (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 564 565# sample output 566# rerank score 0: 0.029 567# rerank score 1: 0.029 568# rerank score 2: 0.135 569 570# check that the score is in the range [$3, $4] 571function check_score { 572qnt =" $ 1 " 573score =$( echo " $ 2 " | grep -oE "[0-9]+\.[0-9]+" | tail -n 1) 574 575if [$( echo " $ score < $ 3 " | bc ) -eq 1 ] || [$( echo " $ score > $ 4 " | bc ) -eq 1 ];then 576printf ' - %s @ %s (FAIL: score not in range [%s, %s])\n' " $ qnt " " $ score " " $ 3 " " $ 4 " 577return 20 578fi 579 580printf ' - %s @ %s OK\n' " $ qnt " " $ score " 581return 0 582 } 583 584check_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 585check_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 586check_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 587 588set +e 589} 590 591function gg_check_build_requirements { 592if !command -v git &> /dev/null;then 593echo 'git not found, please install' 594exit 1 595fi 596 597if !command -v git-lfs &> /dev/null;then 598echo 'git-lfs not found, please install' 599exit 1 600fi 601 602if !git config--get filter.lfs.clean &> /dev/null;then 603echo 'git-lfs not initialized, please run `git lfs install`' 604exit 1 605fi 606 607if !command -v wget &> /dev/null;then 608echo 'wget not found, please install' 609exit 1 610fi 611 612if !command -v python3 &> /dev/null;then 613echo 'python3 not found, please install' 614exit 1 615fi 616 617if !command -v pip3 &> /dev/null;then 618echo 'pip3 not found, please install' 619exit 1 620fi 621 622if !python3 -m ensurepip--help &> /dev/null;then 623echo 'ensurepip not found, please install python3-venv package' 624exit 1 625fi 626 627if !command -v cmake &> /dev/null;then 628echo 'cmake not found, please install' 629exit 1 630fi 631 632if !command -v ccache &> /dev/null;then 633echo 'ccache not found, please consider installing for faster builds' 634fi 635 636if !command -v ctest &> /dev/null;then 637echo 'ctest not found, please install' 638exit 1 639fi 640 641if !command -v unzip &> /dev/null;then 642echo 'unzip not found, please install' 643exit 1 644fi 645} 646 647function gg_run_test_backend_ops { 648cd ${ SRC } 649 650cd build-ci-release 651 652set -e 653 654 localn_jobs =$( nproc ) 655if [" ${ n_jobs } " -gt 2 ];then 656n_jobs =2 657fi 658 localargs_extra ="-j ${ n_jobs } " 659 660# TODO: fix multi-threaded for ROCm 661# https://github.com/ggml-org/llama.cpp/actions/runs/34576278519/job/103297889044?pr=28740#step:3:4865 662if [ ! -z${ GG_BUILD_ROCM } ];then 663args_extra ="" 664fi 665 666# TODO: MoltenVK bug? 667# https://github.com/ggml-org/llama.cpp/actions/runs/34611260059/job/103302413736?pr=28740#step:3:5897 668if [ ! -z" ${ GG_BUILD_VULKAN } " ]&& [" $( uname -s ) " ="Darwin" ];then 669args_extra ="" 670fi 671 672# TODO: reduce the test-backend-ops timeout to 1800s 673if [ ! -z${ GG_BUILD_HIGH_PERF } ];then 674 (time timeout 3600 ./bin/test-backend-ops${ args_extra } -b CPU)2 >&1| tee -a $ OUT /${ ci } -test-backend-ops.log 675else 676 (time timeout 3600 ./bin/test-backend-ops${ args_extra } )2 >&1| tee -a $ OUT /${ ci } -test-backend-ops.log 677fi 678 679set +e 680} 681 682## main 683 684export LLAMA_ARG_LOG_PREFIX =1 685export LLAMA_ARG_LOG_TIMESTAMPS =1 686 687if [ -z${ GG_BUILD_LOW_PERF } ];then 688# Create symlink: ./llama.cpp/models-mnt -> $MNT/models 689rm -rf ${ SRC } /models-mnt 690mnt_models =${ MNT } /models 691mkdir -p ${ mnt_models } 692ln -sfn ${ mnt_models } ${ SRC } /models-mnt 693 694# Create a fresh python3 venv and enter it 695if !python3 -m venv" $ MNT /venv" ;then 696echo "Error: Failed to create Python virtual environment at $ MNT /venv." 697exit 1 698fi 699source " $ MNT /venv/bin/activate" 700 701pip install-r ${ SRC } /requirements.txt--disable-pip-version-check 702pip install--editable gguf-py--disable-pip-version-check 703fi 704 705ret =0 706 707test $ ret -eq 0&& gg_run ctest_debug 708test $ ret -eq 0&& gg_run ctest_release 709 710test $ ret -eq 0&& gg_run test_backend_ops 711 712test $ ret -eq 0&& gg_run test_llama_archs_models 713test $ ret -eq 0&& gg_run test_llama_archs_tensor_split 714 715if [ -z${ GG_BUILD_LOW_PERF } ];then 716test $ ret -eq 0&& gg_run embd_bge_small 717test $ ret -eq 0&& gg_run rerank_tiny 718 719if [ -z${ GG_BUILD_CLOUD } ] || [${ GG_BUILD_EXTRA_TESTS_0 } ];then 720test $ ret -eq 0&& gg_run test_scripts 721fi 722 723test $ ret -eq 0&& gg_run qwen3_0_6b 724 725test $ ret -eq 0&& gg_run ctest_with_model_debug 726test $ ret -eq 0&& gg_run ctest_with_model_release 727fi 728 729exit $ ret