Add build script
Browse files
build.sh
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Builds koboldcpp's CUDA backend from a release tag with machine code for the GPUs storiesbyme rents, and uploads
|
| 3 |
+
# the result to a Hugging Face repo. The pod image downloads that tarball instead of compiling (gpu-image/Dockerfile).
|
| 4 |
+
# Runs as a Hugging Face Job inside nvidia/cuda:<version>-devel-ubuntu22.04; see README.md for the command.
|
| 5 |
+
# Env: KCPP_VERSION (e.g. 1.121), HF_REPO (e.g. user/repo), HF_TOKEN (write access; pass as a Job secret).
|
| 6 |
+
set -euo pipefail
|
| 7 |
+
: "${KCPP_VERSION:?}" "${HF_REPO:?}" "${HF_TOKEN:?}"
|
| 8 |
+
NAME="koboldcpp-${KCPP_VERSION}-cu12-sm86-sm89"
|
| 9 |
+
JOBS="${CPU_CORES:-}"; JOBS="${JOBS%%[!0-9]*}"; JOBS="${JOBS:-$(nproc)}" # nproc reports the host's cores
|
| 10 |
+
log() { echo "[$(date -u +%H:%M:%S)] $*"; }
|
| 11 |
+
|
| 12 |
+
export DEBIAN_FRONTEND=noninteractive
|
| 13 |
+
apt-get update -qq && apt-get install -y -qq --no-install-recommends git ca-certificates python3-pip binutils >/dev/null
|
| 14 |
+
nvcc --version | tail -2; gcc --version | head -1
|
| 15 |
+
git clone -q --depth 1 --branch "v${KCPP_VERSION}" https://github.com/LostRuins/koboldcpp /src
|
| 16 |
+
cd /src
|
| 17 |
+
log "source: $(git log --oneline -1)"
|
| 18 |
+
|
| 19 |
+
# The release compiles its GPU code with `code=compute_NN`, which emits only PTX (portable intermediate code), so the
|
| 20 |
+
# NVIDIA driver has to compile it on a pod's first launch: about 55 s per model. `code=sm_NN` emits machine code.
|
| 21 |
+
# Targets: sm_86 (A40, RTX A6000), sm_89 (L40, L40S, RTX 6000 Ada), and compute_80 PTX as the fallback for other cards.
|
| 22 |
+
CU12='/^else ifdef LLAMA_ARCHES_CU12/,/KCPP_LIMIT_CUDA_MAX_ARCH=800/'
|
| 23 |
+
sed -i "${CU12}{/compute_50\|compute_61\|compute_75/d; s|code=compute_80 |code=compute_80 -gencode arch=compute_86,code=sm_86 -gencode arch=compute_89,code=sm_89 |}" Makefile
|
| 24 |
+
sed -n "${CU12}p" Makefile | tee /tmp/BUILD_FLAGS
|
| 25 |
+
[ "$(grep -c gencode /tmp/BUILD_FLAGS)" = 1 ] && grep -q 'code=sm_86 .*code=sm_89' /tmp/BUILD_FLAGS \
|
| 26 |
+
|| { echo "Makefile no longer has the CUDA 12 flag block this script edits"; exit 1; }
|
| 27 |
+
|
| 28 |
+
TOTAL=$(make -n LLAMA_CUBLAS=1 LLAMA_PORTABLE=1 LLAMA_ARCHES_CU12=1 koboldcpp_cublas 2>/dev/null | grep -cE ' -c ' || true)
|
| 29 |
+
log "building with -j$JOBS, about $TOTAL files to compile"
|
| 30 |
+
( while sleep 60; do log "PROGRESS $(find . -name '*.o' | wc -l)/$TOTAL files"; done ) &
|
| 31 |
+
PROGRESS_PID=$!
|
| 32 |
+
make -j"$JOBS" LLAMA_CUBLAS=1 LLAMA_PORTABLE=1 LLAMA_ARCHES_CU12=1 koboldcpp_cublas > /tmp/make.log 2>&1 \
|
| 33 |
+
|| { kill $PROGRESS_PID; tail -60 /tmp/make.log; exit 1; }
|
| 34 |
+
kill $PROGRESS_PID
|
| 35 |
+
log "build done: $(ls -la koboldcpp_cublas.so)"
|
| 36 |
+
log "PTX targets in the library: $(strings -n 6 koboldcpp_cublas.so | grep -oE '^\.target sm_[0-9]+' | sort -u | tr '\n' ' ')"
|
| 37 |
+
|
| 38 |
+
# The same files the release's PyInstaller bundle carries, minus the non-CUDA backends.
|
| 39 |
+
mkdir -p /out/koboldcpp
|
| 40 |
+
cp -r koboldcpp.py json_to_gbnf.py kcpp_adapters embd_res koboldcpp_cublas.so \
|
| 41 |
+
LICENSE.md MIT_LICENSE_GGML_SDCPP_LLAMACPP_ONLY.md /out/koboldcpp/
|
| 42 |
+
git rev-parse HEAD > /out/koboldcpp/SOURCE_COMMIT
|
| 43 |
+
cp /tmp/BUILD_FLAGS /out/koboldcpp/BUILD_FLAGS
|
| 44 |
+
tar -C /out -czf "/out/$NAME.tar.gz" koboldcpp
|
| 45 |
+
( cd /out && sha256sum "$NAME.tar.gz" | tee "$NAME.tar.gz.sha256" )
|
| 46 |
+
ls -la /out
|
| 47 |
+
|
| 48 |
+
pip3 install -q huggingface_hub
|
| 49 |
+
hf upload "$HF_REPO" "/out/$NAME.tar.gz" "$NAME.tar.gz" --commit-message "koboldcpp $KCPP_VERSION, CUDA 12, sm_86 + sm_89"
|
| 50 |
+
hf upload "$HF_REPO" "/out/$NAME.tar.gz.sha256" "$NAME.tar.gz.sha256" --commit-message "checksum for $NAME"
|
| 51 |
+
log "UPLOAD_DONE $NAME.tar.gz"
|