From acdb150aa26841bc9bcf7f2d16826e8226a930ac Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 24 Apr 2025 16:15:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81CI=E8=87=AA=E5=8A=A8=E5=8F=91?= =?UTF-8?q?=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-windows-cuda-11.8.yml | 93 +++++++++++++++++++ .github/workflows/build-windows-cuda-12.6.yml | 93 +++++++++++++++++++ .github/workflows/build-windows-cuda-12.8.yml | 93 +++++++++++++++++++ .github/workflows/build-windows-directml.yml | 93 +++++++++++++++++++ backend/tools/makedist.py | 65 +++++++++++++ 5 files changed, 437 insertions(+) create mode 100644 .github/workflows/build-windows-cuda-11.8.yml create mode 100644 .github/workflows/build-windows-cuda-12.6.yml create mode 100644 .github/workflows/build-windows-cuda-12.8.yml create mode 100644 .github/workflows/build-windows-directml.yml create mode 100644 backend/tools/makedist.py diff --git a/.github/workflows/build-windows-cuda-11.8.yml b/.github/workflows/build-windows-cuda-11.8.yml new file mode 100644 index 0000000..d2ae167 --- /dev/null +++ b/.github/workflows/build-windows-cuda-11.8.yml @@ -0,0 +1,93 @@ +name: Build Windows CUDA 11.8 + +on: + push: + branches: + - '**' + workflow_dispatch: + inputs: + ssh: + description: 'SSH connection to Actions' + required: false + default: false + +permissions: + contents: write + +jobs: + build: + runs-on: windows-2019 + steps: + - uses: actions/checkout@v4 + - name: 读取 VERSION + id: version + run: | + VERSION=$(sed -n 's/^VERSION = "\(.*\)"/\1/p' backend/config.py) + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + shell: bash + # - name: 检查 tag 是否已存在 + # run: | + # TAG_NAME="${VERSION}" + # if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME"; then + # echo "Tag $TAG_NAME 已存在,发布中止" + # exit 1 + # fi + # shell: bash + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' # caching pip dependencies + - run: pip install paddlepaddle==3.0.0 + - run: pip install -r requirements.txt + - run: pip freeze > requirements.txt + - run: pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu118 + - run: pip install QPT==1.0b8 setuptools + - name: 获取 site-packages 路径 + shell: bash + run: | + SITE_PACKAGES=$(python -c "import site, os; print(os.path.join(site.getsitepackages()[0], 'Lib', 'site-packages'))") + SITE_PACKAGES_UNIX=$(cygpath -u "$SITE_PACKAGES") + echo "site-packages路径: $SITE_PACKAGES" + echo "site-packages UNIX路径: $SITE_PACKAGES_UNIX" + echo "SITE_PACKAGES_UNIX=$SITE_PACKAGES_UNIX" >> $GITHUB_ENV + echo "SITE_PACKAGES=$SITE_PACKAGES" >> $GITHUB_ENV + - name: 修复QPT内部错误 + run: sed -i '98c\ try:\n dep = pkg.requires()\n except TypeError:\n continue' ${SITE_PACKAGES_UNIX}/qpt/kernel/qpackage.py + shell: bash + - name: Start SSH via tmate + if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') + uses: mxschmitt/action-tmate@v3 + - run: | + python backend/tools/makedist.py --cuda 11.8 && \ + mv ../vsr_out ./vsr_out + env: + QPT_Action: "True" + shell: bash + - name: 上传 Debug 文件夹到 Artifacts + uses: actions/upload-artifact@v4 + with: + name: vsr-v${{ env.VERSION }}-windows-nvidia-cuda-11.8-debug + path: vsr_out/Debug/ + - name: 上传 Release 文件夹到 Artifacts + uses: actions/upload-artifact@v4 + with: + name: vsr-v${{ env.VERSION }}-windows-nvidia-cuda-11.8-release + path: vsr_out/Release/ + - name: 打包 Release 文件夹 + run: | + cd vsr_out/Release + 7z a -t7z -mx=9 -m0=LZMA2 -ms=on -mfb=64 -md=32m -mmt=on -v2000m vsr-v${{ env.VERSION }}-windows-nvidia-cuda-11.8.7z * && \ + # 检测是否只有一个分卷 + if [ -f vsr-v${{ env.VERSION }}-windows-nvidia-cuda-11.8.7z.001 ] && [ ! -f vsr-v${{ env.VERSION }}-windows-nvidia-cuda-11.8.7z.002 ]; then \ + mv vsr-v${{ env.VERSION }}-windows-nvidia-cuda-11.8.7z.001 vsr-v${{ env.VERSION }}-windows-nvidia-cuda-11.8.7z; fi + shell: bash + - name: Release + uses: softprops/action-gh-release@v1 + with: + prerelease: true + tag_name: ${{ env.VERSION }} + target_commitish: ${{ github.sha }} + name: 硬字幕提取器 ${{ env.VERSION }} + files: | + vsr_out/Release/vsr-v${{ env.VERSION }}-windows-nvidia-cuda-11.8.7z* \ No newline at end of file diff --git a/.github/workflows/build-windows-cuda-12.6.yml b/.github/workflows/build-windows-cuda-12.6.yml new file mode 100644 index 0000000..17f1a1c --- /dev/null +++ b/.github/workflows/build-windows-cuda-12.6.yml @@ -0,0 +1,93 @@ +name: Build Windows CUDA 12.6 + +on: + push: + branches: + - '**' + workflow_dispatch: + inputs: + ssh: + description: 'SSH connection to Actions' + required: false + default: false + +permissions: + contents: write + +jobs: + build: + runs-on: windows-2019 + steps: + - uses: actions/checkout@v4 + - name: 读取 VERSION + id: version + run: | + VERSION=$(sed -n 's/^VERSION = "\(.*\)"/\1/p' backend/config.py) + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + shell: bash + # - name: 检查 tag 是否已存在 + # run: | + # TAG_NAME="${VERSION}" + # if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME"; then + # echo "Tag $TAG_NAME 已存在,发布中止" + # exit 1 + # fi + # shell: bash + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' # caching pip dependencies + - run: pip install paddlepaddle==3.0.0 + - run: pip install -r requirements.txt + - run: pip freeze > requirements.txt + - run: pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu126 + - run: pip install QPT==1.0b8 setuptools + - name: 获取 site-packages 路径 + shell: bash + run: | + SITE_PACKAGES=$(python -c "import site, os; print(os.path.join(site.getsitepackages()[0], 'Lib', 'site-packages'))") + SITE_PACKAGES_UNIX=$(cygpath -u "$SITE_PACKAGES") + echo "site-packages路径: $SITE_PACKAGES" + echo "site-packages UNIX路径: $SITE_PACKAGES_UNIX" + echo "SITE_PACKAGES_UNIX=$SITE_PACKAGES_UNIX" >> $GITHUB_ENV + echo "SITE_PACKAGES=$SITE_PACKAGES" >> $GITHUB_ENV + - name: 修复QPT内部错误 + run: sed -i '98c\ try:\n dep = pkg.requires()\n except TypeError:\n continue' ${SITE_PACKAGES_UNIX}/qpt/kernel/qpackage.py + shell: bash + - name: Start SSH via tmate + if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') + uses: mxschmitt/action-tmate@v3 + - run: | + python backend/tools/makedist.py --cuda 12.6 && \ + mv ../vsr_out ./vsr_out + env: + QPT_Action: "True" + shell: bash + - name: 上传 Debug 文件夹到 Artifacts + uses: actions/upload-artifact@v4 + with: + name: vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.6-debug + path: vsr_out/Debug/ + - name: 上传 Release 文件夹到 Artifacts + uses: actions/upload-artifact@v4 + with: + name: vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.6-release + path: vsr_out/Release/ + - name: 打包 Release 文件夹 + run: | + cd vsr_out/Release + 7z a -t7z -mx=9 -m0=LZMA2 -ms=on -mfb=64 -md=32m -mmt=on -v2000m vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.6.7z * && \ + # 检测是否只有一个分卷 + if [ -f vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.6.7z.001 ] && [ ! -f vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.6.7z.002 ]; then \ + mv vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.6.7z.001 vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.6.7z; fi + shell: bash + - name: Release + uses: softprops/action-gh-release@v1 + with: + prerelease: true + tag_name: ${{ env.VERSION }} + target_commitish: ${{ github.sha }} + name: 硬字幕提取器 ${{ env.VERSION }} + files: | + vsr_out/Release/vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.6.7z* \ No newline at end of file diff --git a/.github/workflows/build-windows-cuda-12.8.yml b/.github/workflows/build-windows-cuda-12.8.yml new file mode 100644 index 0000000..9b64aec --- /dev/null +++ b/.github/workflows/build-windows-cuda-12.8.yml @@ -0,0 +1,93 @@ +name: Build Windows CUDA 12.8 + +on: + push: + branches: + - '**' + workflow_dispatch: + inputs: + ssh: + description: 'SSH connection to Actions' + required: false + default: false + +permissions: + contents: write + +jobs: + build: + runs-on: windows-2019 + steps: + - uses: actions/checkout@v4 + - name: 读取 VERSION + id: version + run: | + VERSION=$(sed -n 's/^VERSION = "\(.*\)"/\1/p' backend/config.py) + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + shell: bash + # - name: 检查 tag 是否已存在 + # run: | + # TAG_NAME="${VERSION}" + # if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME"; then + # echo "Tag $TAG_NAME 已存在,发布中止" + # exit 1 + # fi + # shell: bash + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' # caching pip dependencies + - run: pip install paddlepaddle==3.0.0 + - run: pip install -r requirements.txt + - run: pip freeze > requirements.txt + - run: pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128 + - run: pip install QPT==1.0b8 setuptools + - name: 获取 site-packages 路径 + shell: bash + run: | + SITE_PACKAGES=$(python -c "import site, os; print(os.path.join(site.getsitepackages()[0], 'Lib', 'site-packages'))") + SITE_PACKAGES_UNIX=$(cygpath -u "$SITE_PACKAGES") + echo "site-packages路径: $SITE_PACKAGES" + echo "site-packages UNIX路径: $SITE_PACKAGES_UNIX" + echo "SITE_PACKAGES_UNIX=$SITE_PACKAGES_UNIX" >> $GITHUB_ENV + echo "SITE_PACKAGES=$SITE_PACKAGES" >> $GITHUB_ENV + - name: 修复QPT内部错误 + run: sed -i '98c\ try:\n dep = pkg.requires()\n except TypeError:\n continue' ${SITE_PACKAGES_UNIX}/qpt/kernel/qpackage.py + shell: bash + - name: Start SSH via tmate + if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') + uses: mxschmitt/action-tmate@v3 + - run: | + python backend/tools/makedist.py --cuda 12.8 && \ + mv ../vsr_out ./vsr_out + env: + QPT_Action: "True" + shell: bash + - name: 上传 Debug 文件夹到 Artifacts + uses: actions/upload-artifact@v4 + with: + name: vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.8-debug + path: vsr_out/Debug/ + - name: 上传 Release 文件夹到 Artifacts + uses: actions/upload-artifact@v4 + with: + name: vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.8-release + path: vsr_out/Release/ + - name: 打包 Release 文件夹 + run: | + cd vsr_out/Release + 7z a -t7z -mx=9 -m0=LZMA2 -ms=on -mfb=64 -md=32m -mmt=on -v2000m vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.8.7z * && \ + # 检测是否只有一个分卷 + if [ -f vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.8.7z.001 ] && [ ! -f vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.8.7z.002 ]; then \ + mv vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.8.7z.001 vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.8.7z; fi + shell: bash + - name: Release + uses: softprops/action-gh-release@v1 + with: + prerelease: true + tag_name: ${{ env.VERSION }} + target_commitish: ${{ github.sha }} + name: 硬字幕提取器 ${{ env.VERSION }} + files: | + vsr_out/Release/vsr-v${{ env.VERSION }}-windows-nvidia-cuda-12.8.7z* \ No newline at end of file diff --git a/.github/workflows/build-windows-directml.yml b/.github/workflows/build-windows-directml.yml new file mode 100644 index 0000000..76bcf9c --- /dev/null +++ b/.github/workflows/build-windows-directml.yml @@ -0,0 +1,93 @@ +name: Build Windows DirectML + +on: + push: + branches: + - '**' + workflow_dispatch: + inputs: + ssh: + description: 'SSH connection to Actions' + required: false + default: false + +permissions: + contents: write + +jobs: + build: + runs-on: windows-2019 + steps: + - uses: actions/checkout@v4 + - name: 读取 VERSION + id: version + run: | + VERSION=$(sed -n 's/^VERSION = "\(.*\)"/\1/p' backend/config.py) + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + shell: bash + # - name: 检查 tag 是否已存在 + # run: | + # TAG_NAME="${VERSION}" + # if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME"; then + # echo "Tag $TAG_NAME 已存在,发布中止" + # exit 1 + # fi + # shell: bash + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' # caching pip dependencies + - run: pip install paddlepaddle==3.0.0 + - run: pip install -r requirements.txt + - run: pip freeze > requirements.txt + - run: pip install torch_directml==0.2.5.dev240914 + - run: pip install QPT==1.0b8 setuptools + - name: 获取 site-packages 路径 + shell: bash + run: | + SITE_PACKAGES=$(python -c "import site, os; print(os.path.join(site.getsitepackages()[0], 'Lib', 'site-packages'))") + SITE_PACKAGES_UNIX=$(cygpath -u "$SITE_PACKAGES") + echo "site-packages路径: $SITE_PACKAGES" + echo "site-packages UNIX路径: $SITE_PACKAGES_UNIX" + echo "SITE_PACKAGES_UNIX=$SITE_PACKAGES_UNIX" >> $GITHUB_ENV + echo "SITE_PACKAGES=$SITE_PACKAGES" >> $GITHUB_ENV + - name: 修复QPT内部错误 + run: sed -i '98c\ try:\n dep = pkg.requires()\n except TypeError:\n continue' ${SITE_PACKAGES_UNIX}/qpt/kernel/qpackage.py + shell: bash + - name: Start SSH via tmate + if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') + uses: mxschmitt/action-tmate@v3 + - run: | + python backend/tools/makedist.py --directml && \ + mv ../vsr_out ./vsr_out + env: + QPT_Action: "True" + shell: bash + - name: 上传 Debug 文件夹到 Artifacts + uses: actions/upload-artifact@v4 + with: + name: vsr-v${{ env.VERSION }}-windows-directml-debug + path: vsr_out/Debug/ + - name: 上传 Release 文件夹到 Artifacts + uses: actions/upload-artifact@v4 + with: + name: vsr-v${{ env.VERSION }}-windows-directml-release + path: vsr_out/Release/ + - name: 打包 Release 文件夹 + run: | + cd vsr_out/Release + 7z a -t7z -mx=9 -m0=LZMA2 -ms=on -mfb=64 -md=32m -mmt=on -v2000m vsr-v${{ env.VERSION }}-windows-directml.7z * && \ + # 检测是否只有一个分卷 + if [ -f vsr-v${{ env.VERSION }}-windows-directml.7z.001 ] && [ ! -f vsr-v${{ env.VERSION }}-windows-directml.7z.002 ]; then \ + mv vsr-v${{ env.VERSION }}-windows-directml.7z.001 vsr-v${{ env.VERSION }}-windows-directml.7z; fi + shell: bash + - name: Release + uses: softprops/action-gh-release@v1 + with: + prerelease: true + tag_name: ${{ env.VERSION }} + target_commitish: ${{ github.sha }} + name: 硬字幕提取器 ${{ env.VERSION }} + files: | + vsr_out/Release/vsr-v${{ env.VERSION }}-windows-directml.7z* \ No newline at end of file diff --git a/backend/tools/makedist.py b/backend/tools/makedist.py new file mode 100644 index 0000000..5e236b3 --- /dev/null +++ b/backend/tools/makedist.py @@ -0,0 +1,65 @@ +import argparse +import os +from qpt.executor import CreateExecutableModule as CEM +from qpt.modules.cuda import CopyCUDAPackage +from qpt.smart_opt import set_default_pip_source +from qpt.kernel.qinterpreter import PYPI_PIP_SOURCE +from qpt.modules.package import CustomPackage, DEFAULT_DEPLOY_MODE + + + +def main(): + WORK_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + LAUNCH_PATH = os.path.join(WORK_DIR, 'gui.py') + SAVE_PATH = os.path.join(os.path.dirname(WORK_DIR), 'vsr_out') + ICON_PATH = os.path.join(WORK_DIR, "design", "vsr.ico") + + # 解析命令行参数 + parser = argparse.ArgumentParser(description="打包程序") + parser.add_argument( + "--cuda", + nargs="?", # 可选参数值 + const="11.8", # 如果只写 --cuda,默认值是 10.2 + default=None, # 不写 --cuda,则为 None + help="是否包含CUDA模块,可指定版本,如 --cuda 或 --cuda=11.8" + ) + parser.add_argument( + "--directml", + nargs="?", # 可选参数值 + const=True, # 如果只写 --directml,默认为True + default=None, # 不写 --directml,则为 None + help="是否使用DirectML加速,仅指定 --directml 即可启用" + ) + + args = parser.parse_args() + + sub_modules = [] + + if args.cuda == "11.8": + sub_modules.append(CustomPackage("torch==2.7.0 torchvision==0.22.0", deploy_mode=DEFAULT_DEPLOY_MODE, find_links=PYPI_PIP_SOURCE, opts="--index-url https://download.pytorch.org/whl/cu118 ")) + elif args.cuda == "12.6": + sub_modules.append(CustomPackage("torch==2.7.0 torchvision==0.22.0", deploy_mode=DEFAULT_DEPLOY_MODE, find_links=PYPI_PIP_SOURCE, opts="--index-url https://download.pytorch.org/whl/cu126 ")) + elif args.cuda == "12.8": + sub_modules.append(CustomPackage("torch==2.7.0 torchvision==0.22.0", deploy_mode=DEFAULT_DEPLOY_MODE, find_links=PYPI_PIP_SOURCE, opts="--index-url https://download.pytorch.org/whl/cu128 ")) + + if args.directml: + sub_modules.append(CustomPackage("torch_directml==0.2.5.dev240914", deploy_mode=DEFAULT_DEPLOY_MODE)) + + if os.getenv("QPT_Action") == "True": + set_default_pip_source(PYPI_PIP_SOURCE) + + module = CEM( + work_dir=WORK_DIR, + launcher_py_path=LAUNCH_PATH, + save_path=SAVE_PATH, + icon=ICON_PATH, + hidden_terminal=False, + requirements_file="./requirements.txt", + sub_modules=sub_modules, + ) + + module.make() + + +if __name__ == '__main__': + main() \ No newline at end of file