Skip to content

Instantly share code, notes, and snippets.

@tgran2028
Created January 10, 2024 00:27
Show Gist options
  • Save tgran2028/1115036ad2c88e704c0975e7aae2a41d to your computer and use it in GitHub Desktop.
Save tgran2028/1115036ad2c88e704c0975e7aae2a41d to your computer and use it in GitHub Desktop.
Install gpt4all on Linux
#!/bin/bash
sudo apt update
sudo apt install -y glslc vulkan-tools vkroots-headers vulkan-validationlayers-dev spirv-cross cmake git
if [ -d ~/.local/gpt4all ] ; then
echo "gpt4all already installed"
exit 1
fi
DIR="$HOME/.local/gpt4all"
BUILD_DIR="$DIR/gpt4all-backend/build"
PY_BINDINGS_DIR="$DIR/gpt4all-bindings/python"
git clone --recurse-submodules https://github.com/nomic-ai/gpt4all.git "$DIR"
cd "$DIR/gpt4all-backend" || exit 1
mkdir -p "$BUILD_DIR" && cd "$BUILD_DIR" || exit 1
cmake ..
cmake --build . --parallel # optionally append: --config Release
# Confirm that libllmodel.* exists in gpt4all-backend/build.
if [ -z "$(ls libllmodel.* 2>/dev/null)" ] ; then
echo "libllmodel.* not found in gpt4all-backend/build"
exit 1
fi
cd "$PY_BINDINGS_DIR" || exit 1
python -m venv venv && source venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .
__test() {
local device
for device in gpu cpu nvidia amd intel ; do
printf "Testing GPT4All on %s...\n" "$device"
python -c "
import sys;
m = 'orca-mini-3b-gguf2-q4_0.gguf'
try:
from gpt4all import GPT4All
model = GPT4All(m, device='${device}', verbose=True)
output = model.generate('The capital of France is ', max_tokens=3)
print(output, file=sys.stdout);
sys.exit(0);
except Exception as e:
print(e, file=sys.stderr);
sys.exit(1);
";
if [ $? -ne 0 ] ; then
echo "Test failed on $device"
exit 1
else
echo "Test passed on $device"
fi
echo '----------------------------------------'
done
}
__test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment