Files
llama.cpp/tools/gguf-split/tests.sh
T

110 lines
3.0 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2024-04-14 13:12:59 +02:00
set -eu
if [ $# -lt 1 ]
then
2024-04-25 14:27:20 +03:00
echo "usage: $0 path_to_build_binary [path_to_temp_folder]"
echo "example: $0 ../../build/bin ../../tmp"
exit 1
2024-04-14 13:12:59 +02:00
fi
if [ $# -gt 1 ]
then
2024-04-25 14:27:20 +03:00
TMP_DIR=$2
2024-04-14 13:12:59 +02:00
else
2024-04-25 14:27:20 +03:00
TMP_DIR=/tmp
2024-04-14 13:12:59 +02:00
fi
set -x
SPLIT=$1/llama-gguf-split
2025-12-10 15:28:59 +01:00
MAIN=$1/llama-completion
2024-04-14 13:12:59 +02:00
WORK_PATH=$TMP_DIR/gguf-split
2024-04-25 14:27:20 +03:00
ROOT_DIR=$(realpath $(dirname $0)/../../)
2024-04-14 13:12:59 +02:00
mkdir -p "$WORK_PATH"
# Clean up in case of previously failed test
rm -f $WORK_PATH/ggml-model-split*.gguf $WORK_PATH/ggml-model-merge*.gguf
# 1. Get a model
(
2024-04-25 14:27:20 +03:00
cd $WORK_PATH
2025-09-22 09:11:39 +03:00
"$ROOT_DIR"/scripts/hf.sh --repo ggml-org/Qwen3-0.6B-GGUF --file Qwen3-0.6B-Q8_0.gguf
2024-04-14 13:12:59 +02:00
)
echo PASS
# 2. Split with max tensors strategy
2025-09-22 09:11:39 +03:00
$SPLIT --split-max-tensors 28 $WORK_PATH/Qwen3-0.6B-Q8_0.gguf $WORK_PATH/ggml-model-split
2024-04-14 13:12:59 +02:00
echo PASS
echo
# 2b. Test the sharded model is loading properly
2025-09-22 09:11:39 +03:00
$MAIN -no-cnv --model $WORK_PATH/ggml-model-split-00001-of-00012.gguf -p "I believe the meaning of life is" --n-predict 32
2024-04-14 13:12:59 +02:00
echo PASS
echo
# 3. Merge
2025-09-22 09:11:39 +03:00
$SPLIT --merge $WORK_PATH/ggml-model-split-00001-of-00012.gguf $WORK_PATH/ggml-model-merge.gguf
2024-04-14 13:12:59 +02:00
echo PASS
echo
# 3b. Test the merged model is loading properly
2025-09-22 09:11:39 +03:00
$MAIN -no-cnv --model $WORK_PATH/ggml-model-merge.gguf -p "I believe the meaning of life is" --n-predict 32
2024-04-14 13:12:59 +02:00
echo PASS
echo
# 4. Split with no tensors in the first split
$SPLIT --split-max-tensors 32 --no-tensor-first-split $WORK_PATH/ggml-model-merge.gguf $WORK_PATH/ggml-model-split-32-tensors
echo PASS
echo
2024-04-14 13:12:59 +02:00
# 4b. Test the sharded model is loading properly
2025-09-22 09:11:39 +03:00
$MAIN -no-cnv --model $WORK_PATH/ggml-model-split-32-tensors-00001-of-00011.gguf -p "I believe the meaning of life is" --n-predict 32
echo PASS
echo
2024-04-14 13:12:59 +02:00
# 5. Merge
#$SPLIT --merge $WORK_PATH/ggml-model-split-32-tensors-00001-of-00011.gguf $WORK_PATH/ggml-model-merge-2.gguf
2024-04-14 13:12:59 +02:00
#echo PASS
#echo
# 5b. Test the merged model is loading properly
#$MAIN -no-cnv --model $WORK_PATH/ggml-model-merge-2.gguf -p "I believe the meaning of life is" --n-predict 32
2024-04-14 13:12:59 +02:00
#echo PASS
#echo
# 6. Split with size strategy
2025-09-22 09:11:39 +03:00
$SPLIT --split-max-size 500M $WORK_PATH/ggml-model-merge.gguf $WORK_PATH/ggml-model-split-500M
2024-04-14 13:12:59 +02:00
echo PASS
echo
# 6b. Test the sharded model is loading properly
2025-09-22 09:11:39 +03:00
$MAIN -no-cnv --model $WORK_PATH/ggml-model-split-500M-00001-of-00002.gguf -p "I believe the meaning of life is" --n-predict 32
2024-04-14 13:12:59 +02:00
echo PASS
echo
# 7. Merge with delete splits
#for i in $(seq -w 1 11); do
# cp "$WORK_PATH/ggml-model-split-32-tensors-000${i}-of-00011.gguf" "$WORK_PATH/ggml-model-split-32-tensors-copy-000${i}-of-00011.gguf"
#done
#$SPLIT --merge --delete-splits $WORK_PATH/ggml-model-split-32-tensors-copy-00001-of-00011.gguf $WORK_PATH/ggml-model-merge-3.gguf
#echo PASS
#echo
# 7b. Test the merged model is loading properly
#$MAIN -no-cnv --model $WORK_PATH/ggml-model-merge-3.gguf -p "I believe the meaning of life is" --n-predict 32
#echo PASS
#echo
# 7c. Test the files were deleted
#for i in $(seq -w 1 11); do
# test ! -f "$WORK_PATH/ggml-model-split-32-tensors-copy-000${i}-of-00011.gguf"
#done
#echo PASS
#echo
2024-04-14 13:12:59 +02:00
# Clean up
rm -f $WORK_PATH/ggml-model-split*.gguf $WORK_PATH/ggml-model-merge*.gguf