sync-ggml-am.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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...
  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. if [ "$1" == "-skip" ]; then
  23. to_skip=$2
  24. fi
  25. cd $SRC_GGML
  26. git log --oneline $lc..HEAD
  27. git log --oneline $lc..HEAD --reverse | grep -v "(llama/[0-9]*)" | cut -d' ' -f1 > $SRC_LLAMA/ggml-commits
  28. if [ ! -s $SRC_LLAMA/ggml-commits ]; then
  29. rm -v $SRC_LLAMA/ggml-commits
  30. echo "No new commits"
  31. exit 0
  32. fi
  33. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  34. rm -v $SRC_LLAMA/ggml-src.patch
  35. fi
  36. while read c; do
  37. if [ -n "$to_skip" ]; then
  38. if [[ $to_skip == *"$c"* ]]; then
  39. echo "Skipping $c"
  40. continue
  41. fi
  42. fi
  43. git format-patch -k $c~1..$c --stdout -- \
  44. CMakeLists.txt \
  45. src/CMakeLists.txt \
  46. cmake/FindSIMD.cmake \
  47. src/ggml*.h \
  48. src/ggml*.c \
  49. src/ggml*.cpp \
  50. src/ggml*.m \
  51. src/ggml*.metal \
  52. src/ggml*.cu \
  53. src/ggml-cuda/* \
  54. include/ggml*.h \
  55. tests/test-opt.cpp \
  56. tests/test-grad0.cpp \
  57. tests/test-quantize-fns.cpp \
  58. tests/test-quantize-perf.cpp \
  59. tests/test-backend-ops.cpp \
  60. LICENSE \
  61. scripts/gen-authors.sh \
  62. >> $SRC_LLAMA/ggml-src.patch
  63. done < $SRC_LLAMA/ggml-commits
  64. rm -v $SRC_LLAMA/ggml-commits
  65. # delete files if empty
  66. if [ ! -s $SRC_LLAMA/ggml-src.patch ]; then
  67. rm -v $SRC_LLAMA/ggml-src.patch
  68. fi
  69. cd $SRC_LLAMA
  70. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  71. # replace PR numbers
  72. #
  73. # Subject: some text (#1234)
  74. # Subject: some text (ggml/1234)
  75. cat ggml-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (ggml\/\2)/' > ggml-src.patch.tmp
  76. mv ggml-src.patch.tmp ggml-src.patch
  77. cat ggml-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (ggml\/\2)/' > ggml-src.patch.tmp
  78. mv ggml-src.patch.tmp ggml-src.patch
  79. # replace filenames:
  80. #
  81. # CMakelists.txt -> ggml/CMakeLists.txt
  82. # src/CMakeLists.txt -> ggml/src/CMakeLists.txt
  83. # cmake/FindSIMD.cmake -> ggml/cmake/FindSIMD.cmake
  84. #
  85. # src/ggml.c -> ggml/src/ggml.c
  86. # src/ggml-alloc.c -> ggml/src/ggml-alloc.c
  87. # src/ggml-backend-impl.h -> ggml/src/ggml-backend-impl.h
  88. # src/ggml-backend.c -> ggml/src/ggml-backend.c
  89. # src/ggml-common.h -> ggml/src/ggml-common.h
  90. # src/ggml-cuda/* -> ggml/src/ggml-cuda/
  91. # src/ggml-cuda.cu -> ggml/src/ggml-cuda.cu
  92. # src/ggml-impl.h -> ggml/src/ggml-impl.h
  93. # src/ggml-kompute.cpp -> ggml/src/ggml-kompute.cpp
  94. # src/ggml-metal.m -> ggml/src/ggml-metal.m
  95. # src/ggml-quants.c -> ggml/src/ggml-quants.c
  96. # src/ggml-quants.h -> ggml/src/ggml-quants.h
  97. # src/ggml-rpc.cpp -> ggml/src/ggml-rpc.cpp
  98. # src/ggml-sycl.cpp -> ggml/src/ggml-sycl.cpp
  99. # src/ggml-vulkan.cpp -> ggml/src/ggml-vulkan.cpp
  100. #
  101. # include/ggml.h -> ggml/include/ggml.h
  102. # include/ggml-alloc.h -> ggml/include/ggml-alloc.h
  103. # include/ggml-backend.h -> ggml/include/ggml-backend.h
  104. # include/ggml-blas.h -> ggml/include/ggml-blas.h
  105. # include/ggml-cuda.h -> ggml/include/ggml-cuda.h
  106. # include/ggml-kompute.h -> ggml/include/ggml-kompute.h
  107. # include/ggml-metal.h -> ggml/include/ggml-metal.h
  108. # include/ggml-rpc.h -> ggml/include/ggml-rpc.h
  109. # include/ggml-sycl.h -> ggml/include/ggml-sycl.h
  110. # include/ggml-vulkan.h -> ggml/include/ggml-vulkan.h
  111. #
  112. # tests/test-opt.cpp -> tests/test-opt.cpp
  113. # tests/test-grad0.cpp -> tests/test-grad0.cpp
  114. # tests/test-quantize-fns.cpp -> tests/test-quantize-fns.cpp
  115. # tests/test-quantize-perf.cpp -> tests/test-quantize-perf.cpp
  116. # tests/test-backend-ops.cpp -> tests/test-backend-ops.cpp
  117. #
  118. # LICENSE -> LICENSE
  119. # scripts/gen-authors.sh -> scripts/gen-authors.sh
  120. cat ggml-src.patch | sed -E \
  121. -e 's/([[:space:]]|[ab]\/)CMakeLists.txt/\1ggml\/CMakeLists.txt/g' \
  122. -e 's/([[:space:]]|[ab]\/)src\/CMakeLists.txt/\1ggml\/src\/CMakeLists.txt/g' \
  123. -e 's/([[:space:]]|[ab]\/)cmake\/FindSIMD.cmake/\1ggml\/cmake\/FindSIMD.cmake/g' \
  124. -e 's/([[:space:]]|[ab]\/)src\/ggml\.c/\1ggml\/src\/ggml.c/g' \
  125. -e 's/([[:space:]]|[ab]\/)src\/ggml-alloc\.c/\1ggml\/src\/ggml-alloc.c/g' \
  126. -e 's/([[:space:]]|[ab]\/)src\/ggml-backend-impl\.h/\1ggml\/src\/ggml-backend-impl.h/g' \
  127. -e 's/([[:space:]]|[ab]\/)src\/ggml-backend\.c/\1ggml\/src\/ggml-backend.c/g' \
  128. -e 's/([[:space:]]|[ab]\/)src\/ggml-common\.h/\1ggml\/src\/ggml-common.h/g' \
  129. -e 's/([[:space:]]|[ab]\/)src\/ggml-cuda\//\1ggml\/src\/ggml-cuda\//g' \
  130. -e 's/([[:space:]]|[ab]\/)src\/ggml-cuda\.cu/\1ggml\/src\/ggml-cuda.cu/g' \
  131. -e 's/([[:space:]]|[ab]\/)src\/ggml-impl\.h/\1ggml\/src\/ggml-impl.h/g' \
  132. -e 's/([[:space:]]|[ab]\/)src\/ggml-kompute\.cpp/\1ggml\/src\/ggml-kompute.cpp/g' \
  133. -e 's/([[:space:]]|[ab]\/)src\/ggml-metal\.m/\1ggml\/src\/ggml-metal.m/g' \
  134. -e 's/([[:space:]]|[ab]\/)src\/ggml-quants\.c/\1ggml\/src\/ggml-quants.c/g' \
  135. -e 's/([[:space:]]|[ab]\/)src\/ggml-quants\.h/\1ggml\/src\/ggml-quants.h/g' \
  136. -e 's/([[:space:]]|[ab]\/)src\/ggml-rpc\.cpp/\1ggml\/src\/ggml-rpc.cpp/g' \
  137. -e 's/([[:space:]]|[ab]\/)src\/ggml-sycl\.cpp/\1ggml\/src\/ggml-sycl.cpp/g' \
  138. -e 's/([[:space:]]|[ab]\/)src\/ggml-vulkan\.cpp/\1ggml\/src\/ggml-vulkan.cpp/g' \
  139. -e 's/([[:space:]]|[ab]\/)include\/ggml\.h/\1ggml\/include\/ggml.h/g' \
  140. -e 's/([[:space:]]|[ab]\/)include\/ggml-alloc\.h/\1ggml\/include\/ggml-alloc.h/g' \
  141. -e 's/([[:space:]]|[ab]\/)include\/ggml-backend\.h/\1ggml\/include\/ggml-backend.h/g' \
  142. -e 's/([[:space:]]|[ab]\/)include\/ggml-blas\.h/\1ggml\/include\/ggml-blas.h/g' \
  143. -e 's/([[:space:]]|[ab]\/)include\/ggml-cuda\.h/\1ggml\/include\/ggml-cuda.h/g' \
  144. -e 's/([[:space:]]|[ab]\/)include\/ggml-kompute\.h/\1ggml\/include\/ggml-kompute.h/g' \
  145. -e 's/([[:space:]]|[ab]\/)include\/ggml-metal\.h/\1ggml\/include\/ggml-metal.h/g' \
  146. -e 's/([[:space:]]|[ab]\/)include\/ggml-rpc\.h/\1ggml\/include\/ggml-rpc.h/g' \
  147. -e 's/([[:space:]]|[ab]\/)include\/ggml-sycl\.h/\1ggml\/include\/ggml-sycl.h/g' \
  148. -e 's/([[:space:]]|[ab]\/)include\/ggml-vulkan\.h/\1ggml\/include\/ggml-vulkan.h/g' \
  149. -e 's/([[:space:]]|[ab]\/)examples\/common\.h/examples\/common.h/g' \
  150. -e 's/([[:space:]]|[ab]\/)examples\/common\.cpp/examples\/common.cpp/g' \
  151. -e 's/([[:space:]]|[ab]\/)examples\/common-ggml\.h/examples\/common-ggml.h/g' \
  152. -e 's/([[:space:]]|[ab]\/)examples\/common-ggml\.cpp/examples\/common-ggml.cpp/g' \
  153. -e 's/([[:space:]]|[ab]\/)LICENSE/LICENSE/g' \
  154. -e 's/([[:space:]]|[ab]\/)scripts\/gen-authors\.sh/scripts\/gen-authors.sh/g' \
  155. > ggml-src.patch.tmp
  156. mv ggml-src.patch.tmp ggml-src.patch
  157. git am ggml-src.patch
  158. rm -v $SRC_LLAMA/ggml-src.patch
  159. fi
  160. # update last commit
  161. cd $SRC_GGML
  162. git log -1 --format=%H > $SRC_LLAMA/scripts/sync-ggml.last
  163. echo "Done"
  164. exit 0