File size: 3,082 Bytes
2c20074
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""Vendor the minimal llama.cpp file set this port needs into `vendor/`, so the package is
self-contained (a hub `kernels` build cannot clone at build time).

The file list is the exact transitive dependency set of our three sources, obtained from the
build with:

    cd build && ninja -t deps | grep -oE '/[^ ]*llama\\.cpp/ggml/[^ ]*\\.(cu|cuh|h)'

Re-run this script after bumping the upstream pin; if upstream adds an include, the build fails
loudly with a missing header rather than silently using a stale copy.

Usage: python vendor.py [--src /path/to/llama.cpp] [--rev <git rev>]
"""

import argparse
import os
import shutil
import subprocess

HERE = os.path.dirname(os.path.abspath(__file__))
VENDOR = os.path.join(HERE, "vendor")

FILES = [
    "include/ggml-alloc.h",
    "include/ggml-backend.h",
    "include/ggml-cuda.h",
    "include/ggml.h",
    "include/gguf.h",
    "src/ggml-common.h",
    "src/ggml-impl.h",
    "src/ggml-cuda/common.cuh",
    "src/ggml-cuda/convert.cu",
    "src/ggml-cuda/convert.cuh",
    "src/ggml-cuda/dequantize.cuh",
    "src/ggml-cuda/mma.cuh",
    "src/ggml-cuda/mmq-config-ampere.cuh",
    "src/ggml-cuda/mmq-config-blackwell.cuh",
    "src/ggml-cuda/mmq-config-cdna.cuh",
    "src/ggml-cuda/mmq-config-pascal.cuh",
    "src/ggml-cuda/mmq-config-rdna2.cuh",
    "src/ggml-cuda/mmq-config-rdna3-5.cuh",
    "src/ggml-cuda/mmq-config-rdna3.cuh",
    "src/ggml-cuda/mmq-config-rdna4.cuh",
    "src/ggml-cuda/mmq-load-tiles.cuh",
    "src/ggml-cuda/mmq-vec-dot.cuh",
    "src/ggml-cuda/mmq.cuh",
    "src/ggml-cuda/mmvq.cu",
    "src/ggml-cuda/mmvq.cuh",
    "src/ggml-cuda/mmvf.cu",
    "src/ggml-cuda/mmvf.cuh",
    "src/ggml-cuda/quantize.cu",
    "src/ggml-cuda/quantize.cuh",
    "src/ggml-cuda/unary.cuh",
    "src/ggml-cuda/vecdotq.cuh",
    "src/ggml-cuda/vendors/cuda.h",
]


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--src", default=os.environ.get("LLAMA_CPP_SRC", os.path.join(HERE, "llama.cpp")))
    ap.add_argument("--rev", default=None, help="git rev to check out before copying")
    args = ap.parse_args()

    if not os.path.isdir(args.src):
        subprocess.run(
            ["git", "clone", "https://github.com/ggml-org/llama.cpp.git", args.src], check=True
        )
    if args.rev:
        subprocess.run(["git", "-C", args.src, "checkout", args.rev], check=True)

    rev = subprocess.run(
        ["git", "-C", args.src, "rev-parse", "HEAD"], capture_output=True, text=True, check=True
    ).stdout.strip()

    if os.path.isdir(VENDOR):
        shutil.rmtree(VENDOR)
    for rel in FILES:
        dst = os.path.join(VENDOR, rel)
        os.makedirs(os.path.dirname(dst), exist_ok=True)
        shutil.copy2(os.path.join(args.src, "ggml", rel), dst)

    with open(os.path.join(VENDOR, "UPSTREAM"), "w") as f:
        f.write(f"https://github.com/ggml-org/llama.cpp\n{rev}\n")
    shutil.copy2(os.path.join(args.src, "LICENSE"), os.path.join(VENDOR, "LICENSE"))

    print(f"vendored {len(FILES)} files from llama.cpp @ {rev[:12]} into {VENDOR}")


if __name__ == "__main__":
    main()