char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
516a4ca9b
char/aliceai-t5-moe
1#!/usr/bin/env bash 2 3PROG =${0##*/} 4build_dir ="build-ci-debug" 5 6# Print Color Commands 7red =$( tput setaf 1) 8green =$( tput setaf 2) 9yellow =$( tput setaf 3) 10blue =$( tput setaf 4) 11magenta =$( tput setaf 5) 12cyan =$( tput setaf 6) 13normal =$( tput sgr0) 14 15 16# Print Help Message 17#################### 18 19print_full_help () { 20cat <<EOF 21Usage: $ PROG [OPTION]... <test_regex> (test_number) 22Debug specific ctest program. 23 24Options: 25-h, --help display this help and exit 26-g run in gdb mode 27 28Arguments: 29<test_regex> (Mandatory) Supply one regex to the script to filter tests 30(test_number) (Optional) Test number to run a specific test 31 32Example: 33$PROG test-tokenizer 34$PROG test-tokenizer 3 35EOF 36} 37 38abort () { 39echo "Error: $ 1 " >&2 40cat <<EOF >&2 41Usage: $ PROG [OPTION]... <test_regex> (test_number) 42Debug specific ctest program. 43Refer to --help for full instructions. 44EOF 45exit 1 46} 47 48 49# Dependency Sanity Check 50######################### 51 52check_dependency () { 53command -v " $ 1 " > /dev/null2 >&1 || { 54abort " $ 1 is required but not found. Please install it and try again." 55 } 56} 57 58check_dependency ctest 59check_dependency cmake 60 61 62# Step 0: Check the args 63######################## 64 65if [ x" $ 1 " = x"-h" ] || [ x" $ 1 " = x"--help" ];then 66print_full_help >&2 67exit 0 68fi 69 70# Parse command-line options 71gdb_mode =false 72while getopts "g" opt;do 73case $ opt in 74 g) 75gdb_mode =true 76echo "gdb_mode Mode Enabled" 77 ;; 78esac 79done 80 81# Shift the option parameters 82shift $((OPTIND - 1)) 83 84# Positionial Argument Processing : <test_regex> 85if [ -z" ${ 1 } " ];then 86abort "Test regex is required" 87else 88test_suite =${ 1 :-} 89fi 90 91# Positionial Argument Processing : (test_number) 92test_number =${ 2 :-} 93 94 95# Step 1: Reset and Setup folder context 96######################################## 97 98## Sanity check that we are actually in a git repo 99repo_root =$( git rev-parse --show-toplevel ) 100if [ ! -d" $ repo_root " ];then 101abort "Not in a Git repository." 102fi 103 104## Reset folder to root context of git repo and Create and enter build directory 105pushd " $ repo_root " 106rm -rf " $ build_dir " && mkdir " $ build_dir " ||abort "Failed to make $ build_dir " 107 108 109# Step 2: Setup Build Environment and Compile Test Binaries 110########################################################### 111 112cmake -B "./ $ build_dir " -DCMAKE_BUILD_TYPE=Debug -DGGML_CUDA=1 ||abort "Failed to build environment" 113pushd " $ build_dir " 114make -j ||abort "Failed to compile" 115popd > /dev/null ||exit 1 116 117 118# Step 3: Find all tests available that matches REGEX 119#################################################### 120 121# Ctest Gather Tests 122# `-R test-tokenizer` : looks for all the test files named `test-tokenizer*` (R=Regex) 123# `-N` : "show-only" disables test execution & shows test commands that you can feed to GDB. 124# `-V` : Verbose Mode 125printf "\n\nGathering tests that fit REGEX: ${ test_suite } ...\n" 126pushd " $ build_dir " 127tests =($( ctest -R ${ test_suite } -V -N | grep -E " +Test +#[0-9]+*" | cut -d ':' -f2 | awk '{$1=$1};1' ) ) 128if [${# tests [@]} -eq 0 ];then 129abort "No tests available... check your compilation process..." 130fi 131popd > /dev/null ||exit 1 132 133 134# Step 4: Identify Test Command for Debugging 135############################################# 136 137# Select test number 138if [ -z$ test_number ];then 139# List out available tests 140printf "Which test would you like to debug?\n" 141id =0 142for s in " ${ tests [@]} " 143do 144echo "Test# ${ id } " 145echo " $ s " 146 ((id++)) 147done 148 149# Prompt user which test they wanted to run 150printf "\nRun test#? " 151read test_number 152 153else 154printf "\nUser Already Requested # ${ test_number } \n" 155 156fi 157 158# Grab all tests commands 159pushd " $ build_dir " 160sIFS =$ IFS # Save Initial IFS (Internal Field Separator) 161IFS =$'\n'# Change IFS (Internal Field Separator) (So we split ctest output by newline rather than by spaces) 162test_args =($( ctest -R ${ test_suite } -V -N | grep "Test command" | cut -d ':' -f3 | awk '{$1=$1};1' ) )# Get test args 163IFS =$ sIFS # Reset IFS (Internal Field Separator) 164popd > /dev/null ||exit 1 165 166# Grab specific test command 167single_test_name =" ${ tests [test_number]} " 168single_test_command =" ${ test_args [test_number]} " 169 170 171# Step 5: Execute or GDB Debug 172############################## 173 174printf " ${ magenta } Running Test # ${ test_number } : ${ single_test_name }${ normal } \n" 175printf " ${ cyan } single_test_command: ${ single_test_command }${ normal } \n" 176 177if [" $ gdb_mode " ="true" ];then 178# Execute debugger 179pushd " $ repo_root " ||exit 1 180eval "gdb --args ${ single_test_command } " 181popd > /dev/null ||exit 1 182 183else 184# Execute Test 185pushd " $ repo_root " ||exit 1 186eval " ${ single_test_command } " 187exit_code =$ ? 188popd > /dev/null ||exit 1 189 190# Print Result 191printf " ${ blue } Ran Test # ${ test_number } : ${ single_test_name }${ normal } \n" 192printf " ${ yellow } Command: ${ single_test_command }${ normal } \n" 193if [$ exit_code -eq 0 ];then 194printf " ${ green } TEST PASS ${ normal } \n" 195else 196printf " ${ red } TEST FAIL ${ normal } \n" 197fi 198 199fi 200 201# Return to the directory from which the user ran the command. 202popd > /dev/null ||exit 1