]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
scripts : add sync-whisper-am.sh
authorGeorgi Gerganov <redacted>
Wed, 27 Dec 2023 09:56:42 +0000 (11:56 +0200)
committerGeorgi Gerganov <redacted>
Fri, 29 Dec 2023 08:53:00 +0000 (10:53 +0200)
scripts/sync-whisper-am.sh [new file with mode: 0755]
scripts/sync-whisper.last [new file with mode: 0644]

diff --git a/scripts/sync-whisper-am.sh b/scripts/sync-whisper-am.sh
new file mode 100755 (executable)
index 0000000..3232300
--- /dev/null
@@ -0,0 +1,140 @@
+#!/bin/bash
+#
+# Synchronize whisper.cpp changes to ggml
+#
+# Usage:
+#
+#   $ cd /path/to/ggml
+#   $ ./scripts/sync-whisper-am.sh
+#
+
+set -e
+
+sd=$(dirname $0)
+cd $sd/../
+
+SRC_GGML=$(pwd)
+SRC_WHISPER=$(cd ../whisper.cpp; pwd)
+
+if [ ! -d $SRC_WHISPER ]; then
+    echo "whisper.cpp not found at $SRC_WHISPER"
+    exit 1
+fi
+
+lc=$(cat $SRC_GGML/scripts/sync-whisper.last)
+echo "Syncing whisper.cpp changes since commit $lc"
+
+cd $SRC_WHISPER
+
+git log --oneline $lc..HEAD
+
+git format-patch $lc --stdout -- \
+    ggml*.h \
+    ggml*.c \
+    ggml*.cpp \
+    ggml*.m \
+    ggml*.metal \
+    ggml*.cu \
+    whisper.h \
+    whisper.cpp \
+    examples/common.h \
+    examples/common.cpp \
+    examples/common-ggml.h \
+    examples/common-ggml.cpp \
+    examples/main/main.cpp \
+    examples/quantize/quantize.cpp \
+    > $SRC_GGML/whisper-src.patch
+
+# delete files if empty
+if [ ! -s $SRC_GGML/whisper-src.patch ]; then
+    rm -v $SRC_GGML/whisper-src.patch
+fi
+
+cd $SRC_GGML
+
+if [ -f $SRC_GGML/whisper-src.patch ]; then
+    # replace PR numbers
+    #
+    # Subject: some text (#1234)
+    # Subject: some text (whisper/1234)
+    cat whisper-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (whisper\/\2)/' > whisper-src.patch.tmp
+    mv whisper-src.patch.tmp whisper-src.patch
+
+    cat whisper-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (whisper\/\2)/' > whisper-src.patch.tmp
+    mv whisper-src.patch.tmp whisper-src.patch
+
+    # replace filenames:
+    #
+    # ggml.c              -> src/ggml.c
+    # ggml-alloc.c        -> src/ggml-alloc.c
+    # ggml-backend-impl.h -> src/ggml-backend-impl.h
+    # ggml-backend.c      -> src/ggml-backend.c
+    # ggml-cuda.cu        -> src/ggml-cuda.cu
+    # ggml-cuda.h         -> src/ggml-cuda.h
+    # ggml-impl.h         -> src/ggml-impl.h
+    # ggml-metal.h        -> src/ggml-metal.h
+    # ggml-metal.m        -> src/ggml-metal.m
+    # ggml-metal.metal    -> src/ggml-metal.metal
+    # ggml-mpi.h          -> src/ggml-mpi.h
+    # ggml-mpi.c          -> src/ggml-mpi.c
+    # ggml-opencl.cpp     -> src/ggml-opencl.cpp
+    # ggml-opencl.h       -> src/ggml-opencl.h
+    # ggml-quants.c       -> src/ggml-quants.c
+    # ggml-quants.h       -> src/ggml-quants.h
+    # ggml.h              -> include/ggml/ggml.h
+    # ggml-alloc.h        -> include/ggml/ggml-alloc.h
+    # ggml-backend.h      -> include/ggml/ggml-backend.h
+    #
+    # whisper.h           -> examples/whisper/whisper.h
+    # whisper.cpp         -> examples/whisper/whisper.cpp
+    #
+    # examples/common.h              -> examples/common.h
+    # examples/common.cpp            -> examples/common.cpp
+    # examples/common-ggml.h         -> examples/common-ggml.h
+    # examples/common-ggml.cpp       -> examples/common-ggml.cpp
+    # examples/main/main.cpp         -> examples/whisper/main.cpp
+    # examples/quantize/quantize.cpp -> examples/whisper/quantize.cpp
+
+    cat whisper-src.patch | sed \
+        -e 's/\/ggml\.c/\/src\/ggml.c/g' \
+        -e 's/\/ggml-alloc\.c/\/src\/ggml-alloc.c/g' \
+        -e 's/\/ggml-backend-impl\.h/\/src\/ggml-backend-impl.h/g' \
+        -e 's/\/ggml-backend\.c/\/src\/ggml-backend.c/g' \
+        -e 's/\/ggml-cuda\.cu/\/src\/ggml-cuda.cu/g' \
+        -e 's/\/ggml-cuda\.h/\/src\/ggml-cuda.h/g' \
+        -e 's/\/ggml-impl\.h/\/src\/ggml-impl.h/g' \
+        -e 's/\/ggml-metal\.h/\/src\/ggml-metal.h/g' \
+        -e 's/\/ggml-metal\.m/\/src\/ggml-metal.m/g' \
+        -e 's/\/ggml-metal\.metal/\/src\/ggml-metal.metal/g' \
+        -e 's/\/ggml-mpi\.h/\/src\/ggml-mpi.h/g' \
+        -e 's/\/ggml-mpi\.c/\/src\/ggml-mpi.c/g' \
+        -e 's/\/ggml-opencl\.cpp/\/src\/ggml-opencl.cpp/g' \
+        -e 's/\/ggml-opencl\.h/\/src\/ggml-opencl.h/g' \
+        -e 's/\/ggml-quants\.c/\/src\/ggml-quants.c/g' \
+        -e 's/\/ggml-quants\.h/\/src\/ggml-quants.h/g' \
+        -e 's/\/ggml\.h/\/include\/ggml\/ggml.h/g' \
+        -e 's/\/ggml-alloc\.h/\/include\/ggml\/ggml-alloc.h/g' \
+        -e 's/\/ggml-backend\.h/\/include\/ggml\/ggml-backend.h/g' \
+        -e 's/\/whisper\.h/\/examples\/whisper\/whisper.h/g' \
+        -e 's/\/whisper\.cpp/\/examples\/whisper\/whisper.cpp/g' \
+        -e 's/\/examples\/common\.h/\/examples\/common.h/g' \
+        -e 's/\/examples\/common\.cpp/\/examples\/common.cpp/g' \
+        -e 's/\/examples\/common-ggml\.h/\/examples\/common-ggml.h/g' \
+        -e 's/\/examples\/common-ggml\.cpp/\/examples\/common-ggml.cpp/g' \
+        -e 's/\/examples\/main\/main\.cpp/\/examples\/whisper\/main.cpp/g' \
+        -e 's/\/examples\/quantize\/quantize\.cpp/\/examples\/whisper\/quantize.cpp/g' \
+        > whisper-src.patch.tmp
+    mv whisper-src.patch.tmp whisper-src.patch
+
+    git am whisper-src.patch
+
+    rm -v $SRC_GGML/whisper-src.patch
+fi
+
+# update last commit
+cd $SRC_WHISPER
+git log -1 --format=%H > $SRC_GGML/scripts/sync-whisper.last
+
+echo "Done"
+
+exit 0
diff --git a/scripts/sync-whisper.last b/scripts/sync-whisper.last
new file mode 100644 (file)
index 0000000..53d497e
--- /dev/null
@@ -0,0 +1 @@
+3a5302108d9054b3b90b0a891264191eb01340dc