diff --git a/.github/upload_to_hf.py b/.github/upload_to_hf.py new file mode 100644 index 000000000..5de067425 --- /dev/null +++ b/.github/upload_to_hf.py @@ -0,0 +1,37 @@ +from huggingface_hub import HfApi +import argparse + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("--token", type=str, default=None) + parser.add_argument("--repo-id", type=str, default="AsakusaRinne/LLamaSharpNative") + parser.add_argument("--folder", type=str, required=True) + parser.add_argument("--revision", type=str, required=True) + parser.add_argument("--commit_message", type=str, default=None) + return parser.parse_args() + +if __name__ == '__main__': + args = parse_args() + api = HfApi(token=args.token) + + if args.commit_message is None: + args.commit_message = f"Upload native library of version {args.revision}" + + print(f'Creating branch {args.revision} ...') + try: + api.delete_branch(repo_id=args.repo_id, branch=args.revision, token=args.token) + print(f'Branch {args.revision} already exists, deleting it ...') + except: + pass + api.create_branch(repo_id=args.repo_id, branch=args.revision, token=args.token, exist_ok=False) + # upload the folder to huggingface repo + print(f'Uploading folder to huggingface repo with revision {args.revision} ...') + api.upload_folder( + repo_id=args.repo_id, + folder_path=args.folder, + path_in_repo="runtimes", + token=args.token, + revision=args.revision, + ) + + \ No newline at end of file diff --git a/.github/workflows/release-minor.yml b/.github/workflows/release-minor.yml index 59be40c90..84069d1f9 100644 --- a/.github/workflows/release-minor.yml +++ b/.github/workflows/release-minor.yml @@ -73,4 +73,10 @@ jobs: version=$(cat ./temp/version.txt) mike deploy --push --update-aliases --force $version latest mike set-default --push --force latest - \ No newline at end of file + + # Upload the native binaries to huggingface (experimental) + - name: Upload native binaries to huggingface + run: | + pip install huggingface_hub + llama_cpp_commit_hash=$(git submodule status llama.cpp | cut -c 2-7) + python .github/upload_to_hf.py --token ${{ secrets.HUGGINGFACE_TOKEN }} --revision $llama_cpp_commit_hash --folder LLama/runtimes diff --git a/.github/workflows/release-patch.yml b/.github/workflows/release-patch.yml index f3533b956..099d399dd 100644 --- a/.github/workflows/release-patch.yml +++ b/.github/workflows/release-patch.yml @@ -74,3 +74,9 @@ jobs: mike deploy --push --update-aliases --force $version latest mike set-default --push --force latest + # Upload the native binaries to huggingface (experimental) + - name: Upload native binaries to huggingface + run: | + pip install huggingface_hub + llama_cpp_commit_hash=$(git submodule status llama.cpp | cut -c 2-7) + python .github/upload_to_hf.py --token ${{ secrets.HUGGINGFACE_TOKEN }} --revision $llama_cpp_commit_hash --folder LLama/runtimes \ No newline at end of file