-
Notifications
You must be signed in to change notification settings - Fork 984
/
sync-llama-am.sh
executable file
·183 lines (159 loc) · 6.09 KB
/
sync-llama-am.sh
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
#
# Synchronize llama.cpp changes to ggml
#
# Usage:
#
# $ cd /path/to/ggml
# $ ./scripts/sync-llama-am.sh -skip hash0,hash1,hash2...
#
set -e
sd=$(dirname $0)
cd $sd/../
SRC_GGML=$(pwd)
SRC_LLAMA=$(cd ../llama.cpp; pwd)
if [ ! -d $SRC_LLAMA ]; then
echo "llama.cpp not found at $SRC_LLAMA"
exit 1
fi
lc=$(cat $SRC_GGML/scripts/sync-llama.last)
echo "Syncing llama.cpp changes since commit $lc"
to_skip=""
if [ "$1" == "-skip" ]; then
to_skip=$2
fi
cd $SRC_LLAMA
git log --oneline $lc..HEAD
git log --oneline $lc..HEAD --reverse | grep -v "(ggml/[0-9]*)" | grep -v "(whisper/[0-9]*)" | cut -d' ' -f1 > $SRC_GGML/llama-commits
if [ ! -s $SRC_GGML/llama-commits ]; then
rm -v $SRC_GGML/llama-commits
echo "No new commits"
exit 0
fi
if [ -f $SRC_GGML/llama-src.patch ]; then
rm -v $SRC_GGML/llama-src.patch
fi
while read c; do
if [ -n "$to_skip" ]; then
if [[ $to_skip == *"$c"* ]]; then
echo "Skipping $c"
continue
fi
fi
git format-patch -k $c~1..$c --stdout -- \
ggml*.h \
ggml*.c \
ggml*.cpp \
ggml*.m \
ggml*.metal \
ggml*.cu \
ggml-cuda/* \
ggml-sycl/* \
tests/test-opt.cpp \
tests/test-grad0.cpp \
tests/test-quantize-fns.cpp \
tests/test-quantize-perf.cpp \
tests/test-backend-ops.cpp \
LICENSE \
scripts/gen-authors.sh \
>> $SRC_GGML/llama-src.patch
done < $SRC_GGML/llama-commits
rm -v $SRC_GGML/llama-commits
# delete files if empty
if [ ! -s $SRC_GGML/llama-src.patch ]; then
rm -v $SRC_GGML/llama-src.patch
fi
cd $SRC_GGML
if [ -f $SRC_GGML/llama-src.patch ]; then
# replace PR numbers
#
# Subject: some text (#1234)
# Subject: some text (llama/1234)
cat llama-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (llama\/\2)/' > llama-src.patch.tmp
mv llama-src.patch.tmp llama-src.patch
cat llama-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (llama\/\2)/' > llama-src.patch.tmp
mv llama-src.patch.tmp llama-src.patch
# replace filenames:
#
# ggml.c -> src/ggml.c
# ggml-alloc.c -> src/ggml-alloc.c
# ggml-backend-impl.h -> src/ggml-backend-impl.h
# ggml-backend.c -> src/ggml-backend.c
# ggml-blas.cpp -> src/ggml-blas.cpp
# ggml-blas.h -> src/ggml-blas.h
# ggml-common.h -> src/ggml-common.h
# ggml-cuda/* -> src/ggml-cuda/*
# ggml-cuda.cu -> src/ggml-cuda.cu
# ggml-cuda.h -> src/ggml-cuda.h
# ggml-impl.h -> src/ggml-impl.h
# ggml-kompute.cpp -> src/ggml-kompute.cpp
# ggml-kompute.h -> src/ggml-kompute.h
# ggml-metal.h -> src/ggml-metal.h
# ggml-metal.m -> src/ggml-metal.m
# ggml-quants.c -> src/ggml-quants.c
# ggml-quants.h -> src/ggml-quants.h
# ggml-rpc.cpp -> src/ggml-rpc.cpp
# ggml-rpc.h -> src/ggml-rpc.h
# ggml-sycl/* -> src/ggml-sycl/*
# ggml-sycl.cpp -> src/ggml-sycl.cpp
# ggml-sycl.h -> src/ggml-sycl.h
# ggml-vulkan.cpp -> src/ggml-vulkan.cpp
# ggml-vulkan.h -> src/ggml-vulkan.h
# ggml.h -> include/ggml/ggml.h
# ggml-alloc.h -> include/ggml/ggml-alloc.h
# ggml-backend.h -> include/ggml/ggml-backend.h
#
# tests/test-opt.cpp -> tests/test-opt.cpp
# tests/test-grad0.cpp -> tests/test-grad0.cpp
# tests/test-quantize-fns.cpp -> tests/test-quantize-fns.cpp
# tests/test-quantize-perf.cpp -> tests/test-quantize-perf.cpp
# tests/test-backend-ops.cpp -> tests/test-backend-ops.cpp
#
# LICENSE -> LICENSE
# scripts/gen-authors.sh -> scripts/gen-authors.sh
cat llama-src.patch | sed \
-e 's/\/ggml\.c/\/src\/ggml.c/g' \
-e 's/\/ggml-alloc\.c/\/src\/ggml-alloc.c/g' \
-e 's/\/ggml-backend-impl\.h/\/src\/ggml-backend-impl.h/g' \
-e 's/\/ggml-backend\.c/\/src\/ggml-backend.c/g' \
-e 's/\/ggml-blas\.cpp/\/src\/ggml-blas.cpp/g' \
-e 's/\/ggml-blas\.h/\/src\/ggml-blas.h/g' \
-e 's/\/ggml-common\.h/\/src\/ggml-common.h/g' \
-e 's/\/ggml-cuda\//\/src\/ggml-cuda\//g' \
-e 's/\/ggml-cuda\.cu/\/src\/ggml-cuda.cu/g' \
-e 's/\/ggml-cuda\.h/\/src\/ggml-cuda.h/g' \
-e 's/\/ggml-impl\.h/\/src\/ggml-impl.h/g' \
-e 's/\/ggml-kompute\.cpp/\/src\/ggml-kompute.cpp/g' \
-e 's/\/ggml-kompute\.h/\/src\/ggml-kompute.h/g' \
-e 's/\/ggml-metal\.h/\/src\/ggml-metal.h/g' \
-e 's/\/ggml-metal\.m/\/src\/ggml-metal.m/g' \
-e 's/\/ggml-quants\.c/\/src\/ggml-quants.c/g' \
-e 's/\/ggml-quants\.h/\/src\/ggml-quants.h/g' \
-e 's/\/ggml-rpc\.cpp/\/src\/ggml-rpc.cpp/g' \
-e 's/\/ggml-rpc\.h/\/src\/ggml-rpc.h/g' \
-e 's/\/ggml-sycl\//\/src\/ggml-sycl\//g' \
-e 's/\/ggml-sycl\.cpp/\/src\/ggml-sycl.cpp/g' \
-e 's/\/ggml-sycl\.h/\/src\/ggml-sycl.h/g' \
-e 's/\/ggml-vulkan\.cpp/\/src\/ggml-vulkan.cpp/g' \
-e 's/\/ggml-vulkan\.h/\/src\/ggml-vulkan.h/g' \
-e 's/\/ggml_vk_generate_shaders\.py/\/src\/ggml_vk_generate_shaders.py/g' \
-e 's/\/ggml\.h/\/include\/ggml\/ggml.h/g' \
-e 's/\/ggml-alloc\.h/\/include\/ggml\/ggml-alloc.h/g' \
-e 's/\/ggml-backend\.h/\/include\/ggml\/ggml-backend.h/g' \
-e 's/\/tests\/test-opt\.cpp/\/tests\/test-opt.cpp/g' \
-e 's/\/tests\/test-grad0\.cpp/\/tests\/test-grad0.cpp/g' \
-e 's/\/tests\/test-quantize-fns\.cpp/\/tests\/test-quantize-fns.cpp/g' \
-e 's/\/tests\/test-quantize-perf\.cpp/\/tests\/test-quantize-perf.cpp/g' \
-e 's/\/tests\/test-backend-ops\.cpp/\/tests\/test-backend-ops.cpp/g' \
-e 's/\/LICENSE/\/LICENSE/g' \
-e 's/\/scripts\/gen-authors\.sh/\/scripts\/gen-authors.sh/g' \
> llama-src.patch.tmp
mv llama-src.patch.tmp llama-src.patch
git am llama-src.patch
rm -v $SRC_GGML/llama-src.patch
fi
# update last commit
cd $SRC_LLAMA
git log -1 --format=%H > $SRC_GGML/scripts/sync-llama.last
echo "Done"
exit 0