Skip to content

Instantly share code, notes, and snippets.

@WorldException
Created May 22, 2026 08:32
Show Gist options
  • Select an option

  • Save WorldException/b462785353f1c4a243174a618dde1243 to your computer and use it in GitHub Desktop.

Select an option

Save WorldException/b462785353f1c4a243174a618dde1243 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
echo "=== macOS llama.cpp Setup Script ==="
echo ""
# Check if Homebrew is installed
if ! command -v brew &> /dev/null; then
echo "Homebrew is not installed. Installing Homebrew..."
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | /bin/bash
echo "Homebrew installed successfully."
# Add brew to PATH for current session
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
else
echo "Homebrew is already installed."
fi
echo ""
#echo "Updating Homebrew..."
#brew update
# Install Git if needed
echo ""
if ! command -v git &> /dev/null; then
echo "Git is not installed. Installing Git..."
brew install git
echo "Git installed successfully."
else
echo "Git is already installed."
fi
# Install CMake if needed
echo ""
if ! command -v cmake &> /dev/null; then
echo "CMake is not installed. Installing CMake..."
brew install cmake
echo "CMake installed successfully."
else
echo "CMake is already installed."
fi
# Clone llama.cpp
echo ""
LLAMA_CPP_DIR="llama.cpp"
if [ -d "$LLAMA_CPP_DIR" ]; then
echo "llama.cpp directory already exists. Pulling latest changes..."
cd "$LLAMA_CPP_DIR"
git pull
cd ..
else
echo "Cloning llama.cpp repository..."
git clone https://github.com/ggml-org/llama.cpp.git
fi
# Build llama.cpp using CMake
echo ""
echo "Building llama.cpp with CMake..."
cd llama.cpp
rm -rf build
cmake -B . -DGGML_NATIVE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release
cmake --build . -j8 --target llama-server llama-bench
cd ..
echo ""
echo "=== Build Complete ==="
echo ""
# Download model and run llama-bench
echo "Downloading model: unsloth/qwen3.5-4b (UD-Q4_K_XL)..."
MODEL_URL="https://huggingface.co/unsloth/Qwen3.5-4B-GGUF/resolve/main/Qwen3.5-4B-UD-Q4_K_XL.gguf?download=true"
MODEL_FILE="qwen3.5-4b-UD-Q4_K_XL.gguf"
if [ ! -f "$MODEL_FILE" ]; then
echo "Downloading model..."
if ! curl -L -o "$MODEL_FILE" "$MODEL_URL"; then
echo "Error: Failed to download model from $MODEL_URL"
exit 1
fi
echo "Model downloaded successfully."
else
echo "Model file already exists."
fi
echo ""
echo "Running llama-bench..."
cd llama.cpp/bin
./llama-bench -m ../../$MODEL_FILE
cd ../..
echo ""
echo "=== Setup and Benchmark Complete ==="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment