1
0

sync-ggml-am.sh 4.5 KB

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