Team Ai
Apppublic

KBaba7/llama.cpp

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
sync-ggml-am.sh190 linesDownload Raw Back to scripts
1#!/bin/bash2#3# Synchronize ggml changes to llama.cpp4#5# Usage:6#7#   $ cd /path/to/llama.cpp8#   $ ./scripts/sync-ggml-am.sh -skip hash0,hash1,hash2... -C 39#10 11set -e12 13sd=$(dirname $0)14cd $sd/../15 16SRC_LLAMA=$(pwd)17SRC_GGML=$(cd ../ggml; pwd)18 19if [ ! -d $SRC_GGML ]; then20    echo "ggml not found at $SRC_GGML"21    exit 122fi23 24lc=$(cat $SRC_LLAMA/scripts/sync-ggml.last)25echo "Syncing ggml changes since commit $lc"26 27to_skip=""28 29# context for git patches in number of lines30ctx="8"31 32while [ "$1" != "" ]; do33    case $1 in34        -skip )35            shift36            to_skip=$137            ;;38        -C )39            shift40            ctx=$141            ;;42    esac43    shift44done45 46cd $SRC_GGML47 48git log --oneline $lc..HEAD49git log --oneline $lc..HEAD --reverse | grep -v "(llama/[0-9]*)" | cut -d' ' -f1 > $SRC_LLAMA/ggml-commits50 51if [ ! -s $SRC_LLAMA/ggml-commits ]; then52    rm -v $SRC_LLAMA/ggml-commits53    echo "No new commits"54    exit 055fi56 57if [ -f $SRC_LLAMA/ggml-src.patch ]; then58    rm -v $SRC_LLAMA/ggml-src.patch59fi60 61while read c; do62    if [ -n "$to_skip" ]; then63        if [[ $to_skip == *"$c"* ]]; then64            echo "Skipping $c"65            continue66        fi67    fi68 69    git format-patch -U${ctx} -k $c~1..$c --stdout -- \70        CMakeLists.txt \71        src/CMakeLists.txt \72        cmake/FindSIMD.cmake \73        src/ggml*.h \74        src/ggml*.c \75        src/ggml*.cpp \76        src/gguf*.cpp \77        src/ggml-blas/* \78        src/ggml-cann/* \79        src/ggml-cpu/* \80        src/ggml-cuda/* \81        src/ggml-hip/* \82        src/ggml-kompute/* \83        src/ggml-metal/* \84        src/ggml-musa/* \85        src/ggml-opencl/* \86        src/ggml-rpc/* \87        src/ggml-sycl/* \88        src/ggml-vulkan/* \89        include/ggml*.h \90        include/gguf*.h \91        tests/test-opt.cpp \92        tests/test-quantize-fns.cpp \93        tests/test-quantize-perf.cpp \94        tests/test-backend-ops.cpp \95        LICENSE \96        scripts/gen-authors.sh \97        >> $SRC_LLAMA/ggml-src.patch98done < $SRC_LLAMA/ggml-commits99 100rm -v $SRC_LLAMA/ggml-commits101 102# delete files if empty103if [ ! -s $SRC_LLAMA/ggml-src.patch ]; then104    rm -v $SRC_LLAMA/ggml-src.patch105fi106 107cd $SRC_LLAMA108 109if [ -f $SRC_LLAMA/ggml-src.patch ]; then110    # replace PR numbers111    #112    # Subject: some text (#1234)113    # Subject: some text (ggml/1234)114    cat ggml-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (ggml\/\2)/' > ggml-src.patch.tmp115    mv ggml-src.patch.tmp ggml-src.patch116 117    cat ggml-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (ggml\/\2)/' > ggml-src.patch.tmp118    mv ggml-src.patch.tmp ggml-src.patch119 120    # replace filenames:121    #122    # CMakelists.txt       -> ggml/CMakeLists.txt123    # src/CMakeLists.txt   -> ggml/src/CMakeLists.txt124    # cmake/FindSIMD.cmake -> ggml/cmake/FindSIMD.cmake125    #126    # src/ggml*.c          -> ggml/src/ggml*.c127    # src/ggml*.cpp        -> ggml/src/ggml*.cpp128    # src/ggml*.h          -> ggml/src/ggml*.h129    # src/gguf*.cpp        -> ggml/src/gguf*.cpp130    # src/ggml-blas/*      -> ggml/src/ggml-blas/*131    # src/ggml-cann/*      -> ggml/src/ggml-cann/*132    # src/ggml-cpu/*       -> ggml/src/ggml-cpu/*133    # src/ggml-cuda/*      -> ggml/src/ggml-cuda/*134    # src/ggml-hip/*       -> ggml/src/ggml-hip/*135    # src/ggml-kompute/*   -> ggml/src/ggml-kompute/*136    # src/ggml-metal/*     -> ggml/src/ggml-metal/*137    # src/ggml-musa/*      -> ggml/src/ggml-musa/*138    # src/ggml-opencl/*    -> ggml/src/ggml-opencl/*139    # src/ggml-rpc/*       -> ggml/src/ggml-rpc/*140    # src/ggml-sycl/*      -> ggml/src/ggml-sycl/*141    # src/ggml-vulkan/*    -> ggml/src/ggml-vulkan/*142    #143    # include/ggml*.h -> ggml/include/ggml*.h144    # include/gguf*.h -> ggml/include/gguf*.h145    #146    # tests/test*.cpp -> tests/147    #148    # LICENSE                -> LICENSE149    # scripts/gen-authors.sh -> scripts/gen-authors.sh150 151    cat ggml-src.patch | sed -E \152        -e 's/([[:space:]]|[ab]\/)CMakeLists.txt/\1ggml\/CMakeLists.txt/g' \153        -e 's/([[:space:]]|[ab]\/)src\/CMakeLists.txt/\1ggml\/src\/CMakeLists.txt/g' \154        -e 's/([[:space:]]|[ab]\/)cmake\/FindSIMD.cmake/\1ggml\/cmake\/FindSIMD.cmake/g' \155        -e 's/([[:space:]]|[ab]\/)src\/ggml(.*)\.c/\1ggml\/src\/ggml\2.c/g' \156        -e 's/([[:space:]]|[ab]\/)src\/ggml(.*)\.cpp/\1ggml\/src\/ggml\2.cpp/g' \157        -e 's/([[:space:]]|[ab]\/)src\/ggml(.*)\.h/\1ggml\/src\/ggml\2.h/g' \158        -e 's/([[:space:]]|[ab]\/)src\/gguf(.*)\.cpp/\1ggml\/src\/gguf\2.cpp/g' \159        -e 's/([[:space:]]|[ab]\/)src\/ggml-blas\//\1ggml\/src\/ggml-blas\//g' \160        -e 's/([[:space:]]|[ab]\/)src\/ggml-cann\//\1ggml\/src\/ggml-cann\//g' \161        -e 's/([[:space:]]|[ab]\/)src\/ggml-cpu\//\1ggml\/src\/ggml-cpu\//g' \162        -e 's/([[:space:]]|[ab]\/)src\/ggml-cuda\//\1ggml\/src\/ggml-cuda\//g' \163        -e 's/([[:space:]]|[ab]\/)src\/ggml-hip\//\1ggml\/src\/ggml-hip\//g' \164        -e 's/([[:space:]]|[ab]\/)src\/ggml-kompute\//\1ggml\/src\/ggml-kompute\//g' \165        -e 's/([[:space:]]|[ab]\/)src\/ggml-metal\//\1ggml\/src\/ggml-metal\//g' \166        -e 's/([[:space:]]|[ab]\/)src\/ggml-opencl\//\1ggml\/src\/ggml-opencl\//g' \167        -e 's/([[:space:]]|[ab]\/)src\/ggml-rpc\//\1ggml\/src\/ggml-rpc\//g' \168        -e 's/([[:space:]]|[ab]\/)src\/ggml-sycl\//\1ggml\/src\/ggml-sycl\//g' \169        -e 's/([[:space:]]|[ab]\/)src\/ggml-vulkan\//\1ggml\/src\/ggml-vulkan\//g' \170        -e 's/([[:space:]]|[ab]\/)include\/ggml(.*)\.h/\1ggml\/include\/ggml\2.h/g' \171        -e 's/([[:space:]]|[ab]\/)include\/gguf(.*)\.h/\1ggml\/include\/gguf\2.h/g' \172        -e 's/([[:space:]]|[ab]\/)tests\/(.*)\.cpp/\1tests\/\2.cpp/g' \173        -e 's/([[:space:]]|[ab]\/)LICENSE/\1LICENSE/g' \174        -e 's/([[:space:]]|[ab]\/)scripts\/gen-authors\.sh/\1scripts\/gen-authors.sh/g' \175        > ggml-src.patch.tmp176    mv ggml-src.patch.tmp ggml-src.patch177 178    git am -C${ctx} ggml-src.patch179 180    rm -v $SRC_LLAMA/ggml-src.patch181fi182 183# update last commit184cd $SRC_GGML185git log -1 --format=%H > $SRC_LLAMA/scripts/sync-ggml.last186 187echo "Done"188 189exit 0190