sync-ggml-am.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. include/ggml/ggml*.h \
  45. src/ggml*.h \
  46. src/ggml*.c \
  47. src/ggml*.cpp \
  48. src/ggml*.m \
  49. src/ggml*.metal \
  50. src/ggml*.cu \
  51. src/ggml-cuda/* \
  52. tests/test-opt.cpp \
  53. tests/test-grad0.cpp \
  54. tests/test-quantize-fns.cpp \
  55. tests/test-quantize-perf.cpp \
  56. tests/test-backend-ops.cpp \
  57. LICENSE \
  58. scripts/gen-authors.sh \
  59. >> $SRC_LLAMA/ggml-src.patch
  60. done < $SRC_LLAMA/ggml-commits
  61. rm -v $SRC_LLAMA/ggml-commits
  62. # delete files if empty
  63. if [ ! -s $SRC_LLAMA/ggml-src.patch ]; then
  64. rm -v $SRC_LLAMA/ggml-src.patch
  65. fi
  66. cd $SRC_LLAMA
  67. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  68. # replace PR numbers
  69. #
  70. # Subject: some text (#1234)
  71. # Subject: some text (ggml/1234)
  72. cat ggml-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (ggml\/\2)/' > ggml-src.patch.tmp
  73. mv ggml-src.patch.tmp ggml-src.patch
  74. cat ggml-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (ggml\/\2)/' > ggml-src.patch.tmp
  75. mv ggml-src.patch.tmp ggml-src.patch
  76. # replace filenames:
  77. #
  78. # src/ggml.c -> ggml.c
  79. # src/ggml-alloc.c -> ggml-alloc.c
  80. # src/ggml-backend-impl.h -> ggml-backend-impl.h
  81. # src/ggml-backend.c -> ggml-backend.c
  82. # src/ggml-common.h -> ggml-common.h
  83. # src/ggml-cuda/* -> ggml-cuda/
  84. # src/ggml-cuda.cu -> ggml-cuda.cu
  85. # src/ggml-cuda.h -> ggml-cuda.h
  86. # src/ggml-impl.h -> ggml-impl.h
  87. # src/ggml-kompute.cpp -> ggml-kompute.cpp
  88. # src/ggml-kompute.h -> ggml-kompute.h
  89. # src/ggml-metal.h -> ggml-metal.h
  90. # src/ggml-metal.m -> ggml-metal.m
  91. # src/ggml-quants.c -> ggml-quants.c
  92. # src/ggml-quants.h -> ggml-quants.h
  93. # src/ggml-rpc.cpp -> ggml-rpc.cpp
  94. # src/ggml-rpc.h -> ggml-rpc.h
  95. # src/ggml-sycl.cpp -> ggml-sycl.cpp
  96. # src/ggml-sycl.h -> ggml-sycl.h
  97. # src/ggml-vulkan.cpp -> ggml-vulkan.cpp
  98. # src/ggml-vulkan.h -> ggml-vulkan.h
  99. # include/ggml/ggml.h -> ggml.h
  100. # include/ggml/ggml-alloc.h -> ggml-alloc.h
  101. # include/ggml/ggml-backend.h -> ggml-backend.h
  102. #
  103. # tests/test-opt.cpp -> tests/test-opt.cpp
  104. # tests/test-grad0.cpp -> tests/test-grad0.cpp
  105. # tests/test-quantize-fns.cpp -> tests/test-quantize-fns.cpp
  106. # tests/test-quantize-perf.cpp -> tests/test-quantize-perf.cpp
  107. # tests/test-backend-ops.cpp -> tests/test-backend-ops.cpp
  108. #
  109. # LICENSE -> LICENSE
  110. # scripts/gen-authors.sh -> scripts/gen-authors.sh
  111. cat ggml-src.patch | sed \
  112. -e 's/src\/ggml\.c/ggml.c/g' \
  113. -e 's/src\/ggml-alloc\.c/ggml-alloc.c/g' \
  114. -e 's/src\/ggml-backend-impl\.h/ggml-backend-impl.h/g' \
  115. -e 's/src\/ggml-backend\.c/ggml-backend.c/g' \
  116. -e 's/src\/ggml-common\.h/ggml-common.h/g' \
  117. -e 's/src\/ggml-cuda\//ggml-cuda\//g' \
  118. -e 's/src\/ggml-cuda\.cu/ggml-cuda.cu/g' \
  119. -e 's/src\/ggml-cuda\.h/ggml-cuda.h/g' \
  120. -e 's/src\/ggml-impl\.h/ggml-impl.h/g' \
  121. -e 's/src\/ggml-kompute\.cpp/ggml-kompute.cpp/g' \
  122. -e 's/src\/ggml-kompute\.h/ggml-kompute.h/g' \
  123. -e 's/src\/ggml-metal\.h/ggml-metal.h/g' \
  124. -e 's/src\/ggml-metal\.m/ggml-metal.m/g' \
  125. -e 's/src\/ggml-quants\.c/ggml-quants.c/g' \
  126. -e 's/src\/ggml-quants\.h/ggml-quants.h/g' \
  127. -e 's/src\/ggml-rpc\.cpp/ggml-rpc.cpp/g' \
  128. -e 's/src\/ggml-rpc\.h/ggml-rpc.h/g' \
  129. -e 's/src\/ggml-sycl\.cpp/ggml-sycl.cpp/g' \
  130. -e 's/src\/ggml-sycl\.h/ggml-sycl.h/g' \
  131. -e 's/src\/ggml-vulkan\.cpp/ggml-vulkan.cpp/g' \
  132. -e 's/src\/ggml-vulkan\.h/ggml-vulkan.h/g' \
  133. -e 's/include\/ggml\/ggml\.h/ggml.h/g' \
  134. -e 's/include\/ggml\/ggml-alloc\.h/ggml-alloc.h/g' \
  135. -e 's/include\/ggml\/ggml-backend\.h/ggml-backend.h/g' \
  136. -e 's/tests\/test-opt\.cpp/tests\/test-opt.cpp/g' \
  137. -e 's/tests\/test-grad0\.cpp/tests\/test-grad0.cpp/g' \
  138. -e 's/tests\/test-quantize-fns\.cpp/tests\/test-quantize-fns.cpp/g' \
  139. -e 's/tests\/test-quantize-perf\.cpp/tests\/test-quantize-perf.cpp/g' \
  140. -e 's/tests\/test-backend-ops\.cpp/tests\/test-backend-ops.cpp/g' \
  141. -e 's/LICENSE/LICENSE/g' \
  142. -e 's/scripts\/gen-authors\.sh/scripts\/gen-authors.sh/g' \
  143. > ggml-src.patch.tmp
  144. mv ggml-src.patch.tmp ggml-src.patch
  145. git am 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