Skip to content

Commit f19554f

Browse files
committed
ci : add rerank tests
ggml-ci
1 parent ca99a6c commit f19554f

File tree

2 files changed

+77
-9
lines changed

2 files changed

+77
-9
lines changed

ci/run.sh

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,81 @@ function gg_run_embd_bge_small {
712712
set +e
713713
}
714714

715+
function gg_sum_embd_bge_small {
716+
gg_printf '### %s\n\n' "${ci}"
717+
718+
gg_printf 'BGE Small (BERT):\n'
719+
gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
720+
gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
721+
gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
722+
}
723+
724+
# rerank_tiny
725+
726+
function gg_run_rerank_tiny {
727+
cd ${SRC}
728+
729+
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json
730+
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer.json
731+
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/tokenizer_config.json
732+
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/special_tokens_map.json
733+
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/resolve/main/pytorch_model.bin
734+
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/sentence_bert_config.json
735+
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/vocab.txt
736+
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/modules.json
737+
gg_wget models-mnt/rerank-tiny/ https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/config.json
738+
739+
gg_wget models-mnt/rerank-tiny/1_Pooling https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/raw/main/1_Pooling/config.json
740+
741+
path_models="../models-mnt/rerank-tiny"
742+
743+
rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
744+
745+
set -e
746+
747+
(time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
748+
(time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
749+
750+
python3 ../convert_hf_to_gguf.py ${path_models} --outfile ${path_models}/ggml-model-f16.gguf
751+
752+
model_f16="${path_models}/ggml-model-f16.gguf"
753+
754+
(time ./bin/llama-embedding --model ${model_f16} -p "what is panda?</s><s>hi\nwhat is panda?</s><s>it's a bear\nwhat is panda?</s><s>The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China." --pooling rank --embd-normalize -1 --verbose-prompt) 2>&1 | tee -a $OUT/${ci}-rk-f16.log
755+
756+
# sample output
757+
# rerank score 0: 0.029
758+
# rerank score 1: 0.029
759+
# rerank score 2: 0.135
760+
761+
# check that the score is in the range [$3, $4]
762+
function check_score {
763+
qnt="$1"
764+
score=$(echo "$2" | grep -oE "[0-9]+\.[0-9]+" | tail -n 1)
765+
766+
if [ $(echo "$score < $3" | bc) -eq 1 ] || [ $(echo "$score > $4" | bc) -eq 1 ]; then
767+
printf ' - %s @ %s (FAIL: score not in range [%s, %s])\n' "$qnt" "$score" "$3" "$4"
768+
return 20
769+
fi
770+
771+
printf ' - %s @ %s OK\n' "$qnt" "$score"
772+
return 0
773+
}
774+
775+
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
776+
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
777+
check_score "rerank score 2" "$(cat $OUT/${ci}-rk-f16.log | grep "rerank score 2")" "0.10" "0.15" | tee -a $OUT/${ci}-rk-f16.log
778+
779+
set +e
780+
}
781+
782+
function gg_sum_rerank_tiny {
783+
gg_printf '### %s\n\n' "${ci}"
784+
785+
gg_printf 'Rerank Tiny (Jina):\n'
786+
gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
787+
gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-rk-f16.log)"
788+
}
789+
715790
function gg_check_build_requirements {
716791
if ! command -v cmake &> /dev/null; then
717792
gg_printf 'cmake not found, please install'
@@ -726,15 +801,6 @@ function gg_check_build_requirements {
726801
fi
727802
}
728803

729-
function gg_sum_embd_bge_small {
730-
gg_printf '### %s\n\n' "${ci}"
731-
732-
gg_printf 'BGE Small (BERT):\n'
733-
gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
734-
gg_printf '- f16: \n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-f16.log)"
735-
gg_printf '- q8_0:\n```\n%s\n```\n' "$(cat $OUT/${ci}-tg-q8_0.log)"
736-
}
737-
738804
## main
739805

740806
export LLAMA_LOG_PREFIX=1
@@ -762,6 +828,7 @@ test $ret -eq 0 && gg_run ctest_release
762828

763829
if [ -z ${GG_BUILD_LOW_PERF} ]; then
764830
test $ret -eq 0 && gg_run embd_bge_small
831+
test $ret -eq 0 && gg_run rerank_tiny
765832

766833
if [ -z ${GG_BUILD_CLOUD} ] || [ ${GG_BUILD_EXTRA_TESTS_0} ]; then
767834
test $ret -eq 0 && gg_run test_scripts_debug

examples/embedding/embedding.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ int main(int argc, char ** argv) {
236236
}
237237
} else if (pooling_type == LLAMA_POOLING_TYPE_RANK) {
238238
for (int j = 0; j < n_embd_count; j++) {
239+
// NOTE: if you change this log - update the tests in ci/run.sh
239240
LOG("rerank score %d: %8.3f\n", j, emb[j * n_embd]);
240241
}
241242
} else {

0 commit comments

Comments
 (0)