#!/usr/bin/env bash
get_msmodelslim_path() {
local custom_path=$1
if [ -n "$custom_path" ] && [ -d "$custom_path" ]; then
echo "$custom_path"
return 0
fi
local path=$(python -c "import msmodelslim; print(msmodelslim.__path__[0])" 2>/dev/null)
if [ $? -eq 0 ] && [ -n "$path" ]; then
echo "$path"
else
echo "错误:无法获取 msmodelslim 路径" >&2
return 1
fi
}
check_files_exist() {
local target_path=$1
shift
local files=("$@")
if [ ! -d "$target_path" ]; then
echo "错误:目标路径 '$target_path' 不存在" >&2
return 1
fi
local all_exist=true
for file in "${files[@]}"; do
full_path="$target_path/$file"
if [ ! -e "$full_path" ]; then
echo "错误:文件 '$file' 不存在" >&2
all_exist=false
fi
done
local quant_model_single="$target_path/quant_model_weights.safetensors"
local quant_model_pattern="$target_path/quant_model_weights-*.safetensors"
shopt -s nullglob
local quant_model_files=($quant_model_pattern)
shopt -u nullglob
if [ ! -e "$quant_model_single" ] && [ ${#quant_model_files[@]} -eq 0 ]; then
echo "错误:quant_model_weights.safetensors 或其分片文件不存在" >&2
all_exist=false
else
if [ ! -e "$quant_model_single" ]; then
for quant_file in "${quant_model_files[@]}"; do
if [ ! -e "$quant_file" ]; then
echo "错误:文件 '$quant_file' 不存在" >&2
all_exist=false
fi
done
fi
fi
if [ "$all_exist" = true ]; then
echo "提示:所有文件均存在于目标路径"
return 0
else
return 1
fi
}