File size: 4,632 Bytes
538ca27 7bde6da 538ca27 d443dcd 8e4cb30 7bde6da d443dcd 538ca27 7bde6da 538ca27 17a696b 7bde6da 8e4cb30 6cc9d7b 17a696b 6cc9d7b 17a696b 538ca27 8e4cb30 6cc9d7b 8e4cb30 6cc9d7b 8e4cb30 6cc9d7b 17a696b 538ca27 8e4cb30 7bde6da 17a696b 538ca27 2b59313 6cc9d7b 538ca27 17a696b 538ca27 7bde6da 6cc9d7b 538ca27 8e4cb30 6cc9d7b 904eb75 6cc9d7b 8e4cb30 6cc9d7b 8e4cb30 6cc9d7b 7bde6da 8e4cb30 538ca27 8e4cb30 6cc9d7b 904eb75 6cc9d7b 8e4cb30 6cc9d7b c454cdd 8e4cb30 6cc9d7b c454cdd 8e4cb30 6cc9d7b 8e4cb30 6cc9d7b 8e4cb30 6cc9d7b 8e4cb30 538ca27 8e4cb30 904eb75 7e54e16 8e4cb30 7e54e16 904eb75 8e4cb30 a7e8a57 904eb75 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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
#!/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_MODEL_NAME=teknium/OpenHermes-2.5-Mistral-7B/openhermes-2.5-mistral-7b-f16.gguf
LLAMA_TEMPLATE=chatml
LLAMA_MODELS_PATH=$HOME/.ai/models/llama
LLAMA_PROMPT_PATH=$HOME/.local/share/llama/prompts
LLAMA_CACHE_PATH=$HOME/.cache/llama
LLAMA_CONTEXT_SIZE=4096
LLAMA_TEMPERATURE=1.6
LLAMA_TOP_P=1.0
LLAMA_MIN_P=0.1
LLAMA_TOP_K=0
LLAMA_REPETITION_PENALTY=1.15
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 2 ]]; then
LLAMA_MODEL_NAME=$1
LLAMA_CONTEXT_SIZE=$2
fi
# if fewer than 4 arguments - but greater than 0 - are provided, then display error message
if [[ $# -lt 2 ]] && [[ $# -gt 0 ]]; then
echo "Error: 4 arguments are required."
echo "Usage: llama <model_name> <context_size>"
echo "Example: llama teknium/OpenHermes-2.5-Mistral-7B/openhermes-2.5-mistral-7b-f16.gguf 4096"
return
fi
LLAMA_TEMPLATE=$(get_template_for_model $LLAMA_MODEL_NAME)
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|>" \
--reverse-prompt "</s>" \
--threads 1 \
--temp 0 \
--top-p 1.0 \
--top-k 40 \
--min-p 0.5 \
--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
# --temp "$LLAMA_TEMPERATURE" \
# --top-p "$LLAMA_TOP_P" \
# --top-k "$LLAMA_TOP_K" \
# --min-p "$LLAMA_MIN_P" \
}
function get_model_prefix {
case $1 in
chatml)
printf "<|im_start|>user\\\n"
;;
instruct)
printf "[INST] "
;;
alpaca)
printf "### Instruction: "
;;
vicuna)
printf "USER: "
;;
*)
printf "Input: "
;;
esac
}
function get_model_suffix {
case $1 in
chatml)
printf "<|im_end|>\n<|im_start|>assistant\\\n"
;;
instruct)
printf " [/INST]"
;;
alpaca)
printf "### Response:"
;;
vicuna)
printf "ASSISTANT:"
;;
*)
printf "Output:"
;;
esac
}
function get_template_for_model {
case $1 in
*dolphin*)
echo "chatml"
;;
*mixtral-8x7b-instruct*)
echo "instruct"
;;
*upstage*|*airoboros*|*hermes*)
echo "alpaca"
;;
*wizardlm*|*samantha*|*scarlett*|*capybara*)
echo "vicuna"
;;
*)
echo "chatml"
;;
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"
;;
*dolphin*)
echo "$LLAMA_PROMPT_PATH/chatml-gpt.txt"
;;
*vicuna*|*wizardlm*)
echo "$LLAMA_PROMPT_PATH/vicuna-v11.txt"
;;
*scarlett*)
echo "$LLAMA_PROMPT_PATH/scarlett.txt"
;;
*samantha*)
echo "$LLAMA_PROMPT_PATH/samantha.txt"
;;
*based*)
echo "$LLAMA_PROMPT_PATH/based.txt"
;;
*capybara*)
echo "$LLAMA_PROMPT_PATH/capybara.txt"
;;
*yi*)
echo "$LLAMA_PROMPT_PATH/yi.txt"
;;
*orca*)
echo "$LLAMA_PROMPT_PATH/orca.txt"
;;
*)
echo "$LLAMA_PROMPT_PATH/idm-gpt-lite.txt"
;;
esac
}
llama_init_environment
llama_interactive $*
|