iandennismiller
commited on
Commit
•
8e4cb30
1
Parent(s):
41ab8d2
refactor
Browse files- bin/llama.sh +80 -98
bin/llama.sh
CHANGED
@@ -11,13 +11,16 @@ LLAMA_TOP_P=0.9
|
|
11 |
LLAMA_TOP_K=20
|
12 |
LLAMA_TEMPLATE=chatml
|
13 |
LLAMA_MODEL_NAME=teknium/OpenHermes-2.5-Mistral-7B/openhermes-2.5-mistral-7b-f16.gguf
|
|
|
|
|
|
|
14 |
EOF
|
15 |
fi
|
16 |
|
17 |
function llama_interactive {
|
18 |
source $HOME/.config/llama/llama-main.conf
|
19 |
|
20 |
-
# if arguments are provided...
|
21 |
if [[ $# -eq 4 ]]; then
|
22 |
LLAMA_MODEL_NAME=$1
|
23 |
LLAMA_TEMPLATE=$2
|
@@ -25,10 +28,18 @@ function llama_interactive {
|
|
25 |
LLAMA_TEMPERATURE=$4
|
26 |
fi
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
llama \
|
29 |
--n-gpu-layers 1 \
|
30 |
-
--model "$
|
31 |
-
--prompt-cache "$
|
32 |
--file "$(get_model_prompt $LLAMA_MODEL_NAME)" \
|
33 |
--in-prefix "$(get_model_prefix $LLAMA_TEMPLATE)" \
|
34 |
--in-suffix "$(get_model_suffix $LLAMA_TEMPLATE)" \
|
@@ -49,108 +60,79 @@ function llama_interactive {
|
|
49 |
--escape
|
50 |
}
|
51 |
|
52 |
-
function model_path {
|
53 |
-
MODEL_NAME=$1
|
54 |
-
echo "$HOME/.ai/models/llama/${MODEL_NAME}"
|
55 |
-
}
|
56 |
-
|
57 |
-
function cache_path {
|
58 |
-
MODEL_NAME=$1
|
59 |
-
echo "$HOME/.ai/cache/menu-${MODEL_NAME//\//_}.cache"
|
60 |
-
}
|
61 |
-
|
62 |
function get_model_prefix {
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
elif [[ $TEMPLATE_NAME == "chatml" ]]; then
|
87 |
-
printf "<|im_start|>user\\\n"
|
88 |
-
else
|
89 |
-
printf "Input: "
|
90 |
-
fi
|
91 |
}
|
92 |
|
93 |
-
# USER: hello, who are you? ASSISTANT:
|
94 |
-
|
95 |
function get_model_suffix {
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
elif [[ $TEMPLATE_NAME == "chatml" ]]; then
|
120 |
-
printf "<|im_end|>\n<|im_start|>assistant\\\n"
|
121 |
-
else
|
122 |
-
printf "Output: "
|
123 |
-
fi
|
124 |
}
|
125 |
|
126 |
function get_model_prompt {
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
elif [[ $MODEL_NAME == *"wizardlm"* ]]; then
|
148 |
-
echo "$HOME/.local/share/llama/prompts/wizardlm-30b.txt"
|
149 |
-
elif [[ $MODEL_NAME == *"orca"* ]]; then
|
150 |
-
echo "$HOME/.local/share/llama/prompts/orca.txt"
|
151 |
-
else
|
152 |
-
echo "$HOME/.local/share/llama/prompts/idm-gpt-lite.txt"
|
153 |
-
fi
|
154 |
}
|
155 |
|
156 |
llama_interactive $*
|
|
|
11 |
LLAMA_TOP_K=20
|
12 |
LLAMA_TEMPLATE=chatml
|
13 |
LLAMA_MODEL_NAME=teknium/OpenHermes-2.5-Mistral-7B/openhermes-2.5-mistral-7b-f16.gguf
|
14 |
+
LLAMA_MODELS_PATH=$HOME/.ai/models/llama
|
15 |
+
LLAMA_PROMPT_PATH=$HOME/.local/share/llama/prompts
|
16 |
+
LLAMA_CACHE_PATH=$HOME/.local/share/llama/cache
|
17 |
EOF
|
18 |
fi
|
19 |
|
20 |
function llama_interactive {
|
21 |
source $HOME/.config/llama/llama-main.conf
|
22 |
|
23 |
+
# if 4 arguments are provided...
|
24 |
if [[ $# -eq 4 ]]; then
|
25 |
LLAMA_MODEL_NAME=$1
|
26 |
LLAMA_TEMPLATE=$2
|
|
|
28 |
LLAMA_TEMPERATURE=$4
|
29 |
fi
|
30 |
|
31 |
+
# if fewer than 4 arguments - but greater than 0 - are provided, then display error message
|
32 |
+
if [[ $# -lt 4 ]] && [[ $# -gt 0 ]]; then
|
33 |
+
echo "Error: 4 arguments are required."
|
34 |
+
echo "Usage: llama <model_name> <template> <context_size> <temperature>"
|
35 |
+
echo "Example: llama teknium/OpenHermes-2.5-Mistral-7B/openhermes-2.5-mistral-7b-f16.gguf chatml 4096 0.1"
|
36 |
+
return
|
37 |
+
fi
|
38 |
+
|
39 |
llama \
|
40 |
--n-gpu-layers 1 \
|
41 |
+
--model "$LLAMA_MODELS_PATH/$LLAMA_MODEL_NAME" \
|
42 |
+
--prompt-cache "$LLAMA_CACHE_PATH/$LLAMA_MODEL_NAME" \
|
43 |
--file "$(get_model_prompt $LLAMA_MODEL_NAME)" \
|
44 |
--in-prefix "$(get_model_prefix $LLAMA_TEMPLATE)" \
|
45 |
--in-suffix "$(get_model_suffix $LLAMA_TEMPLATE)" \
|
|
|
60 |
--escape
|
61 |
}
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
function get_model_prefix {
|
64 |
+
case $1 in
|
65 |
+
*guanaco*)
|
66 |
+
printf "### Human: "
|
67 |
+
;;
|
68 |
+
*alpaca*|*upstage*|*airoboros*|*hermes*)
|
69 |
+
printf "### Instruction: "
|
70 |
+
;;
|
71 |
+
*vicuna*|*wizardlm*|*samantha*)
|
72 |
+
printf "USER:"
|
73 |
+
;;
|
74 |
+
*based*|*yi*)
|
75 |
+
printf "Human:"
|
76 |
+
;;
|
77 |
+
*orca*)
|
78 |
+
printf "### User: "
|
79 |
+
;;
|
80 |
+
chatml)
|
81 |
+
printf "<|im_start|>user\\\n"
|
82 |
+
;;
|
83 |
+
*)
|
84 |
+
printf "Input: "
|
85 |
+
;;
|
86 |
+
esac
|
|
|
|
|
|
|
|
|
|
|
87 |
}
|
88 |
|
|
|
|
|
89 |
function get_model_suffix {
|
90 |
+
case $1 in
|
91 |
+
*guanaco*)
|
92 |
+
printf "### Assistant: "
|
93 |
+
;;
|
94 |
+
*alpaca*|*upstage*|*airoboros*|*hermes*)
|
95 |
+
printf "### Response: "
|
96 |
+
;;
|
97 |
+
*vicuna*|*wizardlm*|*samantha*)
|
98 |
+
printf "ASSISTANT:"
|
99 |
+
;;
|
100 |
+
*based*|*yi*)
|
101 |
+
printf "Assistant:"
|
102 |
+
;;
|
103 |
+
*orca*)
|
104 |
+
printf "### Response: "
|
105 |
+
;;
|
106 |
+
chatml)
|
107 |
+
printf "<|im_end|>\n<|im_start|>assistant\\\n"
|
108 |
+
;;
|
109 |
+
*)
|
110 |
+
printf "Output: "
|
111 |
+
;;
|
112 |
+
esac
|
|
|
|
|
|
|
|
|
|
|
113 |
}
|
114 |
|
115 |
function get_model_prompt {
|
116 |
+
case $1 in
|
117 |
+
*guanaco*)
|
118 |
+
echo "$LLAMA_PROMPT_PATH/guanaco.txt"
|
119 |
+
;;
|
120 |
+
*alpaca*|*upstage*|*airoboros*|*hermes*)
|
121 |
+
echo "$LLAMA_PROMPT_PATH/alpaca.txt"
|
122 |
+
;;
|
123 |
+
*vicuna*|*wizardlm*|*samantha*)
|
124 |
+
echo "$LLAMA_PROMPT_PATH/vicuna-v11.txt"
|
125 |
+
;;
|
126 |
+
*based*|*yi*)
|
127 |
+
echo "$LLAMA_PROMPT_PATH/based.txt"
|
128 |
+
;;
|
129 |
+
*orca*)
|
130 |
+
echo "$LLAMA_PROMPT_PATH/orca.txt"
|
131 |
+
;;
|
132 |
+
*)
|
133 |
+
echo "$LLAMA_PROMPT_PATH/idm-gpt-lite.txt"
|
134 |
+
;;
|
135 |
+
esac
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
}
|
137 |
|
138 |
llama_interactive $*
|