Skip to content

Instantly share code, notes, and snippets.

@lukehinds
Created July 19, 2023 14:28
Show Gist options
  • Save lukehinds/40efac3f6976a50c6334ca05c183d369 to your computer and use it in GitHub Desktop.
Save lukehinds/40efac3f6976a50c6334ca05c183d369 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Default values
MODEL="llama-2-13b-chat.ggmlv3.q4_0.bin"
THREADS=8
NGL=1
COLOR="--color"
C_FLAG=2048
TEMP=0.7
REPEAT_PENALTY=1.1
N_FLAG=-1
# Function to display help menu
function display_help() {
echo "Usage: $0 [options]"
echo " Options:"
echo " --model specify the model name (default: llama-2-13b-chat.ggmlv3.q4_0.bin)"
echo " --threads specify the number of threads (default: 8)"
echo " --ngl specify the ngl (default: 1)"
echo " --color specify the color (default: --color)"
echo " -c specify the c flag (default: 2048)"
echo " --temp specify the temp (default: 0.7)"
echo " --repeat_penalty specify the repeat_penalty (default: 1.1)"
echo " -n specify the n flag (default: -1)"
echo " -h, --help display this help and exit"
exit 1
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--model)
MODEL="$2"
shift # past argument
shift # past value
;;
--threads)
THREADS="$2"
shift
shift
;;
--ngl)
NGL="$2"
shift
shift
;;
--color)
COLOR="$2"
shift
shift
;;
-c)
C_FLAG="$2"
shift
shift
;;
--temp)
TEMP="$2"
shift
shift
;;
--repeat_penalty)
REPEAT_PENALTY="$2"
shift
shift
;;
-n)
N_FLAG="$2"
shift
shift
;;
-h|--help)
display_help
shift # past argument
;;
*) # unknown option
shift # past argument
;;
esac
done
REPO_URL="https://github.com/ggerganov/llama.cpp.git"
MODEL_URL="https://huggingface.co/TheBloke/Llama-2-13B-chat-GGML/resolve/main/${MODEL}"
# Check if llama.cpp directory already exists
if [ -d "llama.cpp" ]; then
echo "Directory llama.cpp already exists. Pulling the latest changes..."
cd llama.cpp
git pull
else
echo "Cloning llama.cpp..."
git clone ${REPO_URL}
cd llama.cpp
fi
# Build it
echo "Building the project..."
LLAMA_METAL=1 make
# Check if model already exists
if [ -f "${MODEL}" ]; then
echo "Model ${MODEL} already exists."
else
echo "Downloading the model..."
wget -q --show-progress ${MODEL_URL}
fi
# Run the program
while true; do
read -p "Enter your prompt (or 'exit' to quit): " PROMPT
if [ "$PROMPT" == "exit" ]; then
echo "Exiting the program."
break
fi
./main \
-t ${THREADS} \
-ngl ${NGL} \
-m ${MODEL} \
${COLOR} \
-c ${C_FLAG} \
--temp ${TEMP} \
--repeat_penalty ${REPEAT_PENALTY} \
-n ${N_FLAG} \
-p "${PROMPT}"
done
@jonathanhawleypeters
Copy link

why wget over curl?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment