sync-ggml-am.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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-amx/* \
  66. src/ggml-cann/* \
  67. src/ggml-cuda/* \
  68. src/ggml-sycl/* \
  69. src/vulkan-shaders/* \
  70. include/ggml*.h \
  71. tests/test-opt.cpp \
  72. tests/test-grad0.cpp \
  73. tests/test-quantize-fns.cpp \
  74. tests/test-quantize-perf.cpp \
  75. tests/test-backend-ops.cpp \
  76. LICENSE \
  77. scripts/gen-authors.sh \
  78. >> $SRC_LLAMA/ggml-src.patch
  79. done < $SRC_LLAMA/ggml-commits
  80. rm -v $SRC_LLAMA/ggml-commits
  81. # delete files if empty
  82. if [ ! -s $SRC_LLAMA/ggml-src.patch ]; then
  83. rm -v $SRC_LLAMA/ggml-src.patch
  84. fi
  85. cd $SRC_LLAMA
  86. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  87. # replace PR numbers
  88. #
  89. # Subject: some text (#1234)
  90. # Subject: some text (ggml/1234)
  91. cat ggml-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (ggml\/\2)/' > ggml-src.patch.tmp
  92. mv ggml-src.patch.tmp ggml-src.patch
  93. cat ggml-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (ggml\/\2)/' > ggml-src.patch.tmp
  94. mv ggml-src.patch.tmp ggml-src.patch
  95. # replace filenames:
  96. #
  97. # CMakelists.txt -> ggml/CMakeLists.txt
  98. # src/CMakeLists.txt -> ggml/src/CMakeLists.txt
  99. # cmake/FindSIMD.cmake -> ggml/cmake/FindSIMD.cmake
  100. #
  101. # src/ggml*.c -> ggml/src/ggml*.c
  102. # src/ggml*.cpp -> ggml/src/ggml*.cpp
  103. # src/ggml*.h -> ggml/src/ggml*.h
  104. # src/ggml*.cu -> ggml/src/ggml*.cu
  105. # src/ggml*.m -> ggml/src/ggml*.m
  106. # src/ggml-amx/* -> ggml/src/ggml-amx/
  107. # src/ggml-cann/* -> ggml/src/ggml-cann/
  108. # src/ggml-cuda/* -> ggml/src/ggml-cuda/
  109. # src/ggml-sycl/* -> ggml/src/ggml-sycl/
  110. # src/vulkan-shaders/* -> ggml/src/vulkan-shaders/
  111. #
  112. # include/ggml*.h -> ggml/include/ggml*.h
  113. #
  114. # tests/test-opt.cpp -> tests/test-opt.cpp
  115. # tests/test-grad0.cpp -> tests/test-grad0.cpp
  116. # tests/test-quantize-fns.cpp -> tests/test-quantize-fns.cpp
  117. # tests/test-quantize-perf.cpp -> tests/test-quantize-perf.cpp
  118. # tests/test-backend-ops.cpp -> tests/test-backend-ops.cpp
  119. #
  120. # LICENSE -> LICENSE
  121. # scripts/gen-authors.sh -> scripts/gen-authors.sh
  122. cat ggml-src.patch | sed -E \
  123. -e 's/([[:space:]]|[ab]\/)CMakeLists.txt/\1ggml\/CMakeLists.txt/g' \
  124. -e 's/([[:space:]]|[ab]\/)src\/CMakeLists.txt/\1ggml\/src\/CMakeLists.txt/g' \
  125. -e 's/([[:space:]]|[ab]\/)cmake\/FindSIMD.cmake/\1ggml\/cmake\/FindSIMD.cmake/g' \
  126. -e 's/([[:space:]]|[ab]\/)src\/ggml(.*)\.c/\1ggml\/src\/ggml\2.c/g' \
  127. -e 's/([[:space:]]|[ab]\/)src\/ggml(.*)\.cpp/\1ggml\/src\/ggml\2.cpp/g' \
  128. -e 's/([[:space:]]|[ab]\/)src\/ggml(.*)\.h/\1ggml\/src\/ggml\2.h/g' \
  129. -e 's/([[:space:]]|[ab]\/)src\/ggml(.*)\.cu/\1ggml\/src\/ggml\2.cu/g' \
  130. -e 's/([[:space:]]|[ab]\/)src\/ggml(.*)\.m/\1ggml\/src\/ggml\2.m/g' \
  131. -e 's/([[:space:]]|[ab]\/)src\/ggml-amx\//\1ggml\/src\/ggml-amx\//g' \
  132. -e 's/([[:space:]]|[ab]\/)src\/ggml-cann\//\1ggml\/src\/ggml-cann\//g' \
  133. -e 's/([[:space:]]|[ab]\/)src\/ggml-cuda\//\1ggml\/src\/ggml-cuda\//g' \
  134. -e 's/([[:space:]]|[ab]\/)src\/ggml-sycl\//\1ggml\/src\/ggml-sycl\//g' \
  135. -e 's/([[:space:]]|[ab]\/)src\/vulkan-shaders\//\1ggml\/src\/vulkan-shaders\//g' \
  136. -e 's/([[:space:]]|[ab]\/)include\/ggml(.*)\.h/\1ggml\/include\/ggml\2.h/g' \
  137. -e 's/([[:space:]]|[ab]\/)examples\/common\.h/\1examples\/common.h/g' \
  138. -e 's/([[:space:]]|[ab]\/)examples\/common\.cpp/\1examples\/common.cpp/g' \
  139. -e 's/([[:space:]]|[ab]\/)examples\/common-ggml\.h/\1examples\/common-ggml.h/g' \
  140. -e 's/([[:space:]]|[ab]\/)examples\/common-ggml\.cpp/\1examples\/common-ggml.cpp/g' \
  141. -e 's/([[:space:]]|[ab]\/)LICENSE/\1LICENSE/g' \
  142. -e 's/([[:space:]]|[ab]\/)scripts\/gen-authors\.sh/\1scripts\/gen-authors.sh/g' \
  143. > ggml-src.patch.tmp
  144. mv ggml-src.patch.tmp ggml-src.patch
  145. git am -C${ctx} ggml-src.patch
  146. rm -v $SRC_LLAMA/ggml-src.patch
  147. fi
  148. # update last commit
  149. cd $SRC_GGML
  150. git log -1 --format=%H > $SRC_LLAMA/scripts/sync-ggml.last
  151. echo "Done"
  152. exit 0