sync-ggml-am.sh 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #!/bin/bash
  2. #
  3. # Synchronize ggml changes to llama.cpp
  4. #
  5. # Usage:
  6. #
  7. # $ cd /path/to/llama.cpp
  8. # $ ./scripts/sync-ggml-am.sh -skip hash0,hash1,hash2... -C 3
  9. #
  10. set -e
  11. sd=$(dirname $0)
  12. cd $sd/../
  13. SRC_LLAMA=$(pwd)
  14. SRC_GGML=$(cd ../ggml; pwd)
  15. if [ ! -d $SRC_GGML ]; then
  16. echo "ggml not found at $SRC_GGML"
  17. exit 1
  18. fi
  19. lc=$(cat $SRC_LLAMA/scripts/sync-ggml.last)
  20. echo "Syncing ggml changes since commit $lc"
  21. to_skip=""
  22. # context for git patches in number of lines
  23. ctx="8"
  24. while [ "$1" != "" ]; do
  25. case $1 in
  26. -skip )
  27. shift
  28. to_skip=$1
  29. ;;
  30. -C )
  31. shift
  32. ctx=$1
  33. ;;
  34. esac
  35. shift
  36. done
  37. cd $SRC_GGML
  38. git log --oneline $lc..HEAD
  39. git log --oneline $lc..HEAD --reverse | grep -v "(llama/[0-9]*)" | cut -d' ' -f1 > $SRC_LLAMA/ggml-commits
  40. if [ ! -s $SRC_LLAMA/ggml-commits ]; then
  41. rm -v $SRC_LLAMA/ggml-commits
  42. echo "No new commits"
  43. exit 0
  44. fi
  45. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  46. rm -v $SRC_LLAMA/ggml-src.patch
  47. fi
  48. while read c; do
  49. if [ -n "$to_skip" ]; then
  50. if [[ $to_skip == *"$c"* ]]; then
  51. echo "Skipping $c"
  52. continue
  53. fi
  54. fi
  55. git format-patch -U${ctx} -k $c~1..$c --stdout -- \
  56. CMakeLists.txt \
  57. src/CMakeLists.txt \
  58. cmake/FindSIMD.cmake \
  59. src/ggml*.h \
  60. src/ggml*.c \
  61. src/ggml*.cpp \
  62. src/ggml*.m \
  63. src/ggml*.metal \
  64. src/ggml*.cu \
  65. src/ggml-cann/* \
  66. src/ggml-cuda/* \
  67. src/ggml-sycl/* \
  68. src/vulkan-shaders/* \
  69. include/ggml*.h \
  70. tests/test-opt.cpp \
  71. tests/test-grad0.cpp \
  72. tests/test-quantize-fns.cpp \
  73. tests/test-quantize-perf.cpp \
  74. tests/test-backend-ops.cpp \
  75. LICENSE \
  76. scripts/gen-authors.sh \
  77. >> $SRC_LLAMA/ggml-src.patch
  78. done < $SRC_LLAMA/ggml-commits
  79. rm -v $SRC_LLAMA/ggml-commits
  80. # delete files if empty
  81. if [ ! -s $SRC_LLAMA/ggml-src.patch ]; then
  82. rm -v $SRC_LLAMA/ggml-src.patch
  83. fi
  84. cd $SRC_LLAMA
  85. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  86. # replace PR numbers
  87. #
  88. # Subject: some text (#1234)
  89. # Subject: some text (ggml/1234)
  90. cat ggml-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (ggml\/\2)/' > ggml-src.patch.tmp
  91. mv ggml-src.patch.tmp ggml-src.patch
  92. cat ggml-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (ggml\/\2)/' > ggml-src.patch.tmp
  93. mv ggml-src.patch.tmp ggml-src.patch
  94. # replace filenames:
  95. #
  96. # CMakelists.txt -> ggml/CMakeLists.txt
  97. # src/CMakeLists.txt -> ggml/src/CMakeLists.txt
  98. # cmake/FindSIMD.cmake -> ggml/cmake/FindSIMD.cmake
  99. #
  100. # src/ggml.c -> ggml/src/ggml.c
  101. # src/ggml-aarch64.c -> ggml/src/ggml-aarch64.c
  102. # src/ggml-aarch64.h -> ggml/src/ggml-aarch64.h
  103. # src/ggml-alloc.c -> ggml/src/ggml-alloc.c
  104. # src/ggml-backend-impl.h -> ggml/src/ggml-backend-impl.h
  105. # src/ggml-backend.c -> ggml/src/ggml-backend.c
  106. # src/ggml-cann/* -> ggml/src/ggml-cann/
  107. # src/ggml-cann.cpp -> ggml/src/ggml-cann.cpp
  108. # src/ggml-common.h -> ggml/src/ggml-common.h
  109. # src/ggml-cuda/* -> ggml/src/ggml-cuda/
  110. # src/ggml-cuda.cu -> ggml/src/ggml-cuda.cu
  111. # src/ggml-impl.h -> ggml/src/ggml-impl.h
  112. # src/ggml-kompute.cpp -> ggml/src/ggml-kompute.cpp
  113. # src/ggml-metal.m -> ggml/src/ggml-metal.m
  114. # src/ggml-quants.c -> ggml/src/ggml-quants.c
  115. # src/ggml-quants.h -> ggml/src/ggml-quants.h
  116. # src/ggml-rpc.cpp -> ggml/src/ggml-rpc.cpp
  117. # src/ggml-sycl/* -> ggml/src/ggml-sycl/
  118. # src/ggml-sycl.cpp -> ggml/src/ggml-sycl.cpp
  119. # src/ggml-vulkan.cpp -> ggml/src/ggml-vulkan.cpp
  120. # src/vulkan-shaders/* -> ggml/src/vulkan-shaders/
  121. #
  122. # include/ggml.h -> ggml/include/ggml.h
  123. # include/ggml-alloc.h -> ggml/include/ggml-alloc.h
  124. # include/ggml-backend.h -> ggml/include/ggml-backend.h
  125. # include/ggml-blas.h -> ggml/include/ggml-blas.h
  126. # include/ggml-cann.h -> ggml/include/ggml-cann.h
  127. # include/ggml-cuda.h -> ggml/include/ggml-cuda.h
  128. # include/ggml-kompute.h -> ggml/include/ggml-kompute.h
  129. # include/ggml-metal.h -> ggml/include/ggml-metal.h
  130. # include/ggml-rpc.h -> ggml/include/ggml-rpc.h
  131. # include/ggml-sycl.h -> ggml/include/ggml-sycl.h
  132. # include/ggml-vulkan.h -> ggml/include/ggml-vulkan.h
  133. #
  134. # tests/test-opt.cpp -> tests/test-opt.cpp
  135. # tests/test-grad0.cpp -> tests/test-grad0.cpp
  136. # tests/test-quantize-fns.cpp -> tests/test-quantize-fns.cpp
  137. # tests/test-quantize-perf.cpp -> tests/test-quantize-perf.cpp
  138. # tests/test-backend-ops.cpp -> tests/test-backend-ops.cpp
  139. #
  140. # LICENSE -> LICENSE
  141. # scripts/gen-authors.sh -> scripts/gen-authors.sh
  142. cat ggml-src.patch | sed -E \
  143. -e 's/([[:space:]]|[ab]\/)CMakeLists.txt/\1ggml\/CMakeLists.txt/g' \
  144. -e 's/([[:space:]]|[ab]\/)src\/CMakeLists.txt/\1ggml\/src\/CMakeLists.txt/g' \
  145. -e 's/([[:space:]]|[ab]\/)cmake\/FindSIMD.cmake/\1ggml\/cmake\/FindSIMD.cmake/g' \
  146. -e 's/([[:space:]]|[ab]\/)src\/ggml\.c/\1ggml\/src\/ggml.c/g' \
  147. -e 's/([[:space:]]|[ab]\/)src\/ggml-aarch64\.c/\1ggml\/src\/ggml-aarch64.c/g' \
  148. -e 's/([[:space:]]|[ab]\/)src\/ggml-aarch64\.h/\1ggml\/src\/ggml-aarch64.h/g' \
  149. -e 's/([[:space:]]|[ab]\/)src\/ggml-alloc\.c/\1ggml\/src\/ggml-alloc.c/g' \
  150. -e 's/([[:space:]]|[ab]\/)src\/ggml-backend-impl\.h/\1ggml\/src\/ggml-backend-impl.h/g' \
  151. -e 's/([[:space:]]|[ab]\/)src\/ggml-backend\.c/\1ggml\/src\/ggml-backend.c/g' \
  152. -e 's/([[:space:]]|[ab]\/)src\/ggml-cann\//\1ggml\/src\/ggml-cann\//g' \
  153. -e 's/([[:space:]]|[ab]\/)src\/ggml-cann\.cpp/\1ggml\/src\/ggml-cann.cpp/g' \
  154. -e 's/([[:space:]]|[ab]\/)src\/ggml-common\.h/\1ggml\/src\/ggml-common.h/g' \
  155. -e 's/([[:space:]]|[ab]\/)src\/ggml-cuda\//\1ggml\/src\/ggml-cuda\//g' \
  156. -e 's/([[:space:]]|[ab]\/)src\/ggml-cuda\.cu/\1ggml\/src\/ggml-cuda.cu/g' \
  157. -e 's/([[:space:]]|[ab]\/)src\/ggml-impl\.h/\1ggml\/src\/ggml-impl.h/g' \
  158. -e 's/([[:space:]]|[ab]\/)src\/ggml-kompute\.cpp/\1ggml\/src\/ggml-kompute.cpp/g' \
  159. -e 's/([[:space:]]|[ab]\/)src\/ggml-metal\.m/\1ggml\/src\/ggml-metal.m/g' \
  160. -e 's/([[:space:]]|[ab]\/)src\/ggml-quants\.c/\1ggml\/src\/ggml-quants.c/g' \
  161. -e 's/([[:space:]]|[ab]\/)src\/ggml-quants\.h/\1ggml\/src\/ggml-quants.h/g' \
  162. -e 's/([[:space:]]|[ab]\/)src\/ggml-rpc\.cpp/\1ggml\/src\/ggml-rpc.cpp/g' \
  163. -e 's/([[:space:]]|[ab]\/)src\/ggml-sycl\//\1ggml\/src\/ggml-sycl\//g' \
  164. -e 's/([[:space:]]|[ab]\/)src\/ggml-sycl\.cpp/\1ggml\/src\/ggml-sycl.cpp/g' \
  165. -e 's/([[:space:]]|[ab]\/)src\/ggml-vulkan\.cpp/\1ggml\/src\/ggml-vulkan.cpp/g' \
  166. -e 's/([[:space:]]|[ab]\/)src\/vulkan-shaders\//\1ggml\/src\/vulkan-shaders\//g' \
  167. -e 's/([[:space:]]|[ab]\/)include\/ggml\.h/\1ggml\/include\/ggml.h/g' \
  168. -e 's/([[:space:]]|[ab]\/)include\/ggml-alloc\.h/\1ggml\/include\/ggml-alloc.h/g' \
  169. -e 's/([[:space:]]|[ab]\/)include\/ggml-backend\.h/\1ggml\/include\/ggml-backend.h/g' \
  170. -e 's/([[:space:]]|[ab]\/)include\/ggml-blas\.h/\1ggml\/include\/ggml-blas.h/g' \
  171. -e 's/([[:space:]]|[ab]\/)include\/ggml-cann\.h/\1ggml\/include\/ggml-cann.h/g' \
  172. -e 's/([[:space:]]|[ab]\/)include\/ggml-cuda\.h/\1ggml\/include\/ggml-cuda.h/g' \
  173. -e 's/([[:space:]]|[ab]\/)include\/ggml-kompute\.h/\1ggml\/include\/ggml-kompute.h/g' \
  174. -e 's/([[:space:]]|[ab]\/)include\/ggml-metal\.h/\1ggml\/include\/ggml-metal.h/g' \
  175. -e 's/([[:space:]]|[ab]\/)include\/ggml-rpc\.h/\1ggml\/include\/ggml-rpc.h/g' \
  176. -e 's/([[:space:]]|[ab]\/)include\/ggml-sycl\.h/\1ggml\/include\/ggml-sycl.h/g' \
  177. -e 's/([[:space:]]|[ab]\/)include\/ggml-vulkan\.h/\1ggml\/include\/ggml-vulkan.h/g' \
  178. -e 's/([[:space:]]|[ab]\/)examples\/common\.h/\1examples\/common.h/g' \
  179. -e 's/([[:space:]]|[ab]\/)examples\/common\.cpp/\1examples\/common.cpp/g' \
  180. -e 's/([[:space:]]|[ab]\/)examples\/common-ggml\.h/\1examples\/common-ggml.h/g' \
  181. -e 's/([[:space:]]|[ab]\/)examples\/common-ggml\.cpp/\1examples\/common-ggml.cpp/g' \
  182. -e 's/([[:space:]]|[ab]\/)LICENSE/\1LICENSE/g' \
  183. -e 's/([[:space:]]|[ab]\/)scripts\/gen-authors\.sh/\1scripts\/gen-authors.sh/g' \
  184. > ggml-src.patch.tmp
  185. mv ggml-src.patch.tmp ggml-src.patch
  186. git am -C${ctx} ggml-src.patch
  187. rm -v $SRC_LLAMA/ggml-src.patch
  188. fi
  189. # update last commit
  190. cd $SRC_GGML
  191. git log -1 --format=%H > $SRC_LLAMA/scripts/sync-ggml.last
  192. echo "Done"
  193. exit 0