File size: 1,490 Bytes
0039a57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
#
# One-click build of llama.cpp with openPangu-R-7B-Diffusion support.
#
#   ./build_llamacpp_pangu_diffusion.sh
#
# It will:
#   1. clone llama.cpp at the pinned release tag
#   2. download and apply the openPangu-R-Diffusion patch
#   3. build llama-diffusion-cli / llama-cli / llama-quantize
#
# Requirements: git, cmake >= 3.14, a C/C++ toolchain, and (optionally) an NVIDIA GPU.
#
set -euo pipefail

LLAMA_TAG="b11719"
PATCH_URL="https://huggingface.co/HelloSun/openPangu-R-7B-Diffusion-Q4KM/resolve/main/pangu-diffusion-llamacpp.patch"
WORKDIR="${WORKDIR:-$PWD/pangu-diffusion-build}"

mkdir -p "$WORKDIR"
cd "$WORKDIR"

if [ ! -d llama.cpp ]; then
    echo ">>> cloning llama.cpp ($LLAMA_TAG) ..."
    git clone --depth 1 --branch "$LLAMA_TAG" https://github.com/ggml-org/llama.cpp.git
fi

cd llama.cpp
git checkout -- . 2>/dev/null || true

echo ">>> downloading patch ..."
curl -L --fail -o pangu-diffusion-llamacpp.patch "$PATCH_URL"

echo ">>> applying patch ..."
git apply pangu-diffusion-llamacpp.patch

echo ">>> configuring ..."
if command -v nvcc >/dev/null 2>&1; then
    cmake -B build -DGGML_CUDA=ON -DLLAMA_CURL=OFF
else
    cmake -B build -DGGML_NATIVE=ON -DLLAMA_CURL=OFF
fi

echo ">>> building ..."
cmake --build build --config Release -j"$(nproc)" --target llama-diffusion-cli llama-cli llama-quantize

echo
echo ">>> done. binaries:"
echo "    $WORKDIR/llama.cpp/build/bin/llama-diffusion-cli"
echo "    $WORKDIR/llama.cpp/build/bin/llama-cli"