scripts : add some fancy conversion from snake_case to PascalCase

This commit is contained in:
crasm 2024-01-19 02:09:57 -05:00
parent a34648d35e
commit 9a11611a7d
3 changed files with 74 additions and 37 deletions

View file

@ -9,62 +9,75 @@ source 'lib.sh'
#### END SETUP #### #### END SETUP ####
# TODO: send model to ctest_model tests using env variable # TODO: send model to ctest_model tests using env variable
# GG_TEST_CTEST_MODEL_MODELFILE=<snip> # GG_CI_CTEST_MODELFILE=<snip>
IsValidTestTarget() { IsValidTestTarget() {
case "$1" in case "$1" in
cmake | ctest_main | model_3b | model_7b | test_cpu | test_cuda | test_metal | ctest_model) cmake | ctest_main | model_3b | model_7b | test_cpu | test_cuda | test_metal | ctest_model)
return 0;; return $_OK;;
*) *)
return 1;; return $_ERR;;
esac esac
} }
declare -a test_targets declare -a targets
if (( $# > 0 )); then if (( $# > 0 )); then
test_targets=("$@") targets=("$@")
elif _IsSet GG_TEST_TARGETS; then elif _IsSet GG_CI_TARGETS; then
read -r -a test_targets <<< "$GG_TEST_TARGETS" read -r -a targets <<< "$GG_CI_TARGETS"
else else
cat >&2 <<'EOF' cat >&2 <<'EOF'
You must specify the test targets either as commandline arguments or using the usage:
GG_TEST_TARGETS environment variable. Test targets will be run sequentially ci-run.sh [targets...]
in-order.
Some test targets depend on other test targets, as described below. config variables:
GG_CI_TARGETS : Space delimited sequence of targets.
Overridden by commandline arguments.
GG_CI_WORKDIR : Build files and results.
Defaults to /tmp.
GG_CI_DATADIR : Persistent model files and datasets, unchanged between runs.
Defaults to ~/.cache/llama.cpp/ci-data.
GG_CI_TEMPDIR : Scratch directory for quantized model files.
Defaults to ~/.cache/llama.cpp/ci-temp
cli usage: examples:
ci-run.sh test_targets... # A run on a low-spec VM without a dedicated GPU.
ci-run.sh cmake ctest_main model_3b test_cpu ctest_model
ci usage: # A run on a Mac Studio with a ramdisk at ~/tmp
GG_TEST_TARGETS='test_targets...' ci-run.sh GG_CI_WORKDIR=~/tmp/ci-work \
GG_CI_TEMPDIR=~/tmp/ci-temp \
example: ci-run.sh cmake ctest_main model_7b test_cpu test_metal ctest_model
# This is a typical run for a low-spec host without a dedicated GPU.
ci-run.sh cmake ctest_main model_3b test_cpu ctest_model
test targets: test targets:
cmake : run cmake to produce debug and release builds cmake : Run cmake to produce debug and release builds.
ctest_main : run main ctest tests for debug and release ctest_main : Run main ctest tests for debug and release.
(requires: cmake) model_3b,
model_3b : download and quantize openllama_3b_v2 model_7b : Download and quantize openllama_3b_v2 and/or openllama_7b_v2.
model_7b : download and quantize openllama_7b_v2 test_cpu,
test_cpu : test CPU inference, perplexity tests, etc. test_cuda,
(requires: model_3b or model_7b) test_metal : Test CPU inference, perplexity tests, etc.
test_cuda : test CUDA ... ctest_model : Run ctest tests that require the openllama model.
(requires: model_3b or model_7b)
test_metal : test Metal ...
(requires: model_3b or model_7b)
ctest_model : run ctest tests that require the openllama model
(requires: model_3b or model_7b)
EOF EOF
exit 1 exit $_ERR
fi fi
for target in "${test_targets[@]}"; do for target in "${targets[@]}"; do
if IsValidTestTarget "$target"; then if IsValidTestTarget "$target"; then
_LogInfo "Received test target: $target" _LogInfo "Received test target: $target"
else else
_LogFatal "Invalid test target: $target" _LogFatal "Invalid test target: $target"
fi fi
done done
cd ..
[[ -d .git && -x .git ]] || _LogFatal 'Could not cd to llama.cpp root direcory'
TargetCmake() {
echo hello
}
for target in "${targets[@]}"; do
pascal_target="$(_SnakeToPascalCase "$target")"
"Target$pascal_target"
done

View file

@ -5,6 +5,9 @@ if [[ ${BASH_SOURCE[0]} -ef $0 ]]; then
exit 1 exit 1
fi fi
readonly _OK=0
readonly _ERR=1
_Log() { _Log() {
local level=$1 msg=$2 local level=$1 msg=$2
printf >&2 '%s: %s\n' "$level" "$msg" printf >&2 '%s: %s\n' "$level" "$msg"
@ -25,14 +28,26 @@ _LogFatal() {
# Return true if the variable with name $1 is set # Return true if the variable with name $1 is set
_IsSet() { _IsSet() {
(( $# != 1 )) && return false (( $# != 1 )) && return $_ERR
if [[ -n ${!1+x} ]]; then if [[ -n ${!1+x} ]]; then
return 0 return $_OK
else else
return 1 return $_ERR
fi fi
} }
_IsNotSet() { _IsNotSet() {
! _IsSet "$@" ! _IsSet "$@"
} }
_SnakeToPascalCase() {
(( $# != 1 )) && return $_ERR
local IFS='_'
local pascal=''
for word in $1; do
local head; head=$(tr '[:lower:]' '[:upper:]' <<< "${word:0:1}")
local tail=${word:1}
pascal+="$head$tail"
done
echo -n "$pascal"
}

View file

@ -12,6 +12,8 @@ shellcheck --external-sources "$this"
source 'lib.sh' source 'lib.sh'
#### END SETUP #### #### END SETUP ####
shellcheck 'lib.sh'
Pass() { Pass() {
local test_func="${FUNCNAME[1]}" local test_func="${FUNCNAME[1]}"
_Log 'PASSED' "$test_func" _Log 'PASSED' "$test_func"
@ -47,3 +49,10 @@ TestIsNotSet() {
Fail 'bar was detected as set' Fail 'bar was detected as set'
else Pass; fi else Pass; fi
}; TestIsNotSet }; TestIsNotSet
TestSnakeToPascalCase() {
local id; id=$(_SnakeToPascalCase this_is_an_id)
if [[ $id != ThisIsAnId ]]; then
Fail "this_is_an_id was converted to $id"
else Pass; fi
}; TestSnakeToPascalCase