sync-ggml-am.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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/BuildTypes.cmake \
  59. cmake/GitVars.cmake \
  60. cmake/common.cmake \
  61. cmake/ggml-config.cmake.in \
  62. src/ggml-cpu/cmake/FindSIMD.cmake \
  63. src/ggml*.h \
  64. src/ggml*.c \
  65. src/ggml*.cpp \
  66. src/gguf*.cpp \
  67. src/ggml-blas/* \
  68. src/ggml-cann/* \
  69. src/ggml-cpu/* \
  70. src/ggml-cuda/* \
  71. src/ggml-hip/* \
  72. src/ggml-kompute/* \
  73. src/ggml-metal/* \
  74. src/ggml-musa/* \
  75. src/ggml-opencl/* \
  76. src/ggml-rpc/* \
  77. src/ggml-sycl/* \
  78. src/ggml-vulkan/* \
  79. include/ggml*.h \
  80. include/gguf*.h \
  81. tests/test-opt.cpp \
  82. tests/test-quantize-fns.cpp \
  83. tests/test-quantize-perf.cpp \
  84. tests/test-backend-ops.cpp \
  85. LICENSE \
  86. scripts/gen-authors.sh \
  87. >> $SRC_LLAMA/ggml-src.patch
  88. done < $SRC_LLAMA/ggml-commits
  89. rm -v $SRC_LLAMA/ggml-commits
  90. # delete files if empty
  91. if [ ! -s $SRC_LLAMA/ggml-src.patch ]; then
  92. rm -v $SRC_LLAMA/ggml-src.patch
  93. fi
  94. cd $SRC_LLAMA
  95. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  96. # replace PR numbers
  97. #
  98. # Subject: some text (#1234)
  99. # Subject: some text (ggml/1234)
  100. cat ggml-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (ggml\/\2)/' > ggml-src.patch.tmp
  101. mv ggml-src.patch.tmp ggml-src.patch
  102. cat ggml-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (ggml\/\2)/' > ggml-src.patch.tmp
  103. mv ggml-src.patch.tmp ggml-src.patch
  104. # replace filenames:
  105. #
  106. # CMakelists.txt -> ggml/CMakeLists.txt
  107. # src/CMakeLists.txt -> ggml/src/CMakeLists.txt
  108. # cmake/BuildTypes.cmake -> ggml/cmake/BuildTypes.cmake
  109. # cmake/GitVars.cmake -> ggml/cmake/GitVars.cmake
  110. # cmake/common.cmake -> ggml/cmake/common.cmake
  111. # cmake/ggml-config.cmake.in -> ggml/cmake/ggml-config.cmake.in
  112. # src/ggml-cpu/cmake/FindSIMD.cmake -> ggml/src/ggml-cpu/cmake/FindSIMD.cmake
  113. #
  114. # src/ggml*.c -> ggml/src/ggml*.c
  115. # src/ggml*.cpp -> ggml/src/ggml*.cpp
  116. # src/ggml*.h -> ggml/src/ggml*.h
  117. # src/gguf*.cpp -> ggml/src/gguf*.cpp
  118. # src/ggml-blas/* -> ggml/src/ggml-blas/*
  119. # src/ggml-cann/* -> ggml/src/ggml-cann/*
  120. # src/ggml-cpu/* -> ggml/src/ggml-cpu/*
  121. # src/ggml-cuda/* -> ggml/src/ggml-cuda/*
  122. # src/ggml-hip/* -> ggml/src/ggml-hip/*
  123. # src/ggml-kompute/* -> ggml/src/ggml-kompute/*
  124. # src/ggml-metal/* -> ggml/src/ggml-metal/*
  125. # src/ggml-musa/* -> ggml/src/ggml-musa/*
  126. # src/ggml-opencl/* -> ggml/src/ggml-opencl/*
  127. # src/ggml-rpc/* -> ggml/src/ggml-rpc/*
  128. # src/ggml-sycl/* -> ggml/src/ggml-sycl/*
  129. # src/ggml-vulkan/* -> ggml/src/ggml-vulkan/*
  130. #
  131. # include/ggml*.h -> ggml/include/ggml*.h
  132. # include/gguf*.h -> ggml/include/gguf*.h
  133. #
  134. # tests/test*.cpp -> tests/
  135. #
  136. # LICENSE -> LICENSE
  137. # scripts/gen-authors.sh -> scripts/gen-authors.sh
  138. cat ggml-src.patch | sed -E \
  139. -e 's/([[:space:]]| [ab]\/)CMakeLists.txt/\1ggml\/CMakeLists.txt/g' \
  140. -e 's/([[:space:]]| [ab]\/)src\/CMakeLists.txt/\1ggml\/src\/CMakeLists.txt/g' \
  141. -e 's/([[:space:]]| [ab]\/)cmake\/BuildTypes.cmake/\1ggml\/cmake\/BuildTypes.cmake/g' \
  142. -e 's/([[:space:]]| [ab]\/)cmake\/GitVars.cmake/\1ggml\/cmake\/GitVars.cmake/g' \
  143. -e 's/([[:space:]]| [ab]\/)cmake\/common.cmake/\1ggml\/cmake\/common.cmake/g' \
  144. -e 's/([[:space:]]| [ab]\/)cmake\/ggml-config.cmake.in/\1ggml\/cmake\/ggml-config.cmake.in/g' \
  145. -e 's/([[:space:]]| [ab]\/)src\/ggml-cpu\/cmake\/FindSIMD.cmake/\1ggml\/src\/ggml-cpu\/cmake\/FindSIMD.cmake/g' \
  146. -e 's/([[:space:]]| [ab]\/)src\/ggml(.*)\.c/\1ggml\/src\/ggml\2.c/g' \
  147. -e 's/([[:space:]]| [ab]\/)src\/ggml(.*)\.cpp/\1ggml\/src\/ggml\2.cpp/g' \
  148. -e 's/([[:space:]]| [ab]\/)src\/ggml(.*)\.h/\1ggml\/src\/ggml\2.h/g' \
  149. -e 's/([[:space:]]| [ab]\/)src\/gguf(.*)\.cpp/\1ggml\/src\/gguf\2.cpp/g' \
  150. -e 's/([[:space:]]| [ab]\/)src\/ggml-blas\//\1ggml\/src\/ggml-blas\//g' \
  151. -e 's/([[:space:]]| [ab]\/)src\/ggml-cann\//\1ggml\/src\/ggml-cann\//g' \
  152. -e 's/([[:space:]]| [ab]\/)src\/ggml-cpu\//\1ggml\/src\/ggml-cpu\//g' \
  153. -e 's/([[:space:]]| [ab]\/)src\/ggml-cuda\//\1ggml\/src\/ggml-cuda\//g' \
  154. -e 's/([[:space:]]| [ab]\/)src\/ggml-hip\//\1ggml\/src\/ggml-hip\//g' \
  155. -e 's/([[:space:]]| [ab]\/)src\/ggml-kompute\//\1ggml\/src\/ggml-kompute\//g' \
  156. -e 's/([[:space:]]| [ab]\/)src\/ggml-metal\//\1ggml\/src\/ggml-metal\//g' \
  157. -e 's/([[:space:]]| [ab]\/)src\/ggml-opencl\//\1ggml\/src\/ggml-opencl\//g' \
  158. -e 's/([[:space:]]| [ab]\/)src\/ggml-rpc\//\1ggml\/src\/ggml-rpc\//g' \
  159. -e 's/([[:space:]]| [ab]\/)src\/ggml-sycl\//\1ggml\/src\/ggml-sycl\//g' \
  160. -e 's/([[:space:]]| [ab]\/)src\/ggml-vulkan\//\1ggml\/src\/ggml-vulkan\//g' \
  161. -e 's/([[:space:]]| [ab]\/)include\/ggml(.*)\.h/\1ggml\/include\/ggml\2.h/g' \
  162. -e 's/([[:space:]]| [ab]\/)include\/gguf(.*)\.h/\1ggml\/include\/gguf\2.h/g' \
  163. -e 's/([[:space:]]| [ab]\/)tests\/(.*)\.cpp/\1tests\/\2.cpp/g' \
  164. -e 's/([[:space:]]| [ab]\/)LICENSE/\1LICENSE/g' \
  165. -e 's/([[:space:]]| [ab]\/)scripts\/gen-authors\.sh/\1scripts\/gen-authors.sh/g' \
  166. > ggml-src.patch.tmp
  167. mv ggml-src.patch.tmp ggml-src.patch
  168. git am -C${ctx} ggml-src.patch
  169. rm -v $SRC_LLAMA/ggml-src.patch
  170. fi
  171. # update last commit
  172. cd $SRC_GGML
  173. git log -1 --format=%H > $SRC_LLAMA/scripts/sync-ggml.last
  174. echo "Done"
  175. exit 0