2025-06-30 10:17:18 +02:00
#!/usr/bin/env bash
2023-07-22 11:48:22 +03:00
#
# sample usage:
#
# mkdir tmp
#
# # CPU-only build
# bash ./ci/run.sh ./tmp/results ./tmp/mnt
#
# # with CUDA support
# GG_BUILD_CUDA=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt
#
2024-01-28 21:26:23 +05:30
# # with SYCL support
# GG_BUILD_SYCL=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt
#
2024-08-26 12:19:39 +03:00
# # with VULKAN support
# GG_BUILD_VULKAN=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt
#
2025-07-16 08:18:51 -07:00
# # with WebGPU support
# GG_BUILD_WEBGPU=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt
#
2025-03-25 15:45:08 +08:00
# # with MUSA support
# GG_BUILD_MUSA=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt
#
2023-07-18 14:24:43 +03:00
if [ -z " $2 " ] ; then
echo "usage: $0 <output-dir> <mnt-dir>"
exit 1
fi
mkdir -p " $1 "
mkdir -p " $2 "
OUT = $( realpath " $1 " )
MNT = $( realpath " $2 " )
2025-10-02 10:35:43 +03:00
rm -f $OUT /*.log
rm -f $OUT /*.exit
rm -f $OUT /*.md
2023-07-18 14:24:43 +03:00
sd = ` dirname $0 `
cd $sd /../
SRC = ` pwd `
2025-06-16 08:11:43 -07:00
CMAKE_EXTRA = "-DLLAMA_FATAL_WARNINGS=ON -DLLAMA_CURL=ON"
2024-01-02 10:57:44 +02:00
if [ ! -z ${ GG_BUILD_METAL } ] ; then
2025-09-17 20:38:12 +03:00
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DGGML_METAL=ON"
2024-01-02 10:57:44 +02:00
fi
2024-01-17 18:54:56 +02:00
if [ ! -z ${ GG_BUILD_CUDA } ] ; then
2025-06-05 06:25:29 -07:00
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DGGML_CUDA=ON"
if command -v nvidia-smi >/dev/null 2>& 1; then
CUDA_ARCH = $( nvidia-smi --query-gpu= compute_cap --format= csv,noheader,nounits 2>/dev/null | head -1 | tr -d '.' )
if [[ -n " $CUDA_ARCH " && " $CUDA_ARCH " = ~ ^[ 0-9] +$ ]] ; then
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DCMAKE_CUDA_ARCHITECTURES= ${ CUDA_ARCH } "
else
echo "Warning: Using fallback CUDA architectures"
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DCMAKE_CUDA_ARCHITECTURES=61;70;75;80;86;89"
fi
else
echo "Error: nvidia-smi not found, cannot build with CUDA"
exit 1
fi
2024-01-17 18:54:56 +02:00
fi
2025-09-21 16:50:45 +03:00
if [ ! -z ${ GG_BUILD_ROCM } ] ; then
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DGGML_HIP=ON"
if [ -z ${ GG_BUILD_AMDGPU_TARGETS } ] ; then
echo "Missing GG_BUILD_AMDGPU_TARGETS, please set it to your GPU architecture (e.g. gfx90a, gfx1100, etc.)"
exit 1
fi
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DAMDGPU_TARGETS= ${ GG_BUILD_AMDGPU_TARGETS } "
fi
2024-01-28 21:26:23 +05:30
if [ ! -z ${ GG_BUILD_SYCL } ] ; then
if [ -z ${ ONEAPI_ROOT } ] ; then
2024-03-06 12:08:32 +08:00
echo "Not detected ONEAPI_ROOT, please install oneAPI base toolkit and enable it by:"
echo "source /opt/intel/oneapi/setvars.sh"
2024-01-28 21:26:23 +05:30
exit 1
fi
2025-03-24 23:05:38 +05:30
# Use only main GPU
export ONEAPI_DEVICE_SELECTOR = "level_zero:0"
# Enable sysman for correct memory reporting
export ZES_ENABLE_SYSMAN = 1
2025-04-03 13:12:39 +01:00
# to circumvent precision issues on CPY operations
export SYCL_PROGRAM_COMPILE_OPTIONS = "-cl-fp32-correctly-rounded-divide-sqrt"
2024-10-24 21:23:33 +03:00
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DGGML_SYCL=1 -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON"
2024-01-28 21:26:23 +05:30
fi
2024-08-26 12:19:39 +03:00
if [ ! -z ${ GG_BUILD_VULKAN } ] ; then
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DGGML_VULKAN=1"
2025-09-23 13:44:25 +03:00
# if on Mac, disable METAL
if [[ " $OSTYPE " == "darwin" * ]] ; then
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DGGML_METAL=OFF -DGGML_BLAS=OFF"
fi
2024-08-26 12:19:39 +03:00
fi
2025-03-25 15:45:08 +08:00
2025-07-16 08:18:51 -07:00
if [ ! -z ${ GG_BUILD_WEBGPU } ] ; then
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DGGML_WEBGPU=1"
fi
2025-03-25 15:45:08 +08:00
if [ ! -z ${ GG_BUILD_MUSA } ] ; then
# Use qy1 by default (MTT S80)
MUSA_ARCH = ${ MUSA_ARCH :- 21 }
2025-03-30 16:59:38 +08:00
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DGGML_MUSA=ON -DMUSA_ARCHITECTURES= ${ MUSA_ARCH } "
2025-03-25 15:45:08 +08:00
fi
2025-09-25 05:06:06 +00:00
if [ ! -z ${ GG_BUILD_NO_SVE } ] ; then
# arm 9 and newer enables sve by default, adjust these flags depending on the cpu used
CMAKE_EXTRA = " ${ CMAKE_EXTRA } -DGGML_NATIVE=OFF -DGGML_CPU_ARM_ARCH=armv8.5-a+fp16+i8mm"
fi
2025-09-29 17:51:48 +03:00
2023-07-18 14:24:43 +03:00
## helpers
# download a file if it does not exist or if it is outdated
function gg_wget {
local out = $1
local url = $2
local cwd = ` pwd `
mkdir -p $out
cd $out
# should not re-download if file is the same
2025-08-21 13:42:55 +03:00
wget -nv -c -N $url
2023-07-18 14:24:43 +03:00
cd $cwd
}
function gg_printf {
printf -- " $@ " >> $OUT /README.md
}
function gg_run {
ci = $1
set -o pipefail
set -x
gg_run_$ci | tee $OUT /$ci .log
cur = $?
echo " $cur " > $OUT /$ci .exit
set +x
set +o pipefail
gg_sum_$ci
ret = $(( ret | cur))
}
## ci
# ctest_debug
function gg_run_ctest_debug {
cd ${ SRC }
rm -rf build-ci-debug && mkdir build-ci-debug && cd build-ci-debug
set -e
2024-07-07 15:59:14 +01:00
# Check cmake, make and ctest are installed
gg_check_build_requirements
2024-01-02 10:57:44 +02:00
( time cmake -DCMAKE_BUILD_TYPE= Debug ${ CMAKE_EXTRA } .. ) 2>& 1 | tee -a $OUT /${ ci } -cmake.log
2024-08-26 11:03:30 +02:00
( time make -j$( nproc) ) 2>& 1 | tee -a $OUT /${ ci } -make.log
2023-07-18 14:24:43 +03:00
2025-09-21 16:50:45 +03:00
( time ctest --output-on-failure -L main -E "test-opt|test-backend-ops" ) 2>& 1 | tee -a $OUT /${ ci } -ctest.log
2023-07-18 14:24:43 +03:00
set +e
}
function gg_sum_ctest_debug {
gg_printf '### %s\n\n' " ${ ci } "
gg_printf 'Runs ctest in debug mode\n'
gg_printf '- status: %s\n' " $( cat $OUT /${ ci } .exit) "
gg_printf '```\n'
gg_printf '%s\n' " $( cat $OUT /${ ci } -ctest.log) "
gg_printf '```\n'
gg_printf '\n'
}
# ctest_release
function gg_run_ctest_release {
cd ${ SRC }
rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
set -e
2024-07-07 15:59:14 +01:00
# Check cmake, make and ctest are installed
gg_check_build_requirements
2024-01-02 10:57:44 +02:00
( time cmake -DCMAKE_BUILD_TYPE= Release ${ CMAKE_EXTRA } .. ) 2>& 1 | tee -a $OUT /${ ci } -cmake.log
2024-08-26 11:03:30 +02:00
( time make -j$( nproc) ) 2>& 1 | tee -a $OUT /${ ci } -make.log
2023-07-18 14:24:43 +03:00
2023-07-22 11:48:22 +03:00
if [ -z ${ GG_BUILD_LOW_PERF } ] ; then
2024-01-26 07:18:00 -05:00
( time ctest --output-on-failure -L main ) 2>& 1 | tee -a $OUT /${ ci } -ctest.log
2023-07-18 14:24:43 +03:00
else
2024-01-26 07:18:00 -05:00
( time ctest --output-on-failure -L main -E test-opt ) 2>& 1 | tee -a $OUT /${ ci } -ctest.log
2023-07-18 14:24:43 +03:00
fi
set +e
}
function gg_sum_ctest_release {
gg_printf '### %s\n\n' " ${ ci } "
gg_printf 'Runs ctest in release mode\n'
gg_printf '- status: %s\n' " $( cat $OUT /${ ci } .exit) "
gg_printf '```\n'
gg_printf '%s\n' " $( cat $OUT /${ ci } -ctest.log) "
gg_printf '```\n'
}
2025-09-22 09:11:39 +03:00
# test_scripts
2024-04-14 13:12:59 +02:00
2025-09-22 09:11:39 +03:00
function gg_run_test_scripts {
2024-04-14 13:12:59 +02:00
cd ${ SRC }
set -e
2025-05-02 20:27:13 +02:00
( cd ./tools/gguf-split && time bash tests.sh " $SRC /build-ci-release/bin" " $MNT /models" ) 2>& 1 | tee -a $OUT /${ ci } -scripts.log
( cd ./tools/quantize && time bash tests.sh " $SRC /build-ci-release/bin" " $MNT /models" ) 2>& 1 | tee -a $OUT /${ ci } -scripts.log
2024-04-14 13:12:59 +02:00
set +e
}
2025-09-22 09:11:39 +03:00
function gg_sum_test_scripts {
2024-04-14 13:12:59 +02:00
gg_printf '### %s\n\n' " ${ ci } "
2025-09-22 09:11:39 +03:00
gg_printf 'Runs test scripts\n'
2024-04-14 13:12:59 +02:00
gg_printf '- status: %s\n' " $( cat $OUT /${ ci } .exit) "
gg_printf '```\n'
gg_printf '%s\n' " $( cat $OUT /${ ci } -scripts.log) "
gg_printf '```\n'
gg_printf '\n'
}
2024-01-26 07:18:00 -05:00
function gg_get_model {
2025-09-22 08:31:40 +03:00
local gguf_0 = " $MNT /models/qwen3/0.6B/ggml-model-f16.gguf"
2024-05-23 15:28:14 +03:00
if [[ -s $gguf_0 ]] ; then
echo -n " $gguf_0 "
2024-01-26 07:18:00 -05:00
else
echo >& 2 "No model found. Can't run gg_run_ctest_with_model."
exit 1
fi
}
function gg_run_ctest_with_model_debug {
cd ${ SRC }
local model; model = $( gg_get_model)
cd build-ci-debug
set -e
2025-09-13 16:24:22 +03:00
2024-01-26 07:18:00 -05:00
( LLAMACPP_TEST_MODELFILE = " $model " time ctest --output-on-failure -L model) 2>& 1 | tee -a $OUT /${ ci } -ctest.log
2025-09-13 16:24:22 +03:00
2024-01-26 07:18:00 -05:00
set +e
cd ..
}
function gg_run_ctest_with_model_release {
cd ${ SRC }
local model; model = $( gg_get_model)
cd build-ci-release
set -e
2025-09-13 16:24:22 +03:00
2024-01-26 07:18:00 -05:00
( LLAMACPP_TEST_MODELFILE = " $model " time ctest --output-on-failure -L model) 2>& 1 | tee -a $OUT /${ ci } -ctest.log
2025-09-13 16:24:22 +03:00
# test memory leaks
#if [[ ! -z ${GG_BUILD_METAL} ]]; then
# # TODO: this hangs for some reason ...
# (time leaks -quiet -atExit -- ./bin/test-thread-safety -m $model --parallel 2 -t 2 -p "hello") 2>&1 | tee -a $OUT/${ci}-leaks.log
#fi
2024-01-26 07:18:00 -05:00
set +e
cd ..
}
function gg_sum_ctest_with_model_debug {
gg_printf '### %s\n\n' " ${ ci } "
gg_printf 'Runs ctest with model files in debug mode\n'
gg_printf '- status: %s\n' " $( cat $OUT /${ ci } .exit) "
gg_printf '```\n'
gg_printf '%s\n' " $( cat $OUT /${ ci } -ctest.log) "
gg_printf '```\n'
}
function gg_sum_ctest_with_model_release {
gg_printf '### %s\n\n' " ${ ci } "
gg_printf 'Runs ctest with model files in release mode\n'
gg_printf '- status: %s\n' " $( cat $OUT /${ ci } .exit) "
gg_printf '```\n'
gg_printf '%s\n' " $( cat $OUT /${ ci } -ctest.log) "
gg_printf '```\n'
}
2025-09-21 16:50:45 +03:00
# qwen3_0_6b
2023-07-22 11:48:22 +03:00
2025-09-21 16:50:45 +03:00
function gg_run_qwen3_0_6b {
2023-07-22 11:48:22 +03:00
cd ${ SRC }
2025-09-21 16:50:45 +03:00
gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/config.json
gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/tokenizer.json
gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/tokenizer_config.json
#gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/raw/main/special_tokens_map.json
gg_wget models-mnt/qwen3/0.6B/ https://huggingface.co/Qwen/Qwen3-0.6B-Base/resolve/main/model.safetensors
2023-07-22 11:48:22 +03:00
2024-02-18 22:39:30 +02:00
gg_wget models-mnt/wikitext/ https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip
2023-07-22 11:48:22 +03:00
unzip -o models-mnt/wikitext/wikitext-2-raw-v1.zip -d models-mnt/wikitext/
2025-09-21 16:50:45 +03:00
path_models = "../models-mnt/qwen3/0.6B"
2023-07-22 11:48:22 +03:00
path_wiki = "../models-mnt/wikitext/wikitext-2-raw"
rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
set -e
2024-08-26 12:19:39 +03:00
( time cmake -DCMAKE_BUILD_TYPE= Release ${ CMAKE_EXTRA } .. ) 2>& 1 | tee -a $OUT /${ ci } -cmake.log
( time make -j$( nproc) ) 2>& 1 | tee -a $OUT /${ ci } -make.log
2023-07-22 11:48:22 +03:00
2025-09-22 08:31:40 +03:00
python3 ../convert_hf_to_gguf.py ${ path_models } --outfile ${ path_models } /ggml-model-f16.gguf --outtype f16
2025-09-21 16:50:45 +03:00
python3 ../convert_hf_to_gguf.py ${ path_models } --outfile ${ path_models } /ggml-model-bf16.gguf --outtype bf16
2023-07-22 11:48:22 +03:00
2025-09-22 08:31:40 +03:00
model_f16 = " ${ path_models } /ggml-model-f16.gguf"
2025-09-21 16:50:45 +03:00
model_bf16 = " ${ path_models } /ggml-model-bf16.gguf"
2023-08-21 23:07:43 +03:00
model_q8_0 = " ${ path_models } /ggml-model-q8_0.gguf"
model_q4_0 = " ${ path_models } /ggml-model-q4_0.gguf"
model_q4_1 = " ${ path_models } /ggml-model-q4_1.gguf"
model_q5_0 = " ${ path_models } /ggml-model-q5_0.gguf"
model_q5_1 = " ${ path_models } /ggml-model-q5_1.gguf"
model_q2_k = " ${ path_models } /ggml-model-q2_k.gguf"
model_q3_k = " ${ path_models } /ggml-model-q3_k.gguf"
model_q4_k = " ${ path_models } /ggml-model-q4_k.gguf"
model_q5_k = " ${ path_models } /ggml-model-q5_k.gguf"
model_q6_k = " ${ path_models } /ggml-model-q6_k.gguf"
2023-07-22 11:48:22 +03:00
wiki_test = " ${ path_wiki } /wiki.test.raw"
2025-09-25 05:06:06 +00:00
./bin/llama-quantize ${ model_bf16 } ${ model_q8_0 } q8_0 $( nproc)
./bin/llama-quantize ${ model_bf16 } ${ model_q4_0 } q4_0 $( nproc)
./bin/llama-quantize ${ model_bf16 } ${ model_q4_1 } q4_1 $( nproc)
./bin/llama-quantize ${ model_bf16 } ${ model_q5_0 } q5_0 $( nproc)
./bin/llama-quantize ${ model_bf16 } ${ model_q5_1 } q5_1 $( nproc)
./bin/llama-quantize ${ model_bf16 } ${ model_q2_k } q2_k $( nproc)
./bin/llama-quantize ${ model_bf16 } ${ model_q3_k } q3_k $( nproc)
./bin/llama-quantize ${ model_bf16 } ${ model_q4_k } q4_k $( nproc)
./bin/llama-quantize ${ model_bf16 } ${ model_q5_k } q5_k $( nproc)
./bin/llama-quantize ${ model_bf16 } ${ model_q6_k } q6_k $( nproc)
2023-07-22 11:48:22 +03:00
2025-09-22 08:31:40 +03:00
( time ./bin/llama-cli -no-cnv --model ${ model_f16 } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-f16.log
( time ./bin/llama-cli -no-cnv --model ${ model_bf16 } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-bf16.log
( time ./bin/llama-cli -no-cnv --model ${ model_q8_0 } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-q8_0.log
( time ./bin/llama-cli -no-cnv --model ${ model_q4_0 } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-q4_0.log
( time ./bin/llama-cli -no-cnv --model ${ model_q4_1 } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-q4_1.log
( time ./bin/llama-cli -no-cnv --model ${ model_q5_0 } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-q5_0.log
( time ./bin/llama-cli -no-cnv --model ${ model_q5_1 } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-q5_1.log
( time ./bin/llama-cli -no-cnv --model ${ model_q2_k } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-q2_k.log
( time ./bin/llama-cli -no-cnv --model ${ model_q3_k } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-q3_k.log
( time ./bin/llama-cli -no-cnv --model ${ model_q4_k } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-q4_k.log
( time ./bin/llama-cli -no-cnv --model ${ model_q5_k } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-q5_k.log
( time ./bin/llama-cli -no-cnv --model ${ model_q6_k } -ngl 99 -c 1024 -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>& 1 | tee -a $OUT /${ ci } -tg-q6_k.log
2023-07-22 11:48:22 +03:00
2025-09-22 08:31:40 +03:00
( 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
if [ -z ${ GG_BUILD_NO_BF16 } ] ; then
( 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
fi
( 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
( 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
( 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
( 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
( 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
( 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
( 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
( 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
( 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
( 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
2023-07-22 11:48:22 +03:00
2025-09-22 08:31:40 +03:00
( 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
2024-01-17 18:46:30 +02:00
2025-09-22 08:31:40 +03:00
( time ./bin/llama-save-load-state --model ${ model_q4_0 } -ngl 10 -c 1024 -fa off ) 2>& 1 | tee -a $OUT /${ ci } -save-load-state.log
( time ./bin/llama-save-load-state --model ${ model_q4_0 } -ngl 10 -c 1024 -fa on ) 2>& 1 | tee -a $OUT /${ ci } -save-load-state.log
( 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
( 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
2023-10-17 19:12:46 +03:00
2023-07-22 11:48:22 +03:00
function check_ppl {
qnt = " $1 "
ppl = $( echo " $2 " | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
if [ $( echo " $ppl > 20.0" | bc) -eq 1 ] ; then
printf ' - %s @ %s (FAIL: ppl > 20.0)\n' " $qnt " " $ppl "
return 20
fi
printf ' - %s @ %s OK\n' " $qnt " " $ppl "
return 0
}
2025-09-22 08:31:40 +03:00
check_ppl "f16" " $( cat $OUT /${ ci } -tg-f16.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
if [ -z ${ GG_BUILD_NO_BF16 } ] ; then
check_ppl "bf16" " $( cat $OUT /${ ci } -tg-bf16.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
fi
2024-05-23 15:28:14 +03:00
check_ppl "q8_0" " $( cat $OUT /${ ci } -tg-q8_0.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
check_ppl "q4_0" " $( cat $OUT /${ ci } -tg-q4_0.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
check_ppl "q4_1" " $( cat $OUT /${ ci } -tg-q4_1.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
check_ppl "q5_0" " $( cat $OUT /${ ci } -tg-q5_0.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
check_ppl "q5_1" " $( cat $OUT /${ ci } -tg-q5_1.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
#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
check_ppl "q3_k" " $( cat $OUT /${ ci } -tg-q3_k.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
check_ppl "q4_k" " $( cat $OUT /${ ci } -tg-q4_k.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
check_ppl "q5_k" " $( cat $OUT /${ ci } -tg-q5_k.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
check_ppl "q6_k" " $( cat $OUT /${ ci } -tg-q6_k.log | grep "^\[1\]" ) " | tee -a $OUT /${ ci } -ppl.log
cat $OUT /${ ci } -imatrix.log | grep "Final" >> $OUT /${ ci } -imatrix-sum.log
set +e
}
2025-09-21 16:50:45 +03:00
function gg_sum_qwen3_0_6b {
2024-05-23 15:28:14 +03:00
gg_printf '### %s\n\n' " ${ ci } "
2025-09-25 05:06:06 +00:00
gg_printf 'Qwen3 0.6B:\n'
2024-05-23 15:28:14 +03:00
gg_printf '- status: %s\n' " $( cat $OUT /${ ci } .exit) "
gg_printf '- perplexity:\n%s\n' " $( cat $OUT /${ ci } -ppl.log) "
gg_printf '- imatrix:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -imatrix-sum.log) "
2025-09-22 08:31:40 +03:00
gg_printf '- f16:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-f16.log) "
if [ -z ${ GG_BUILD_NO_BF16 } ] ; then
gg_printf '- bf16:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-bf16.log) "
fi
2024-05-23 15:28:14 +03:00
gg_printf '- q8_0:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q8_0.log) "
gg_printf '- q4_0:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q4_0.log) "
gg_printf '- q4_1:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q4_1.log) "
gg_printf '- q5_0:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q5_0.log) "
gg_printf '- q5_1:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q5_1.log) "
gg_printf '- q2_k:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q2_k.log) "
gg_printf '- q3_k:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q3_k.log) "
gg_printf '- q4_k:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q4_k.log) "
gg_printf '- q5_k:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q5_k.log) "
gg_printf '- q6_k:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q6_k.log) "
gg_printf '- save-load-state: \n```\n%s\n```\n' " $( cat $OUT /${ ci } -save-load-state.log) "
}
2024-02-13 13:01:29 +02:00
# bge-small
function gg_run_embd_bge_small {
cd ${ SRC }
gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json
2024-03-29 14:34:28 +02:00
gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer.json
2024-02-13 13:01:29 +02:00
gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/tokenizer_config.json
gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/special_tokens_map.json
gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/resolve/main/pytorch_model.bin
gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/sentence_bert_config.json
gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/vocab.txt
2024-02-16 09:57:55 +02:00
gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/modules.json
gg_wget models-mnt/bge-small/ https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/config.json
gg_wget models-mnt/bge-small/1_Pooling https://huggingface.co/BAAI/bge-small-en-v1.5/raw/main/1_Pooling/config.json
2024-02-13 13:01:29 +02:00
path_models = "../models-mnt/bge-small"
rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
set -e
( time cmake -DCMAKE_BUILD_TYPE= Release ${ CMAKE_EXTRA } .. ) 2>& 1 | tee -a $OUT /${ ci } -cmake.log
2024-08-26 11:03:30 +02:00
( time make -j$( nproc) ) 2>& 1 | tee -a $OUT /${ ci } -make.log
2024-02-13 13:01:29 +02:00
2024-03-10 23:21:46 +05:30
python3 ../convert_hf_to_gguf.py ${ path_models } --outfile ${ path_models } /ggml-model-f16.gguf
2024-02-13 13:01:29 +02:00
model_f16 = " ${ path_models } /ggml-model-f16.gguf"
model_q8_0 = " ${ path_models } /ggml-model-q8_0.gguf"
2024-06-13 00:41:52 +01:00
./bin/llama-quantize ${ model_f16 } ${ model_q8_0 } q8_0
2024-02-13 13:01:29 +02:00
2024-11-02 15:18:56 +02:00
( 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
( 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
2024-02-13 13:01:29 +02:00
set +e
}
2024-09-28 17:42:03 +03:00
function gg_sum_embd_bge_small {
gg_printf '### %s\n\n' " ${ ci } "
gg_printf 'BGE Small (BERT):\n'
gg_printf '- status: %s\n' " $( cat $OUT /${ ci } .exit) "
gg_printf '- f16: \n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-f16.log) "
gg_printf '- q8_0:\n```\n%s\n```\n' " $( cat $OUT /${ ci } -tg-q8_0.log) "
}
# rerank_tiny
function gg_run_rerank_tiny {
cd ${ SRC }
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer.json
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer_config.json
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/special_tokens_map.json
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/resolve/main/pytorch_model.bin
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/sentence_bert_config.json
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/vocab.txt
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/modules.json
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json
gg_wget models-mnt/rerank-tiny/1_Pooling https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/1_Pooling/config.json
path_models = "../models-mnt/rerank-tiny"
rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
set -e
( time cmake -DCMAKE_BUILD_TYPE= Release ${ CMAKE_EXTRA } .. ) 2>& 1 | tee -a $OUT /${ ci } -cmake.log
( time make -j$( nproc) ) 2>& 1 | tee -a $OUT /${ ci } -make.log
python3 ../convert_hf_to_gguf.py ${ path_models } --outfile ${ path_models } /ggml-model-f16.gguf
model_f16 = " ${ path_models } /ggml-model-f16.gguf"
2024-10-05 15:55:04 +03:00
# for this model, the SEP token is "</s>"
2025-06-20 14:04:09 +02:00
( 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
2024-09-28 17:42:03 +03:00
# sample output
# rerank score 0: 0.029
# rerank score 1: 0.029
# rerank score 2: 0.135
# check that the score is in the range [$3, $4]
function check_score {
qnt = " $1 "
score = $( echo " $2 " | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
if [ $( echo " $score < $3 " | bc) -eq 1 ] || [ $( echo " $score > $4 " | bc) -eq 1 ] ; then
printf ' - %s @ %s (FAIL: score not in range [%s, %s])\n' " $qnt " " $score " " $3 " " $4 "
return 20
fi
printf ' - %s @ %s OK\n' " $qnt " " $score "
return 0
}
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
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
2024-10-05 15:55:04 +03:00
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
2024-09-28 17:42:03 +03:00
set +e
}
function gg_sum_rerank_tiny {
gg_printf '### %s\n\n' " ${ ci } "
gg_printf 'Rerank Tiny (Jina):\n'
gg_printf '- status: %s\n' " $( cat $OUT /${ ci } .exit) "
gg_printf '- f16: \n```\n%s\n```\n' " $( cat $OUT /${ ci } -rk-f16.log) "
}
2024-07-07 15:59:14 +01:00
function gg_check_build_requirements {
if ! command -v cmake & > /dev/null; then
gg_printf 'cmake not found, please install'
fi
if ! command -v make & > /dev/null; then
gg_printf 'make not found, please install'
fi
if ! command -v ctest & > /dev/null; then
gg_printf 'ctest not found, please install'
fi
}
2023-07-18 14:24:43 +03:00
## main
2024-09-15 20:46:12 +03:00
export LLAMA_LOG_PREFIX = 1
export LLAMA_LOG_TIMESTAMPS = 1
2023-07-22 11:48:22 +03:00
if [ -z ${ GG_BUILD_LOW_PERF } ] ; then
2025-03-25 15:45:08 +08:00
# Create symlink: ./llama.cpp/models-mnt -> $MNT/models
2023-07-18 14:24:43 +03:00
rm -rf ${ SRC } /models-mnt
2023-07-21 13:48:18 +03:00
mnt_models = ${ MNT } /models
2023-07-18 14:24:43 +03:00
mkdir -p ${ mnt_models }
ln -sfn ${ mnt_models } ${ SRC } /models-mnt
2024-01-26 07:18:00 -05:00
# Create a fresh python3 venv and enter it
2024-12-01 10:11:42 -08:00
if ! python3 -m venv " $MNT /venv" ; then
echo "Error: Failed to create Python virtual environment at $MNT /venv."
exit 1
fi
2024-01-26 07:18:00 -05:00
source " $MNT /venv/bin/activate"
pip install -r ${ SRC } /requirements.txt --disable-pip-version-check
pip install --editable gguf-py --disable-pip-version-check
2023-07-18 14:24:43 +03:00
fi
ret = 0
2025-10-02 10:35:43 +03:00
2025-09-13 16:24:22 +03:00
test $ret -eq 0 && gg_run ctest_debug
2023-07-22 11:48:22 +03:00
test $ret -eq 0 && gg_run ctest_release
2023-07-18 14:24:43 +03:00
2023-07-22 11:48:22 +03:00
if [ -z ${ GG_BUILD_LOW_PERF } ] ; then
2024-02-13 13:01:29 +02:00
test $ret -eq 0 && gg_run embd_bge_small
2024-09-28 17:42:03 +03:00
test $ret -eq 0 && gg_run rerank_tiny
2024-02-13 13:01:29 +02:00
2024-05-07 11:08:49 +03:00
if [ -z ${ GG_BUILD_CLOUD } ] || [ ${ GG_BUILD_EXTRA_TESTS_0 } ] ; then
2025-09-22 09:11:39 +03:00
test $ret -eq 0 && gg_run test_scripts
2024-05-07 11:08:49 +03:00
fi
2024-04-14 13:12:59 +02:00
2025-09-21 16:50:45 +03:00
test $ret -eq 0 && gg_run qwen3_0_6b
test $ret -eq 0 && gg_run ctest_with_model_debug
test $ret -eq 0 && gg_run ctest_with_model_release
2023-07-18 14:24:43 +03:00
fi
2025-10-02 10:35:43 +03:00
cat $OUT /README.md
2023-07-18 14:24:43 +03:00
exit $ret