#!/bin/bash # pi-setup.sh: build Unsloth's llama.cpp "b12572-mix-8eebad4" on a Raspberry Pi 5 (Cortex-A76, NEON + dotprod), CPU only. # The fork's tag only holds the CI tooling; the mix tree is upstream b12572 (652d559ed) + 30 pinned PR commits that the # fork mirrors under refs/pins/. This script rebuilds that tree exactly like the PC copy (same order, same pins). # Needs: git cmake ninja-build (or make) g++ libgomp (apt install git cmake ninja-build build-essential python3). # Usage: ./pi-setup.sh [dest_dir] (pins-b12572.txt must sit next to this script) set -euo pipefail HERE=$(cd "$(dirname "$0")" && pwd) DEST=${1:-$HOME/llama.cpp-inkling} BASE=652d559edf278347160baeb91ab654ac57ac429e # upstream b12572 (rev-list --count = 12572) PINS=$HERE/pins-b12572.txt [ -f "$PINS" ] || { echo "missing $PINS" >&2; exit 1; } if [ ! -d "$DEST/.git" ]; then git clone --filter=blob:none https://github.com/unslothai/llama.cpp "$DEST" fi cd "$DEST" git fetch -q --no-tags origin $(awk '{print "refs/pins/"$3":refs/pins/"$3}' "$PINS") git fetch -q origin "refs/tags/b12572-mix-8eebad4:refs/tags/b12572-mix-8eebad4" US=$(mktemp -d); git archive b12572-mix-8eebad4 scripts/unsloth | tar -x -C "$US" git checkout -q --detach $BASE git switch -q -C mix-b12572-8eebad4 while read -r SRC NUM SHA; do if ! git -c user.name=local -c user.email=local@localhost -c merge.conflictStyle=diff3 \ merge -q --no-ff --no-edit -m "Merge ${SRC}#${NUM} @ ${SHA}" "$SHA" /dev/null 2>&1; then if python3 -I "$US/scripts/unsloth/additive_merge.py" /dev/null 2>&1 && [ -z "$(git diff --name-only --diff-filter=U)" ]; then git -c user.name=local -c user.email=local@localhost commit -q --no-edit; echo "additive ${SRC}#${NUM}" else git merge --abort; echo "FAIL ${SRC}#${NUM}" >&2; exit 1 fi else echo "ok ${SRC}#${NUM}"; fi done < "$PINS" T=$(git rev-parse HEAD^{tree}); R=$(cat "$HERE/mix-tree.txt" 2>/dev/null || echo n/a) echo "mix tree hash: $T (PC build: $R)"; [ "$T" = "$R" ] || echo "WARNING: source tree differs from the PC build" >&2 cmake -S . -B build-pi -G Ninja -DCMAKE_BUILD_TYPE=Release -DGGML_NATIVE=ON -DGGML_OPENMP=ON \ -DLLAMA_CURL=OFF -DLLAMA_BUILD_TESTS=OFF -DGGML_CUDA=OFF -DGGML_VULKAN=OFF cmake --build build-pi -j4 --target llama-cli llama-server llama-completion llama-bench llama-perplexity ./build-pi/bin/llama-cli --version