Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "modules/llama.cpp"]
path = modules/llama.cpp
url = https://github.com/gkielian/llama.cpp.git
25 changes: 25 additions & 0 deletions data_augmentation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Running Mistral 7B Test

Scripts here download and test the Mistral 7B model with a python wrapper for
`llama.cpp` called `llama-cpp-python`.

## Install Steps

1. First install the nanogpt requirements (see main [README.md](../README.md))
2. Second install `llama-cpp-python` and dependencies via the installation
script provided in the repo root directory:

```bash
bash install_llama_cpp_python.sh
```
3. Finally cd into this directory and run the `download_and_test_mistral.sh`
script via sourcing (b/c will need one's python environment):

```bash
source download_and_test_mistral7b.sh
```

This script will download mistral7b if not already in the `./models` directory,
and start the `llama-cpp-python_example.py` script.

This will should complete fairly quickly with GPU acceleration.
17 changes: 17 additions & 0 deletions data_augmentation/download_and_test_mistral7b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# This script will downlaod and test Mistral7B using llama-cpp-python

if [ -d ./models ]; then
mkdir -p ./models
fi

if [ -f "./models/mistral-7b-instruct-v0.1.Q5_K_M.gguf" ]; then
echo "./models/mistral-7b-instruct-v0.1.Q5_K_M.gguf file found, continuing"
else
echo "./models/mistral-7b-instruct-v0.1.Q5_K_M.gguf file not found, downloading"
wget -P ./models https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q5_K_M.gguf
fi

python3 llama-cpp-python_example.py

12 changes: 12 additions & 0 deletions data_augmentation/llama-cpp-python_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from llama_cpp import Llama

text = """<s>[INST] What is your favourite condiment? [/INST]
Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!</s>
[INST] Do you have mayonnaise recipes? [/INST]"""

llm = Llama(model_path="./models/mistral-7b-instruct-v0.1.Q5_K_M.gguf", n_ctx=2048,
n_threads=8, n_gpu_layers=35, verbose=True)

output = llm(text, max_tokens=256, stop=["[INST]"], echo=True)

print(output)
67 changes: 67 additions & 0 deletions install_llama_cpp_python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

# Set strict error handling
set -euo pipefail

# Get current script directory
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"

echo "This script will install llama-cpp-python with GPU support"

# Check if llama module exists, prompt to initialize submodule
if [ ! -d "$script_dir/modules/llama.cpp" ]; then

read -p "llama.cpp module not found. Download with git? [Y/n] " response

response=${response,,}

if [ "$response" != "n" ]; then

# Initialize llama submodule
git submodule update --init --recursive

else

echo "Exiting. llama.cpp module required."
exit 1

fi

fi

read -p "Enter CUDA install location (default /usr/local/cuda): " cuda_home

cuda_home=${cuda_home:-/usr/local/cuda}

if [ ! -d "$cuda_home" ]; then
echo "Error: $cuda_home is not a valid directory"
exit 1
fi

read -p "Append CUDA settings to ~/.bashrc? [Y/n] " response

response=${response,,}

if [ "$response" != "n" ]; then

echo "export CUDA_HOME=$cuda_home" >> ~/.bashrc
echo "export PATH=\"$cuda_home/bin:\$PATH\"" >> ~/.bashrc
echo "export LLAMA_CUBLAS=on" >> ~/.bashrc
echo "export LLAMA_CPP_LIB=\"$script_dir/modules/llama.cpp/libllama.so\"" >> ~/.bashrc

echo "Appended CUDA settings to ~/.bashrc"

fi

pushd "$script_dir/modules/llama.cpp"

make clean
make libllama.so || { echo "Error compiling llama.cpp"; exit 1; }

popd

export LLAMA_CPP_LIB="$script_dir/modules/llama.cpp/libllama.so"

CMAKE_ARGS="-DLLAMA_CUBLAS=on" python3 -m pip install llama-cpp-python --no-cache-dir

echo "llama-cpp-python installed successfully"
1 change: 1 addition & 0 deletions modules/llama.cpp
Submodule llama.cpp added at 48edda