File size: 4,054 Bytes
538ca27 7bde6da 538ca27 8e4cb30 7bde6da 538ca27 7bde6da 538ca27 17a696b 7bde6da 8e4cb30 17a696b 538ca27 8e4cb30 17a696b 538ca27 8e4cb30 7bde6da 17a696b 538ca27 17a696b 538ca27 17a696b 538ca27 7bde6da 538ca27 8e4cb30 7bde6da 8e4cb30 7bde6da 8e4cb30 538ca27 8e4cb30 7bde6da 8e4cb30 7bde6da 8e4cb30 538ca27 8e4cb30 538ca27 7bde6da 17a696b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
#!/bin/bash
function llama_init_environment {
# if conf does not exist, create it
if [ ! -f "$HOME/.config/llama/llama-main.conf" ]; then
mkdir -p "$HOME/.config/llama"
cat <<EOF > "$HOME/.config/llama/llama-main.conf"
LLAMA_TEMPERATURE=0.1
LLAMA_CONTEXT_SIZE=4096
LLAMA_REPETITION_PENALTY=1.15
LLAMA_TOP_P=0.9
LLAMA_TOP_K=20
LLAMA_TEMPLATE=chatml
LLAMA_MODEL_NAME=teknium/OpenHermes-2.5-Mistral-7B/openhermes-2.5-mistral-7b-f16.gguf
LLAMA_MODELS_PATH=$HOME/.ai/models/llama
LLAMA_PROMPT_PATH=$HOME/.local/share/llama/prompts
LLAMA_CACHE_PATH=$HOME/.cache/llama
EOF
fi
source $HOME/.config/llama/llama-main.conf
if [ ! -d "$LLAMA_CACHE_PATH" ]; then
mkdir -p "$LLAMA_CACHE_PATH"
fi
}
function llama_interactive {
# if 4 arguments are provided...
if [[ $# -eq 4 ]]; then
LLAMA_MODEL_NAME=$1
LLAMA_TEMPLATE=$2
LLAMA_CONTEXT_SIZE=$3
LLAMA_TEMPERATURE=$4
fi
# if fewer than 4 arguments - but greater than 0 - are provided, then display error message
if [[ $# -lt 4 ]] && [[ $# -gt 0 ]]; then
echo "Error: 4 arguments are required."
echo "Usage: llama <model_name> <template> <context_size> <temperature>"
echo "Example: llama teknium/OpenHermes-2.5-Mistral-7B/openhermes-2.5-mistral-7b-f16.gguf chatml 4096 0.1"
return
fi
llama \
--n-gpu-layers 1 \
--model "$LLAMA_MODELS_PATH/$LLAMA_MODEL_NAME" \
--prompt-cache "$LLAMA_CACHE_PATH/${LLAMA_MODEL_NAME//[\/\.]/-}-${LLAMA_CONTEXT_SIZE}.cache" \
--file "$(get_model_prompt $LLAMA_MODEL_NAME)" \
--in-prefix "$(get_model_prefix $LLAMA_TEMPLATE)" \
--in-suffix "$(get_model_suffix $LLAMA_TEMPLATE)" \
--reverse-prompt "$(get_model_prefix $LLAMA_TEMPLATE)" \
--reverse-prompt "<|im_end|>" \
--threads "6" \
--temp "$LLAMA_TEMPERATURE" \
--top-p "$LLAMA_TOP_P" \
--top-k "$LLAMA_TOP_K" \
--repeat-penalty "$LLAMA_REPETITION_PENALTY" \
--ctx-size "$LLAMA_CONTEXT_SIZE" \
--batch-size 1024 \
--n-predict -1 \
--keep -1 \
--instruct \
--no-mmap \
--color \
--escape \
--log-disable
}
function get_model_prefix {
case $1 in
*guanaco*)
printf "### Human: "
;;
*alpaca*|*upstage*|*airoboros*|*hermes*)
printf "### Instruction: "
;;
*vicuna*|*wizardlm*|*samantha*)
printf "USER: "
;;
*based*|*yi*)
printf "Human: "
;;
*orca*)
printf "### User: "
;;
chatml)
printf "<|im_start|>user\\\n"
;;
*)
printf "Input: "
;;
esac
}
function get_model_suffix {
case $1 in
*guanaco*)
printf "### Assistant: "
;;
*alpaca*|*upstage*|*airoboros*|*hermes*)
printf "### Response: "
;;
*vicuna*|*wizardlm*|*samantha*)
printf "ASSISTANT: "
;;
*based*|*yi*)
printf "Assistant: "
;;
*orca*)
printf "### Response: "
;;
chatml)
printf "<|im_end|>\n<|im_start|>assistant\\\n"
;;
*)
printf "Output: "
;;
esac
}
function get_model_prompt {
case $1 in
*guanaco*)
echo "$LLAMA_PROMPT_PATH/guanaco.txt"
;;
*alpaca*|*upstage*|*airoboros*|*hermes*)
echo "$LLAMA_PROMPT_PATH/alpaca.txt"
;;
*vicuna*|*wizardlm*|*samantha*)
echo "$LLAMA_PROMPT_PATH/vicuna-v11.txt"
;;
*based*|*yi*)
echo "$LLAMA_PROMPT_PATH/based.txt"
;;
*orca*)
echo "$LLAMA_PROMPT_PATH/orca.txt"
;;
*)
echo "$LLAMA_PROMPT_PATH/idm-gpt-lite.txt"
;;
esac
}
llama_init_environment
llama_interactive $*
|