sync-ggml-am.sh 6.6 KB

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