From cb1920adc4a3110363aeb9a5164c4456442efb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E9=A3=8E=E9=80=8D=E9=81=A5=E6=B8=B8?= Date: Wed, 11 Nov 2026 23:52:13 +0800 Subject: [PATCH 1/3] Fix CosyVoice2 CUDA inference and integrate root runtime dependencies --- .gitignore | 4 + dependencies/dependencies.yaml | 33 +++ dependencies/dependency_config.test.cjs | 14 ++ dependencies/linux-dependencies.yaml | 217 +++++++++++++++++- dependencies/linux.lock | 179 +++++++++++++-- dependencies/requirements-linux.txt | 18 +- dependencies/requirements-windows.txt | 13 +- dependencies/windows-dependencies.yaml | 107 ++++++++- dependencies/windows.lock | 93 +++++++- doc/CosyVoice2.md | 35 +++ extensions/Voice/ssui_voice/Cosyvoice.py | 173 +++++++------- .../Voice/vendor/cosyvoice/cli/frontend.py | 25 +- .../Voice/vendor/cosyvoice/cli/model.py | 23 +- extensions/Voice/vendor/cosyvoice/llm/llm.py | 2 +- package.json | 3 +- scripts/cosyvoice_smoke.py | 70 ++++++ tests/cosyvoice_adapter_test.py | 65 ++++++ tests/model/cosyvoice_model_test.py | 56 ++--- 18 files changed, 956 insertions(+), 174 deletions(-) create mode 100644 doc/CosyVoice2.md create mode 100644 scripts/cosyvoice_smoke.py create mode 100644 tests/cosyvoice_adapter_test.py diff --git a/.gitignore b/.gitignore index 7d265749..aee55808 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,7 @@ desktop/src-tauri/workflow/txt2img/ # Native test build cache (directory or local symlink) /desktop/src-tauri/target /.yarn-cache/ + +# Local model validation caches and retained media +/.runtime-cache/ +/artifacts/ diff --git a/dependencies/dependencies.yaml b/dependencies/dependencies.yaml index 04f92ca0..bc775d5f 100644 --- a/dependencies/dependencies.yaml +++ b/dependencies/dependencies.yaml @@ -251,3 +251,36 @@ overrides: # Last Numba/LLVM pair with official CPython 3.12 macOS Intel wheels. numba: '==0.62.1' llvmlite: '==0.45.1' + + # CosyVoice2 inference dependencies share the root CUDA runtime. + # Other profiles retain their platform-specific wheels and constraints. + - when: + os: [linux, windows] + arch: x64 + backend: cuda + packages: + onnxruntime: null + onnxruntime-gpu: "==1.22.0" + HyperPyYAML: "==1.2.2" + # HyperPyYAML 1.2.2 needs the pre-0.19 loader API. + ruamel.yaml: "==0.18.6" + conformer: ">=0.3.2" + soundfile: ">=0.12.1" + librosa: "==0.11.0" + openai-whisper: "==20240930" + inflect: ">=7.3.1" + WeTextProcessing: "@ https://github.com/sunxfancy/pynini-2.1.6.post1/releases/download/2.1.6.post1/WeTextProcessing-1.0.4-py3-none-any.whl" + hydra-core: "==1.3.2" + lightning: ">=2.2.4" + rich: ">=13.7.1" + gdown: ">=5.1.0" + wget: ">=3.2" + # Newer PyArrow wheels require NumPy 2; retain Torch 2.4 compatibility. + pyarrow: "==20.0.0" + - when: + os: linux + arch: x64 + backend: cuda + packages: + pynini: "==2.1.6.post1" + pyworld: "==0.3.5" diff --git a/dependencies/dependency_config.test.cjs b/dependencies/dependency_config.test.cjs index d68b0bdc..3a5ab6dc 100644 --- a/dependencies/dependency_config.test.cjs +++ b/dependencies/dependency_config.test.cjs @@ -184,3 +184,17 @@ test('generated lock graph preserves uv root and reverse-dependency annotations' assert.ok(cuda.requirements.some(line => line.startsWith('nvdiffrast @ ') && line.includes('/v0.3.3.1/'))); assert.ok(!cuda.requirements.some(line => line.startsWith('natten '))); }); + +test('CosyVoice CUDA dependencies use one ONNX runtime and retain native platform wheels', () => { + const spec = loadConfig(); + for (const os of ['linux', 'windows']) { + const { requirements } = resolveDependencies({ os, arch: 'x64', backend: 'cuda' }, spec); + assert.ok(requirements.includes('onnxruntime-gpu==1.22.0')); + assert.ok(!requirements.some(line => /^onnxruntime[<>=@]/.test(line))); + assert.ok(requirements.includes('HyperPyYAML==1.2.2')); + assert.ok(requirements.includes('ruamel.yaml==0.18.6')); + assert.ok(requirements.includes('pyarrow==20.0.0')); + const pynini = requirements.find(line => line.startsWith('pynini')); + assert.ok(os === 'windows' ? pynini.includes('win_amd64.whl') : pynini === 'pynini==2.1.6.post1'); + } +}); diff --git a/dependencies/linux-dependencies.yaml b/dependencies/linux-dependencies.yaml index 89606e61..3b3722b7 100644 --- a/dependencies/linux-dependencies.yaml +++ b/dependencies/linux-dependencies.yaml @@ -17,6 +17,8 @@ aiohappyeyeballs: aiohttp: version: "3.11.18" isRoot: true + dependents: + - fsspec aioshutil: version: "1.5" isRoot: true @@ -28,6 +30,11 @@ annotated-types: version: "0.7.0" dependents: - pydantic +antlr4-python3-runtime: + version: "4.9.3" + dependents: + - hydra-core + - omegaconf anyio: version: "4.9.0" dependents: @@ -41,6 +48,14 @@ attrs: - jsonschema - mediapipe - referencing +audioread: + version: "3.1.0" + dependents: + - librosa +beautifulsoup4: + version: "4.15.0" + dependents: + - gdown blake3: version: "1.0.5" isRoot: true @@ -54,6 +69,7 @@ cffi: version: "1.17.1" dependents: - sounddevice + - soundfile charset-normalizer: version: "2.1.1" dependents: @@ -67,13 +83,20 @@ click: clip-anytorch: version: "2.6.0" isRoot: true +cloudpickle: + version: "3.1.2" + dependents: + - joblib coloredlogs: version: "15.0.1" dependents: - - onnxruntime + - onnxruntime-gpu compel: version: "2.1.1" isRoot: true +conformer: + version: "0.3.2" + isRoot: true contourpy: version: "1.3.2" dependents: @@ -85,6 +108,10 @@ cycler: version: "0.12.1" dependents: - matplotlib +decorator: + version: "5.3.1" + dependents: + - librosa deprecated: version: "1.2.18" isRoot: true @@ -111,6 +138,7 @@ einops: version: "0.8.1" isRoot: true dependents: + - conformer - controlnet-aux - diffsynth - spandrel @@ -130,6 +158,7 @@ filelock: dependents: - controlnet-aux - diffusers + - gdown - huggingface-hub - torch - transformers @@ -139,7 +168,7 @@ flatbuffers: version: "25.2.10" dependents: - mediapipe - - onnxruntime + - onnxruntime-gpu fonttools: version: "4.58.0" dependents: @@ -153,12 +182,17 @@ fsspec: version: "2024.6.1" dependents: - huggingface-hub + - lightning + - pytorch-lightning - torch ftfy: version: "6.3.1" dependents: - clip-anytorch - diffsynth +gdown: + version: "6.5.1" + isRoot: true gguf: version: "0.16.3" isRoot: true @@ -207,6 +241,12 @@ humanfriendly: version: "10.0" dependents: - coloredlogs +hydra-core: + version: "1.3.2" + isRoot: true +hyperpyyaml: + version: "1.2.2" + isRoot: true idna: version: "3.4" dependents: @@ -232,6 +272,17 @@ importlib-metadata: dependents: - controlnet-aux - diffusers +importlib-resources: + version: "7.1.0" + dependents: + - wetextprocessing +inflect: + version: "7.6.0" + isRoot: true +jaraco-functools: + version: "4.6.0" + dependents: + - inflect jax: version: "0.6.1" dependents: @@ -246,6 +297,11 @@ jinja2: dependents: - fastapi - torch +joblib: + version: "1.6.0" + dependents: + - librosa + - scikit-learn jsonschema: version: "4.23.0" dependents: @@ -268,7 +324,20 @@ kornia-rs: lazy-loader: version: "0.4" dependents: + - librosa - scikit-image +librosa: + version: "0.11.0" + isRoot: true +lightning: + version: "2.6.6" + isRoot: true +lightning-utilities: + version: "0.11.8" + dependents: + - lightning + - pytorch-lightning + - torchmetrics llvmlite: version: "0.44.0" dependents: @@ -307,15 +376,29 @@ modelscope: moderngl: version: "5.12.0" isRoot: true +more-itertools: + version: "11.2.1" + dependents: + - inflect + - jaraco-functools + - openai-whisper mpmath: version: "1.3.0" dependents: - sympy +msgpack: + version: "1.2.4" + dependents: + - librosa multidict: version: "6.4.4" dependents: - aiohttp - yarl +narwhals: + version: "2.28.0" + dependents: + - scikit-learn networkx: version: "3.3" dependents: @@ -324,6 +407,8 @@ networkx: numba: version: "0.61.2" dependents: + - librosa + - openai-whisper - pymatting numpy: version: "1.26.3" @@ -336,12 +421,14 @@ numpy: - imageio - jax - jaxlib + - librosa - matplotlib - mediapipe - ml-dtypes - numba - onnx - - onnxruntime + - onnxruntime-gpu + - openai-whisper - opencv-contrib-python - opencv-python - opencv-python-headless @@ -351,11 +438,16 @@ numpy: - pymatting - pymeshfix - pyvista + - pyworld - rembg - scikit-image + - scikit-learn - scipy + - soundfile + - soxr - spandrel - tifffile + - torchmetrics - torchsde - torchvision - transformers @@ -414,12 +506,19 @@ nvidia-nvtx-cu12: version: "12.4.99" dependents: - torch +omegaconf: + version: "2.3.1" + dependents: + - hydra-core onnx: version: "1.18.0" isRoot: true -onnxruntime: +onnxruntime-gpu: version: "1.22.0" isRoot: true +openai-whisper: + version: "20240930" + isRoot: true opencv-contrib-python: version: "4.11.0.86" dependents: @@ -441,13 +540,18 @@ packaging: dependents: - accelerate - huggingface-hub + - hydra-core - kornia - lazy-loader + - lightning + - lightning-utilities - matplotlib - - onnxruntime + - onnxruntime-gpu - peft - pooch + - pytorch-lightning - scikit-image + - torchmetrics - transformers pandas: version: "3.0.6" @@ -485,6 +589,7 @@ plyfile: pooch: version: "1.8.2" dependents: + - librosa - pyvista - rembg propcache: @@ -497,13 +602,16 @@ protobuf: dependents: - mediapipe - onnx - - onnxruntime + - onnxruntime-gpu psutil: version: "7.0.0" dependents: - accelerate - imageio - peft +pyarrow: + version: "20.0.0" + isRoot: true pycparser: version: "2.22" dependents: @@ -532,11 +640,18 @@ pymatting: pymeshfix: version: "0.17.1" isRoot: true +pynini: + version: "2.1.6.post1" + isRoot: true pyparsing: version: "3.2.3" dependents: - compel - matplotlib +pysocks: + version: "1.7.1" + dependents: + - requests python-dateutil: version: "2.9.0.post0" dependents: @@ -551,11 +666,18 @@ python-multipart: version: "0.0.20" dependents: - fastapi +pytorch-lightning: + version: "2.6.6" + dependents: + - lightning pyvista: version: "0.45.2" isRoot: true dependents: - pymeshfix +pyworld: + version: "0.3.5" + isRoot: true pyyaml: version: "6.0.2" isRoot: true @@ -563,7 +685,11 @@ pyyaml: - accelerate - gguf - huggingface-hub + - hyperpyyaml + - lightning + - omegaconf - peft + - pytorch-lightning - timm - transformers - uvicorn @@ -577,6 +703,7 @@ regex: dependents: - clip-anytorch - diffusers + - tiktoken - transformers rembg: version: "2.0.66" @@ -585,15 +712,18 @@ requests: version: "2.28.1" dependents: - diffusers + - gdown - huggingface-hub - modelscope - pooch + - tiktoken - transformers restrictedpython: version: "8.0" isRoot: true rich: version: "14.0.0" + isRoot: true dependents: - rich-toolkit - typer @@ -606,6 +736,15 @@ rpds-py: dependents: - jsonschema - referencing +ruamel-yaml: + version: "0.18.6" + isRoot: true + dependents: + - hyperpyyaml +ruamel-yaml-clib: + version: "0.2.15" + dependents: + - ruamel-yaml safetensors: version: "0.8.0" isRoot: true @@ -622,6 +761,10 @@ scikit-image: dependents: - controlnet-aux - rembg +scikit-learn: + version: "1.9.1" + dependents: + - librosa scipy: version: "1.15.3" isRoot: true @@ -629,9 +772,11 @@ scipy: - controlnet-aux - jax - jaxlib + - librosa - pymatting - rembg - scikit-image + - scikit-learn - torchsde scooby: version: "0.10.1" @@ -645,6 +790,7 @@ sentencepiece: setuptools: version: "70.2.0" dependents: + - lightning-utilities - torch shellingham: version: "1.5.4" @@ -662,6 +808,19 @@ sounddevice: version: "0.5.2" dependents: - mediapipe +soundfile: + version: "0.14.0" + isRoot: true + dependents: + - librosa +soupsieve: + version: "4.1" + dependents: + - beautifulsoup4 +soxr: + version: "1.1.0" + dependents: + - librosa spandrel: version: "0.4.1" isRoot: true @@ -672,16 +831,24 @@ starlette: sympy: version: "1.13.3" dependents: - - onnxruntime + - onnxruntime-gpu - torch texttable: version: "1.7.0" dependents: - igraph +threadpoolctl: + version: "3.8.0" + dependents: + - scikit-learn tifffile: version: "2025.5.21" dependents: - scikit-image +tiktoken: + version: "0.14.0" + dependents: + - openai-whisper timm: version: "1.0.15" dependents: @@ -698,20 +865,30 @@ torch: - accelerate - clip-anytorch - compel + - conformer - controlnet-aux - diffsynth - diffusers - kornia + - lightning + - openai-whisper - peft + - pytorch-lightning - spandrel - timm - torchaudio + - torchmetrics - torchsde - torchvision - xformers torchaudio: version: "2.4.1+cu124" isRoot: true +torchmetrics: + version: "1.0.3" + dependents: + - lightning + - pytorch-lightning torchsde: version: "0.2.6" isRoot: true @@ -728,10 +905,14 @@ tqdm: version: "4.66.5" dependents: - clip-anytorch + - gdown - gguf - huggingface-hub + - lightning - modelscope + - openai-whisper - peft + - pytorch-lightning - rembg - transformers trampoline: @@ -751,25 +932,37 @@ trimesh: triton: version: "3.0.0" dependents: + - openai-whisper - torch +typeguard: + version: "4.6.0" + dependents: + - inflect typer: version: "0.15.4" dependents: - fastapi-cli typing-extensions: - version: "4.12.2" + version: "4.16.0" dependents: - anyio + - beautifulsoup4 - fastapi - huggingface-hub + - librosa + - lightning + - lightning-utilities - onnx - pydantic - pydantic-core + - pytorch-lightning - pyvista - referencing - rich-toolkit + - soundfile - spandrel - torch + - typeguard - typer - typing-inspection typing-inspection: @@ -780,6 +973,7 @@ typing-inspection: urllib3: version: "1.26.13" dependents: + - gdown - modelscope - requests uvicorn: @@ -811,6 +1005,13 @@ websockets: isRoot: true dependents: - uvicorn +wetextprocessing: + version: "1.0.4" + url: "https://github.com/sunxfancy/pynini-2.1.6.post1/releases/download/2.1.6.post1/WeTextProcessing-1.0.4-py3-none-any.whl" + isRoot: true +wget: + version: "3.2" + isRoot: true wrapt: version: "1.17.2" dependents: diff --git a/dependencies/linux.lock b/dependencies/linux.lock index 93060aa6..579452c7 100644 --- a/dependencies/linux.lock +++ b/dependencies/linux.lock @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile dependencies\requirements-linux.txt -o dependencies\linux.lock --python-platform x86_64-unknown-linux-gnu --python-version 3.12.8 +# uv pip compile dependencies/requirements-linux.txt -o dependencies/linux.lock --python-platform x86_64-unknown-linux-gnu --python-version 3.12.8 absl-py==2.2.2 # via mediapipe accelerate==1.7.0 @@ -11,13 +11,19 @@ accelerate==1.7.0 aiohappyeyeballs==2.6.1 # via aiohttp aiohttp==3.11.18 - # via -r dependencies/requirements-linux.txt + # via + # -r dependencies/requirements-linux.txt + # fsspec aioshutil==1.5 # via -r dependencies/requirements-linux.txt aiosignal==1.3.2 # via aiohttp annotated-types==0.7.0 # via pydantic +antlr4-python3-runtime==4.9.3 + # via + # hydra-core + # omegaconf anyio==4.9.0 # via # httpx @@ -29,6 +35,10 @@ attrs==25.3.0 # jsonschema # mediapipe # referencing +audioread==3.1.0 + # via librosa +beautifulsoup4==4.15.0 + # via gdown blake3==1.0.5 # via -r dependencies/requirements-linux.txt certifi==2022.12.7 @@ -37,7 +47,9 @@ certifi==2022.12.7 # httpx # requests cffi==1.17.1 - # via sounddevice + # via + # sounddevice + # soundfile charset-normalizer==2.1.1 # via requests click==8.1.8 @@ -47,16 +59,22 @@ click==8.1.8 # uvicorn clip-anytorch==2.6.0 # via -r dependencies/requirements-linux.txt +cloudpickle==3.1.2 + # via joblib coloredlogs==15.0.1 - # via onnxruntime + # via onnxruntime-gpu compel==2.1.1 # via -r dependencies/requirements-linux.txt +conformer==0.3.2 + # via -r dependencies/requirements-linux.txt contourpy==1.3.2 # via matplotlib controlnet-aux==0.0.7 # via -r dependencies/requirements-linux.txt cycler==0.12.1 # via matplotlib +decorator==5.3.1 + # via librosa deprecated==1.2.18 # via -r dependencies/requirements-linux.txt diffsynth==2.1.12 @@ -74,6 +92,7 @@ easydict==1.13 einops==0.8.1 # via # -r dependencies/requirements-linux.txt + # conformer # controlnet-aux # diffsynth # spandrel @@ -87,6 +106,7 @@ filelock==3.13.1 # via # controlnet-aux # diffusers + # gdown # huggingface-hub # torch # transformers @@ -95,7 +115,7 @@ filelock==3.13.1 flatbuffers==25.2.10 # via # mediapipe - # onnxruntime + # onnxruntime-gpu fonttools==4.58.0 # via matplotlib frozenlist==1.6.0 @@ -105,11 +125,15 @@ frozenlist==1.6.0 fsspec==2024.6.1 # via # huggingface-hub + # lightning + # pytorch-lightning # torch ftfy==6.3.1 # via # clip-anytorch # diffsynth +gdown==6.5.1 + # via -r dependencies/requirements-linux.txt gguf==0.16.3 # via -r dependencies/requirements-linux.txt glcontext==3.0.0 @@ -142,6 +166,10 @@ huggingface-hub==0.36.2 # transformers humanfriendly==10.0 # via coloredlogs +hydra-core==1.3.2 + # via -r dependencies/requirements-linux.txt +hyperpyyaml==1.2.2 + # via -r dependencies/requirements-linux.txt idna==3.4 # via # anyio @@ -161,6 +189,12 @@ importlib-metadata==7.1.0 # via # controlnet-aux # diffusers +importlib-resources==7.1.0 + # via wetextprocessing +inflect==7.6.0 + # via -r dependencies/requirements-linux.txt +jaraco-functools==4.6.0 + # via inflect jax==0.6.1 # via mediapipe jaxlib==0.6.1 @@ -171,6 +205,10 @@ jinja2==3.1.4 # via # fastapi # torch +joblib==1.6.0 + # via + # librosa + # scikit-learn jsonschema==4.23.0 # via rembg jsonschema-specifications==2025.4.1 @@ -182,7 +220,18 @@ kornia==0.8.1 kornia-rs==0.1.9 # via kornia lazy-loader==0.4 - # via scikit-image + # via + # librosa + # scikit-image +librosa==0.11.0 + # via -r dependencies/requirements-linux.txt +lightning==2.6.6 + # via -r dependencies/requirements-linux.txt +lightning-utilities==0.11.8 + # via + # lightning + # pytorch-lightning + # torchmetrics llvmlite==0.44.0 # via numba markdown-it-py==3.0.0 @@ -207,18 +256,30 @@ modelscope==1.26.0 # via diffsynth moderngl==5.12.0 # via -r dependencies/requirements-linux.txt +more-itertools==11.2.1 + # via + # inflect + # jaraco-functools + # openai-whisper mpmath==1.3.0 # via sympy +msgpack==1.2.4 + # via librosa multidict==6.4.4 # via # aiohttp # yarl +narwhals==2.28.0 + # via scikit-learn networkx==3.3 # via # scikit-image # torch numba==0.61.2 - # via pymatting + # via + # librosa + # openai-whisper + # pymatting numpy==1.26.3 # via # accelerate @@ -229,12 +290,14 @@ numpy==1.26.3 # imageio # jax # jaxlib + # librosa # matplotlib # mediapipe # ml-dtypes # numba # onnx - # onnxruntime + # onnxruntime-gpu + # openai-whisper # opencv-contrib-python # opencv-python # opencv-python-headless @@ -244,11 +307,16 @@ numpy==1.26.3 # pymatting # pymeshfix # pyvista + # pyworld # rembg # scikit-image + # scikit-learn # scipy + # soundfile + # soxr # spandrel # tifffile + # torchmetrics # torchsde # torchvision # transformers @@ -286,9 +354,13 @@ nvidia-nvjitlink-cu12==12.4.99 # torch nvidia-nvtx-cu12==12.4.99 # via torch +omegaconf==2.3.1 + # via hydra-core onnx==1.18.0 # via -r dependencies/requirements-linux.txt -onnxruntime==1.22.0 +onnxruntime-gpu==1.22.0 + # via -r dependencies/requirements-linux.txt +openai-whisper==20240930 # via -r dependencies/requirements-linux.txt opencv-contrib-python==4.11.0.86 # via mediapipe @@ -302,13 +374,18 @@ packaging==24.1 # via # accelerate # huggingface-hub + # hydra-core # kornia # lazy-loader + # lightning + # lightning-utilities # matplotlib - # onnxruntime + # onnxruntime-gpu # peft # pooch + # pytorch-lightning # scikit-image + # torchmetrics # transformers pandas==3.0.6 # via diffsynth @@ -338,6 +415,7 @@ plyfile==1.1 # via -r dependencies/requirements-linux.txt pooch==1.8.2 # via + # librosa # pyvista # rembg propcache==0.3.1 @@ -348,12 +426,14 @@ protobuf==4.25.7 # via # mediapipe # onnx - # onnxruntime + # onnxruntime-gpu psutil==7.0.0 # via # accelerate # imageio # peft +pyarrow==20.0.0 + # via -r dependencies/requirements-linux.txt pycparser==2.22 # via cffi pydantic==2.11.5 @@ -371,10 +451,14 @@ pymatting==1.1.14 # via rembg pymeshfix==0.17.1 # via -r dependencies/requirements-linux.txt +pynini==2.1.6.post1 + # via -r dependencies/requirements-linux.txt pyparsing==3.2.3 # via # compel # matplotlib +pysocks==1.7.1 + # via requests python-dateutil==2.9.0.post0 # via # matplotlib @@ -385,17 +469,25 @@ python-dotenv==1.1.0 # uvicorn python-multipart==0.0.20 # via fastapi +pytorch-lightning==2.6.6 + # via lightning pyvista==0.45.2 # via # -r dependencies/requirements-linux.txt # pymeshfix +pyworld==0.3.5 + # via -r dependencies/requirements-linux.txt pyyaml==6.0.2 # via # -r dependencies/requirements-linux.txt # accelerate # gguf # huggingface-hub + # hyperpyyaml + # lightning + # omegaconf # peft + # pytorch-lightning # timm # transformers # uvicorn @@ -407,20 +499,24 @@ regex==2024.11.6 # via # clip-anytorch # diffusers + # tiktoken # transformers rembg==2.0.66 # via -r dependencies/requirements-linux.txt requests==2.28.1 # via # diffusers + # gdown # huggingface-hub # modelscope # pooch + # tiktoken # transformers restrictedpython==8.0 # via -r dependencies/requirements-linux.txt rich==14.0.0 # via + # -r dependencies/requirements-linux.txt # rich-toolkit # typer rich-toolkit==0.14.6 @@ -429,6 +525,12 @@ rpds-py==0.25.1 # via # jsonschema # referencing +ruamel-yaml==0.18.6 + # via + # -r dependencies/requirements-linux.txt + # hyperpyyaml +ruamel-yaml-clib==0.2.15 + # via ruamel-yaml safetensors==0.8.0 # via # -r dependencies/requirements-linux.txt @@ -443,15 +545,19 @@ scikit-image==0.25.2 # via # controlnet-aux # rembg +scikit-learn==1.9.1 + # via librosa scipy==1.15.3 # via # -r dependencies/requirements-linux.txt # controlnet-aux # jax # jaxlib + # librosa # pymatting # rembg # scikit-image + # scikit-learn # torchsde scooby==0.10.1 # via pyvista @@ -460,7 +566,9 @@ sentencepiece==0.2.0 # gguf # mediapipe setuptools==70.2.0 - # via torch + # via + # lightning-utilities + # torch shellingham==1.5.4 # via typer six==1.17.0 @@ -469,18 +577,30 @@ sniffio==1.3.1 # via anyio sounddevice==0.5.2 # via mediapipe +soundfile==0.14.0 + # via + # -r dependencies/requirements-linux.txt + # librosa +soupsieve==4.1 + # via beautifulsoup4 +soxr==1.1.0 + # via librosa spandrel==0.4.1 # via -r dependencies/requirements-linux.txt starlette==0.41.3 # via fastapi sympy==1.13.3 # via - # onnxruntime + # onnxruntime-gpu # torch texttable==1.7.0 # via igraph +threadpoolctl==3.8.0 + # via scikit-learn tifffile==2025.5.21 # via scikit-image +tiktoken==0.14.0 + # via openai-whisper timm==1.0.15 # via controlnet-aux tokenizers==0.22.2 @@ -493,19 +613,28 @@ torch==2.4.1+cu124 # accelerate # clip-anytorch # compel + # conformer # controlnet-aux # diffsynth # diffusers # kornia + # lightning + # openai-whisper # peft + # pytorch-lightning # spandrel # timm # torchaudio + # torchmetrics # torchsde # torchvision # xformers torchaudio==2.4.1+cu124 # via -r dependencies/requirements-linux.txt +torchmetrics==1.0.3 + # via + # lightning + # pytorch-lightning torchsde==0.2.6 # via -r dependencies/requirements-linux.txt torchvision==0.19.1+cu124 @@ -519,10 +648,14 @@ torchvision==0.19.1+cu124 tqdm==4.66.5 # via # clip-anytorch + # gdown # gguf # huggingface-hub + # lightning # modelscope + # openai-whisper # peft + # pytorch-lightning # rembg # transformers trampoline==0.1.2 @@ -536,22 +669,33 @@ transformers==4.57.6 trimesh==4.6.10 # via -r dependencies/requirements-linux.txt triton==3.0.0 - # via torch + # via + # openai-whisper + # torch +typeguard==4.6.0 + # via inflect typer==0.15.4 # via fastapi-cli -typing-extensions==4.12.2 +typing-extensions==4.16.0 # via # anyio + # beautifulsoup4 # fastapi # huggingface-hub + # librosa + # lightning + # lightning-utilities # onnx # pydantic # pydantic-core + # pytorch-lightning # pyvista # referencing # rich-toolkit + # soundfile # spandrel # torch + # typeguard # typer # typing-inspection typing-inspection==0.4.1 @@ -560,6 +704,7 @@ typing-inspection==0.4.1 # pydantic-settings urllib3==1.26.13 # via + # gdown # modelscope # requests uvicorn==0.34.2 @@ -580,6 +725,10 @@ websockets==15.0.1 # via # -r dependencies/requirements-linux.txt # uvicorn +wetextprocessing @ https://github.com/sunxfancy/pynini-2.1.6.post1/releases/download/2.1.6.post1/WeTextProcessing-1.0.4-py3-none-any.whl + # via -r dependencies/requirements-linux.txt +wget==3.2 + # via -r dependencies/requirements-linux.txt wrapt==1.17.2 # via deprecated xatlas==0.0.10 diff --git a/dependencies/requirements-linux.txt b/dependencies/requirements-linux.txt index c4244a5f..de684672 100644 --- a/dependencies/requirements-linux.txt +++ b/dependencies/requirements-linux.txt @@ -7,6 +7,7 @@ aioshutil>=1.5 blake3>=1.0.4 clip-anytorch>=2.6.0 compel>=2.0.3 +conformer>=0.3.2 controlnet-aux>=0.0.7 deprecated>=1.2.18 diffsynth>=1.1.7 @@ -14,28 +15,41 @@ diffusers[torch]>=0.37.0,<0.41 easydict>=1.13 einops>=0.8.0 fastapi[standard]>=0.115.6 +gdown>=5.1.0 gguf>=0.14.0 huggingface_hub[hf-transfer,hf_xet]>=0.31 +hydra-core==1.3.2 +HyperPyYAML==1.2.2 igraph>=0.11.8 +inflect>=7.3.1 kornia>=0.8.0 +librosa==0.11.0 +lightning>=2.2.4 matplotlib>=3.10.1 mediapipe>=0.10.21 moderngl>=5.12.0 onnx>=1.17.0 -onnxruntime>=1.21.0 +onnxruntime-gpu==1.22.0 +openai-whisper==20240930 peft==0.17.1 picklescan>=0.0.24 pillow>=11.0.0 plyfile>=1.1 +pyarrow==20.0.0 pydantic>=2.10.4 pydantic-settings>=2.7.0 pymeshfix>=0.17.0 +pynini==2.1.6.post1 pyvista>=0.44.2 +pyworld==0.3.5 pyyaml>=6.0.2 rembg>=2.0.65 RestrictedPython>=8.0 +rich>=13.7.1 +ruamel.yaml==0.18.6 safetensors>=0.4.5 scipy>=1.15.2 +soundfile>=0.12.1 spandrel>=0.4.1 tokenizers>=0.20.0 torch==2.4.1+cu124 @@ -46,6 +60,8 @@ transformers>=4.51.3,<5 trimesh>=4.6.5 virtualenv>=20.28.0 websockets>=14.1 +WeTextProcessing @ https://github.com/sunxfancy/pynini-2.1.6.post1/releases/download/2.1.6.post1/WeTextProcessing-1.0.4-py3-none-any.whl +wget>=3.2 xatlas>=0.0.9 xformers==0.0.28.post1 --extra-index-url https://download.pytorch.org/whl/cu124 diff --git a/dependencies/requirements-windows.txt b/dependencies/requirements-windows.txt index 9d751bab..d53c5730 100644 --- a/dependencies/requirements-windows.txt +++ b/dependencies/requirements-windows.txt @@ -18,14 +18,18 @@ easydict>=1.13 einops>=0.8.0 fastapi[standard]>=0.115.6 ftfy>=6.3 +gdown>=5.1.0 gguf>=0.10.0 huggingface_hub[hf-transfer,hf_xet]>=0.36.2,<1 hydra-core==1.3.2 +HyperPyYAML==1.2.2 igraph>=0.11.8 imageio[ffmpeg]>=2.37.0 +inflect>=7.3.1 kaolin @ https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.4.0_cu124/kaolin-0.17.0-cp312-cp312-win_amd64.whl kornia>=0.8.0 librosa==0.11.0 +lightning>=2.2.4 matplotlib>=3.10.1 mediapipe>=0.10.21 modelscope==1.26.0 @@ -33,14 +37,14 @@ moderngl>=5.12.0 networkx==3.3 nvdiffrast @ https://github.com/sunxfancy/nvdiffrast/releases/download/v0.3.3.1/nvdiffrast-0.3.3.1-cp312-cp312-win_amd64.whl onnx>=1.17.0 -onnxruntime>=1.21.0 +onnxruntime-gpu==1.22.0 openai-whisper==20240930 opencv-python-headless>=4.11.0.86 peft==0.17.1 picklescan>=0.0.24 pillow>=11.0.0 plyfile>=1.1 -pyarrow>=20.0.0 +pyarrow==20.0.0 pydantic>=2.10.4 pydantic-settings>=2.7.0 pymeshfix>=0.17.0 @@ -50,11 +54,13 @@ pyworld==0.3.4 pyyaml>=6.0.2 rembg>=2.0.65 RestrictedPython>=8.0 +rich>=13.7.1 +ruamel.yaml==0.18.6 safetensors>=0.4.5 scipy>=1.15.2 scipy>=1.15 sentencepiece==0.2.0 -soundfile==0.12.1 +soundfile>=0.12.1 spandrel>=0.4.1 spconv-cu124>=2.3.8 tiktoken>=0.9.0 @@ -72,6 +78,7 @@ triton-windows==3.1.0.post17 virtualenv>=20.28.0 websockets>=14.1 WeTextProcessing @ https://github.com/sunxfancy/pynini-2.1.6.post1/releases/download/2.1.6.post1/WeTextProcessing-1.0.4-py3-none-any.whl +wget>=3.2 xatlas>=0.0.9 xformers==0.0.28.post1 --extra-index-url https://download.pytorch.org/whl/cu124 diff --git a/dependencies/windows-dependencies.yaml b/dependencies/windows-dependencies.yaml index 0ae96257..30c29672 100644 --- a/dependencies/windows-dependencies.yaml +++ b/dependencies/windows-dependencies.yaml @@ -16,6 +16,8 @@ aiohappyeyeballs: aiohttp: version: "3.11.14" isRoot: true + dependents: + - fsspec aioshutil: version: "1.5" isRoot: true @@ -53,6 +55,10 @@ audioread: version: "3.0.1" dependents: - librosa +beautifulsoup4: + version: "4.15.0" + dependents: + - gdown bitsandbytes: version: "0.45.4" isRoot: true @@ -103,7 +109,7 @@ colorama: coloredlogs: version: "15.0.1" dependents: - - onnxruntime + - onnxruntime-gpu comm: version: "0.2.2" dependents: @@ -206,6 +212,7 @@ filelock: dependents: - controlnet-aux - diffusers + - gdown - huggingface-hub - torch - transformers @@ -225,7 +232,7 @@ flatbuffers: version: "25.2.10" dependents: - mediapipe - - onnxruntime + - onnxruntime-gpu fonttools: version: "4.56.0" dependents: @@ -239,12 +246,17 @@ fsspec: version: "2024.6.1" dependents: - huggingface-hub + - lightning + - pytorch-lightning - torch ftfy: version: "6.3.1" isRoot: true dependents: - clip-anytorch +gdown: + version: "6.5.1" + isRoot: true gguf: version: "0.14.0" isRoot: true @@ -296,6 +308,9 @@ humanfriendly: hydra-core: version: "1.3.2" isRoot: true +hyperpyyaml: + version: "1.2.2" + isRoot: true idna: version: "3.4" dependents: @@ -325,6 +340,9 @@ importlib-resources: version: "6.5.2" dependents: - wetextprocessing +inflect: + version: "7.6.0" + isRoot: true ipycanvas: version: "0.13.3" dependents: @@ -351,6 +369,10 @@ itsdangerous: version: "2.2.0" dependents: - flask +jaraco-functools: + version: "4.6.0" + dependents: + - inflect jax: version: "0.5.3" dependents: @@ -422,6 +444,15 @@ lazy-loader: librosa: version: "0.11.0" isRoot: true +lightning: + version: "2.6.6" + isRoot: true +lightning-utilities: + version: "0.11.8" + dependents: + - lightning + - pytorch-lightning + - torchmetrics llvmlite: version: "0.44.0" dependents: @@ -471,6 +502,8 @@ moderngl: more-itertools: version: "10.7.0" dependents: + - inflect + - jaraco-functools - openai-whisper mpmath: version: "1.3.0" @@ -532,7 +565,7 @@ numpy: - numba - nvdiffrast - onnx - - onnxruntime + - onnxruntime-gpu - openai-whisper - opencv-contrib-python - opencv-python @@ -551,6 +584,7 @@ numpy: - spandrel - spconv-cu124 - tifffile + - torchmetrics - torchsde - torchvision - transformers @@ -569,8 +603,8 @@ omegaconf: onnx: version: "1.17.0" isRoot: true -onnxruntime: - version: "1.21.0" +onnxruntime-gpu: + version: "1.22.0" isRoot: true openai-whisper: version: "20240930" @@ -600,12 +634,16 @@ packaging: - hydra-core - kornia - lazy-loader + - lightning + - lightning-utilities - marshmallow - matplotlib - - onnxruntime + - onnxruntime-gpu - peft - pooch + - pytorch-lightning - scikit-image + - torchmetrics - transformers parso: version: "0.8.4" @@ -670,7 +708,7 @@ protobuf: dependents: - mediapipe - onnx - - onnxruntime + - onnxruntime-gpu psutil: version: "7.0.0" dependents: @@ -739,6 +777,10 @@ pyreadline3: version: "3.5.4" dependents: - humanfriendly +pysocks: + version: "1.7.1" + dependents: + - requests python-dateutil: version: "2.9.0.post0" dependents: @@ -753,6 +795,10 @@ python-multipart: version: "0.0.20" dependents: - fastapi +pytorch-lightning: + version: "2.6.6" + dependents: + - lightning pyvista: version: "0.44.2" isRoot: true @@ -773,8 +819,11 @@ pyyaml: - accelerate - gguf - huggingface-hub + - hyperpyyaml + - lightning - omegaconf - peft + - pytorch-lightning - timm - transformers - uvicorn @@ -802,6 +851,7 @@ requests: dependents: - ccimport - diffusers + - gdown - huggingface-hub - modelscope - pooch @@ -812,6 +862,7 @@ restrictedpython: isRoot: true rich: version: "13.9.4" + isRoot: true dependents: - rich-toolkit - typer @@ -824,6 +875,15 @@ rpds-py: dependents: - jsonschema - referencing +ruamel-yaml: + version: "0.18.6" + isRoot: true + dependents: + - hyperpyyaml +ruamel-yaml-clib: + version: "0.2.15" + dependents: + - ruamel-yaml safetensors: version: "0.8.0" isRoot: true @@ -870,6 +930,7 @@ sentencepiece: setuptools: version: "70.2.0" dependents: + - lightning-utilities - torch shellingham: version: "1.5.4" @@ -892,6 +953,10 @@ soundfile: isRoot: true dependents: - librosa +soupsieve: + version: "4.1" + dependents: + - beautifulsoup4 soxr: version: "0.5.0.post1" dependents: @@ -914,7 +979,7 @@ sympy: version: "1.13.1" dependents: - cumm-cu124 - - onnxruntime + - onnxruntime-gpu - torch termcolor: version: "2.5.0" @@ -959,11 +1024,14 @@ torch: - controlnet-aux - diffusers - kornia + - lightning - openai-whisper - peft + - pytorch-lightning - spandrel - timm - torchaudio + - torchmetrics - torchsde - torchvision - xformers @@ -974,6 +1042,11 @@ torch-scatter: torchaudio: version: "2.4.1+cu124" isRoot: true +torchmetrics: + version: "1.0.3" + dependents: + - lightning + - pytorch-lightning torchsde: version: "0.2.6" isRoot: true @@ -994,12 +1067,15 @@ tqdm: version: "4.66.5" dependents: - clip-anytorch + - gdown - gguf - huggingface-hub - kaolin + - lightning - modelscope - openai-whisper - peft + - pytorch-lightning - rembg - transformers traitlets: @@ -1031,24 +1107,33 @@ trimesh: triton-windows: version: "3.1.0.post17" isRoot: true +typeguard: + version: "4.6.0" + dependents: + - inflect typer: version: "0.15.2" dependents: - fastapi-cli typing-extensions: - version: "4.12.2" + version: "4.16.0" dependents: - anyio + - beautifulsoup4 - fastapi - huggingface-hub - librosa + - lightning + - lightning-utilities - pydantic - pydantic-core + - pytorch-lightning - pyvista - referencing - rich-toolkit - spandrel - torch + - typeguard - typer - typing-inspect - typing-inspection @@ -1063,6 +1148,7 @@ typing-inspection: urllib3: version: "1.26.13" dependents: + - gdown - modelscope - requests usd-core: @@ -1107,6 +1193,9 @@ wetextprocessing: version: "1.0.4" url: "https://github.com/sunxfancy/pynini-2.1.6.post1/releases/download/2.1.6.post1/WeTextProcessing-1.0.4-py3-none-any.whl" isRoot: true +wget: + version: "3.2" + isRoot: true widgetsnbextension: version: "4.0.13" dependents: diff --git a/dependencies/windows.lock b/dependencies/windows.lock index cabaa16f..99eb4b5d 100644 --- a/dependencies/windows.lock +++ b/dependencies/windows.lock @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile dependencies\requirements-windows.txt -o dependencies\windows.lock --python-platform x86_64-pc-windows-msvc --python-version 3.12.8 +# uv pip compile dependencies/requirements-windows.txt -o dependencies/windows.lock --python-platform x86_64-pc-windows-msvc --python-version 3.12.8 absl-py==2.2.1 # via mediapipe accelerate==1.5.2 @@ -10,7 +10,9 @@ accelerate==1.5.2 aiohappyeyeballs==2.6.1 # via aiohttp aiohttp==3.11.14 - # via -r dependencies/requirements-windows.txt + # via + # -r dependencies/requirements-windows.txt + # fsspec aioshutil==1.5 # via -r dependencies/requirements-windows.txt aiosignal==1.3.2 @@ -36,6 +38,8 @@ attrs==25.3.0 # referencing audioread==3.0.1 # via librosa +beautifulsoup4==4.15.0 + # via gdown bitsandbytes==0.45.4 # via -r dependencies/requirements-windows.txt blake3==1.0.4 @@ -72,7 +76,7 @@ colorama==0.4.6 # tqdm # uvicorn coloredlogs==15.0.1 - # via onnxruntime + # via onnxruntime-gpu comm==0.2.2 # via # ipywidgets @@ -137,6 +141,7 @@ filelock==3.13.1 # via # controlnet-aux # diffusers + # gdown # huggingface-hub # torch # transformers @@ -152,7 +157,7 @@ flask==3.1.0 flatbuffers==25.2.10 # via # mediapipe - # onnxruntime + # onnxruntime-gpu fonttools==4.56.0 # via matplotlib frozenlist==1.5.0 @@ -162,11 +167,15 @@ frozenlist==1.5.0 fsspec==2024.6.1 # via # huggingface-hub + # lightning + # pytorch-lightning # torch ftfy==6.3.1 # via # -r dependencies/requirements-windows.txt # clip-anytorch +gdown==6.5.1 + # via -r dependencies/requirements-windows.txt gguf==0.14.0 # via -r dependencies/requirements-windows.txt glcontext==3.0.0 @@ -201,6 +210,8 @@ humanfriendly==10.0 # via coloredlogs hydra-core==1.3.2 # via -r dependencies/requirements-windows.txt +hyperpyyaml==1.2.2 + # via -r dependencies/requirements-windows.txt idna==3.4 # via # anyio @@ -222,6 +233,8 @@ importlib-metadata==7.1.0 # diffusers importlib-resources==6.5.2 # via wetextprocessing +inflect==7.6.0 + # via -r dependencies/requirements-windows.txt ipycanvas==0.13.3 # via kaolin ipyevents==2.0.2 @@ -238,6 +251,8 @@ ipywidgets==8.1.5 # ipyevents itsdangerous==2.2.0 # via flask +jaraco-functools==4.6.0 + # via inflect jax==0.5.3 # via mediapipe jaxlib==0.5.3 @@ -281,6 +296,13 @@ lazy-loader==0.4 # scikit-image librosa==0.11.0 # via -r dependencies/requirements-windows.txt +lightning==2.6.6 + # via -r dependencies/requirements-windows.txt +lightning-utilities==0.11.8 + # via + # lightning + # pytorch-lightning + # torchmetrics llvmlite==0.44.0 # via numba markdown-it-py==3.0.0 @@ -312,7 +334,10 @@ modelscope==1.26.0 moderngl==5.12.0 # via -r dependencies/requirements-windows.txt more-itertools==10.7.0 - # via openai-whisper + # via + # inflect + # jaraco-functools + # openai-whisper mpmath==1.3.0 # via sympy msgpack==1.1.0 @@ -359,7 +384,7 @@ numpy==1.26.3 # numba # nvdiffrast # onnx - # onnxruntime + # onnxruntime-gpu # openai-whisper # opencv-contrib-python # opencv-python @@ -378,6 +403,7 @@ numpy==1.26.3 # spandrel # spconv-cu124 # tifffile + # torchmetrics # torchsde # torchvision # transformers @@ -391,7 +417,7 @@ omegaconf==2.3.0 # via hydra-core onnx==1.17.0 # via -r dependencies/requirements-windows.txt -onnxruntime==1.21.0 +onnxruntime-gpu==1.22.0 # via -r dependencies/requirements-windows.txt openai-whisper==20240930 # via -r dependencies/requirements-windows.txt @@ -412,12 +438,16 @@ packaging==24.1 # hydra-core # kornia # lazy-loader + # lightning + # lightning-utilities # marshmallow # matplotlib - # onnxruntime + # onnxruntime-gpu # peft # pooch + # pytorch-lightning # scikit-image + # torchmetrics # transformers parso==0.8.4 # via jedi @@ -467,7 +497,7 @@ protobuf==4.25.6 # via # mediapipe # onnx - # onnxruntime + # onnxruntime-gpu psutil==7.0.0 # via # accelerate @@ -514,6 +544,8 @@ pyparsing==3.2.3 # matplotlib pyreadline3==3.5.4 # via humanfriendly +pysocks==1.7.1 + # via requests python-dateutil==2.9.0.post0 # via # jupyter-client @@ -524,6 +556,8 @@ python-dotenv==1.1.0 # uvicorn python-multipart==0.0.20 # via fastapi +pytorch-lightning==2.6.6 + # via lightning pyvista==0.44.2 # via # -r dependencies/requirements-windows.txt @@ -540,8 +574,11 @@ pyyaml==6.0.2 # accelerate # gguf # huggingface-hub + # hyperpyyaml + # lightning # omegaconf # peft + # pytorch-lightning # timm # transformers # uvicorn @@ -563,6 +600,7 @@ requests==2.28.1 # via # ccimport # diffusers + # gdown # huggingface-hub # modelscope # pooch @@ -572,6 +610,7 @@ restrictedpython==8.0 # via -r dependencies/requirements-windows.txt rich==13.9.4 # via + # -r dependencies/requirements-windows.txt # rich-toolkit # typer rich-toolkit==0.14.0 @@ -580,6 +619,12 @@ rpds-py==0.24.0 # via # jsonschema # referencing +ruamel-yaml==0.18.6 + # via + # -r dependencies/requirements-windows.txt + # hyperpyyaml +ruamel-yaml-clib==0.2.15 + # via ruamel-yaml safetensors==0.8.0 # via # -r dependencies/requirements-windows.txt @@ -616,7 +661,9 @@ sentencepiece==0.2.0 # gguf # mediapipe setuptools==70.2.0 - # via torch + # via + # lightning-utilities + # torch shellingham==1.5.4 # via typer six==1.17.0 @@ -629,6 +676,8 @@ soundfile==0.12.1 # via # -r dependencies/requirements-windows.txt # librosa +soupsieve==4.1 + # via beautifulsoup4 soxr==0.5.0.post1 # via librosa spandrel==0.4.1 @@ -642,7 +691,7 @@ starlette==0.41.3 sympy==1.13.1 # via # cumm-cu124 - # onnxruntime + # onnxruntime-gpu # torch termcolor==2.5.0 # via fire @@ -675,11 +724,14 @@ torch==2.4.1+cu124 # controlnet-aux # diffusers # kornia + # lightning # openai-whisper # peft + # pytorch-lightning # spandrel # timm # torchaudio + # torchmetrics # torchsde # torchvision # xformers @@ -687,6 +739,10 @@ torch-scatter @ https://data.pyg.org/whl/torch-2.4.0%2Bcu124/torch_scatter-2.1.2 # via -r dependencies/requirements-windows.txt torchaudio==2.4.1+cu124 # via -r dependencies/requirements-windows.txt +torchmetrics==1.0.3 + # via + # lightning + # pytorch-lightning torchsde==0.2.6 # via -r dependencies/requirements-windows.txt torchvision==0.19.1+cu124 @@ -703,12 +759,15 @@ tornado==6.4.2 tqdm==4.66.5 # via # clip-anytorch + # gdown # gguf # huggingface-hub # kaolin + # lightning # modelscope # openai-whisper # peft + # pytorch-lightning # rembg # transformers traitlets==5.14.3 @@ -733,21 +792,28 @@ trimesh==4.6.6 # via -r dependencies/requirements-windows.txt triton-windows==3.1.0.post17 # via -r dependencies/requirements-windows.txt +typeguard==4.6.0 + # via inflect typer==0.15.2 # via fastapi-cli -typing-extensions==4.12.2 +typing-extensions==4.16.0 # via # anyio + # beautifulsoup4 # fastapi # huggingface-hub # librosa + # lightning + # lightning-utilities # pydantic # pydantic-core + # pytorch-lightning # pyvista # referencing # rich-toolkit # spandrel # torch + # typeguard # typer # typing-inspect # typing-inspection @@ -757,6 +823,7 @@ typing-inspection==0.4.0 # via pydantic urllib3==1.26.13 # via + # gdown # modelscope # requests usd-core==25.2.post1 @@ -785,6 +852,8 @@ werkzeug==3.1.3 # via flask wetextprocessing @ https://github.com/sunxfancy/pynini-2.1.6.post1/releases/download/2.1.6.post1/WeTextProcessing-1.0.4-py3-none-any.whl # via -r dependencies/requirements-windows.txt +wget==3.2 + # via -r dependencies/requirements-windows.txt widgetsnbextension==4.0.13 # via ipywidgets wrapt==1.17.2 diff --git a/doc/CosyVoice2.md b/doc/CosyVoice2.md new file mode 100644 index 00000000..7c447a89 --- /dev/null +++ b/doc/CosyVoice2.md @@ -0,0 +1,35 @@ +# CosyVoice2 + +CosyVoice2 使用根目录的共享 `.venv`。第三方代码已经随 Voice/vendor 提供,无需单独克隆 CosyVoice 或创建另一套环境。 + +在根目录运行 `yarn` 安装依赖。已有环境在更新仓库后运行 `yarn install-requirements`。依赖源位于 `dependencies/dependencies.yaml`,requirements 和 lock 均由项目命令生成。Linux / Windows x64 CUDA 目标集中声明 CosyVoice2 所需依赖;其他目标保留上游的平台专用运行时和约束。首次运行需要下载数 GB 模型。 + +```bash +yarn test:cosyvoice --prompt /absolute/path/reference.wav \ + --prompt-text "参考录音中实际说出的文字。" \ + --text "你好,欢迎使用语音合成。" --device cuda +``` + +参考音频不超过 30 秒,建议使用清晰、单人、有声录音。程序将其转成单声道 16 kHz,`--prompt-text` 必须与录音一致。默认下载 `FunAudioLLM/CosyVoice2-0.5B` 到根目录 `models/CosyVoice2-0.5B`;已有权重可通过 `--model /absolute/path/model` 指定。 + +默认输出 `artifacts/cosyvoice2/output.wav` 和同名 JSON,记录 PyTorch 版本、三个合成子模型的设备、ONNX provider、采样率和时长。`--device cuda` 要求三个模型以及语音 tokenizer 都启用 CUDA,否则报错。`--device cpu` 可在没有 GPU 的机器上验证真实合成;`auto` 自动选择可用设备。CPU 输出不能作为 CUDA 验证结果。 + +完整测试系统中的真模型测试: + +```bash +SSUI_RUN_MODEL_TESTS=1 SSUI_COSYVOICE_DEVICE=cuda yarn test_on model.cosyvoice_model_test +``` + +真模型测试使用独立进程,默认下载上游示例参考音频,保留生成结果到 `TEST_DATA_DIR/cosyvoice2-artifacts`(默认 `~/.ssui_test_data`)。可通过 `SSUI_COSYVOICE_MODEL`、`SSUI_COSYVOICE_PROMPT`、`SSUI_COSYVOICE_PROMPT_TEXT` 指定本地输入。 + +SSUI 接口为 `CosyVoiceModel.load(model_path)` 与 `GenVoice(config, model, text, prompt_audio, prompt_text)`。`prompt_audio` 使用 `Audio('wav', wav_bytes)`;结果是 WAV 字节形式的 `Voice`,保留全部合成分段。 + +共享 WeTextProcessing wheel 沿用 Windows 已使用的发行包;Linux CUDA 显式声明 pynini,避免旧版 PyPI WeTextProcessing 强制安装不适合 Python 3.12 的 pynini 2.1.5。无需 TensorRT、DeepSpeed 或 vLLM 即可运行此推理路径。 + +HyperPyYAML 的 ruamel.yaml 与配置加载所需的 pyarrow 已固定兼容版本,避免最新依赖与当前加载器 API / NumPy 1.x 不兼容。 + +为控制内存,验证命令默认跳过文本规范化,请传入已规范化文本(数字、日期等需先转为读法)。需要完整文本规范化时显式传入 `--text-frontend`,首次 FST 编译可能占用较多内存。正常 SSUI 接口保留文本规范化默认行为,按需加载单一语言并复用 FST 缓存。验证时只启动一个推理进程。 + +本次 Linux / RTX 3090 验证通过:PyTorch 2.4.1+cu124,三个合成子模型位于 cuda:0,ONNX tokenizer 使用 CUDAExecutionProvider,生成 24 kHz / 2.64 秒 WAV。单进程在 4 GiB MemoryMax、MemorySwapMax=0 的 systemd scope 下完成,迁移到最新 dev 后复测最大 RSS 4,377,880 KiB(RSS 包含共享映射,与 cgroup 内存计费不同)。未验证 Windows/macOS 实机推理,也未运行首次 FST 编译。 + +复测复用了已安装的 Python 环境和模型缓存,未重新安装整个最新 dev 依赖集合。Linux/Windows CUDA 锁文件已按最新配置源重新解析;其他目标保持上游约束。 diff --git a/extensions/Voice/ssui_voice/Cosyvoice.py b/extensions/Voice/ssui_voice/Cosyvoice.py index e5beeed4..3f4a7a30 100644 --- a/extensions/Voice/ssui_voice/Cosyvoice.py +++ b/extensions/Voice/ssui_voice/Cosyvoice.py @@ -1,86 +1,105 @@ from ssui.model_memory import ModelMemoryOptions -from typing import Optional, List, Union, Generator -import torch -import torchaudio -from ssui.config import SSUIConfig +from typing import Optional +import io +import random +import numpy as np +import soundfile as sf +import torch +import torchaudio +from ssui.config import SSUIConfig from ssui.base import Audio, Voice -from ssui.annotation import param -from ssui.controller import Random, Switch, Slider -from cosyvoice.cli.cosyvoice import CosyVoice2 -from cosyvoice.utils.file_utils import load_wav - -class CosyVoiceModel: - def __init__( - self, - model_path: str = "", - model: Optional[CosyVoice2] = None, - ): - self.model_path = model_path - self.model = model - - def getModel(self): - return self.model - - @staticmethod +from ssui.annotation import param +from ssui.controller import Random, Switch, Slider +from cosyvoice.cli.cosyvoice import CosyVoice2 + +class CosyVoiceModel: + def __init__( + self, + model_path: str = "", + model: Optional[CosyVoice2] = None, + ): + self.model_path = model_path + self.model = model + + def getModel(self): + return self.model + + @staticmethod def load(model_path: str, *, quantization: str = "none", cpu_offload: bool = False): - options = ModelMemoryOptions(quantization, cpu_offload) - model = CosyVoice2(model_path, load_jit=False, load_trt=False, fp16=False) + options = ModelMemoryOptions(quantization, cpu_offload) + model = CosyVoice2(model_path, load_jit=False, load_trt=False, fp16=False) if quantization != "none" or cpu_offload: options.configure([model.model.llm, model.model.flow, model.model.hift], device=model.model.device) - return CosyVoiceModel(model_path, model) - -@param("seed", Random(), default=42) -@param("use_zero_shot", Switch(), default=True) -@param("zero_shot_prompt", Switch(), default=True) -@param("speaker_id", Slider(0, 100, 1), default=0) -def GenVoice( - config: SSUIConfig, - model: CosyVoiceModel, - text: str, + return CosyVoiceModel(model_path, model) + +@param("seed", Random(), default=42) +@param("use_zero_shot", Switch(), default=True) +@param("zero_shot_prompt", Switch(), default=True) +@param("speaker_id", Slider(0, 100, 1), default=0) +def GenVoice( + config: SSUIConfig, + model: CosyVoiceModel, + text: str, prompt_audio: Optional[Audio] = None, + prompt_text: str = "", + text_frontend: bool = True, ): if config.is_prepare(): return Voice() - - print("GenVoice executed") - print("seed:", config["seed"]) - print("use_zero_shot:", config["use_zero_shot"]) - print("zero_shot_prompt:", config["zero_shot_prompt"]) - print("speaker_id:", config["speaker_id"]) - - # Convert prompt audio to the required format if provided - prompt_speech_16k = None - if prompt_audio and config["zero_shot_prompt"]: - prompt_speech_16k = load_wav(prompt_audio.path, 16000) - - # Generate audio based on configuration - if config["use_zero_shot"]: - if prompt_speech_16k: - # Use zero-shot with prompt - outputs = model.getModel().inference_zero_shot( - text, - f"Speaker {config['speaker_id']}", - prompt_speech_16k, - stream=False - ) - else: - # Use zero-shot without prompt - outputs = model.getModel().inference_zero_shot( - text, - "", - "", - zero_shot_spk_id=f"speaker_{config['speaker_id']}", - stream=False - ) - else: - # Use cross-lingual inference - outputs = model.getModel().inference_cross_lingual( - text, - prompt_speech_16k if prompt_speech_16k else None, - stream=False - ) - - # Get the first output audio - output_audio = next(outputs)['tts_speech'] - - return Voice(audio=output_audio, fps=model.getModel().sample_rate, text=text) + + seed = int(config["seed"]) + random.seed(seed) + np.random.seed(seed % (2**32)) + torch.manual_seed(seed) + + # Convert prompt audio to the required format if provided + prompt_speech_16k = None + if prompt_audio and config["zero_shot_prompt"]: + speech, sr = torchaudio.load(prompt_audio.path or io.BytesIO(prompt_audio._audio), backend="soundfile") + prompt_speech_16k = torchaudio.functional.resample(speech.mean(dim=0, keepdim=True), sr, 16000) + + # Generate audio based on configuration + if config["use_zero_shot"]: + if prompt_speech_16k is not None: + if not prompt_text.strip(): + raise ValueError("Zero-shot synthesis requires the reference audio transcript (prompt_text)") + # Use zero-shot with prompt + outputs = model.getModel().inference_zero_shot( + text, + prompt_text, + prompt_speech_16k, + stream=False, + text_frontend=text_frontend, + ) + else: + speaker = f"speaker_{config['speaker_id']}" + if speaker not in model.getModel().frontend.spk2info: + raise ValueError("Provide reference audio and prompt_text, or register the selected speaker first") + # Use zero-shot without prompt + outputs = model.getModel().inference_zero_shot( + text, + "", + "", + zero_shot_spk_id=f"speaker_{config['speaker_id']}", + stream=False, + text_frontend=text_frontend, + ) + else: + if prompt_speech_16k is None: + raise ValueError("Cross-lingual synthesis requires reference audio") + # Use cross-lingual inference + outputs = model.getModel().inference_cross_lingual( + text, + prompt_speech_16k, + stream=False, + text_frontend=text_frontend, + ) + + chunks = [chunk['tts_speech'].detach().cpu() for chunk in outputs] + if not chunks: + raise RuntimeError("CosyVoice2 produced no audio") + output_audio = torch.cat(chunks, dim=-1) + + buffer = io.BytesIO() + sf.write(buffer, output_audio.squeeze(0).numpy(), model.getModel().sample_rate, format="WAV") + return Voice("wav", buffer.getvalue(), fps=model.getModel().sample_rate, text=text) diff --git a/extensions/Voice/vendor/cosyvoice/cli/frontend.py b/extensions/Voice/vendor/cosyvoice/cli/frontend.py index 36dcd189..076087fa 100644 --- a/extensions/Voice/vendor/cosyvoice/cli/frontend.py +++ b/extensions/Voice/vendor/cosyvoice/cli/frontend.py @@ -52,9 +52,16 @@ def __init__(self, option.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_ALL option.intra_op_num_threads = 1 self.campplus_session = onnxruntime.InferenceSession(campplus_model, sess_options=option, providers=["CPUExecutionProvider"]) - self.speech_tokenizer_session = onnxruntime.InferenceSession(speech_tokenizer_model, sess_options=option, - providers=["CUDAExecutionProvider" if torch.cuda.is_available() else - "CPUExecutionProvider"]) + if torch.cuda.is_available() and hasattr(onnxruntime, "preload_dlls"): + onnxruntime.preload_dlls() + providers = ["CPUExecutionProvider"] + if torch.cuda.is_available(): + if "CUDAExecutionProvider" in onnxruntime.get_available_providers(): + providers.insert(0, "CUDAExecutionProvider") + else: + logging.warning("ONNX speech tokenizer uses CPU; PyTorch synthesis still uses CUDA") + self.speech_tokenizer_session = onnxruntime.InferenceSession( + speech_tokenizer_model, sess_options=option, providers=providers) if os.path.exists(spk2info): self.spk2info = torch.load(spk2info, map_location=self.device) else: @@ -68,9 +75,10 @@ def __init__(self, 'failed to initialize ttsfrd resource' self.frd.set_lang_type('pinyinvg') else: - self.zh_tn_model = ZhNormalizer(remove_erhua=False, full_to_half=False, overwrite_cache=True) - self.en_tn_model = EnNormalizer() - self.inflect_parser = inflect.engine() + # Build only the requested language, and reuse its on-disk FST cache. + self.zh_tn_model = None + self.en_tn_model = None + self.inflect_parser = None def _extract_text_token(self, text): if isinstance(text, Generator): @@ -130,6 +138,8 @@ def text_normalize(self, text, split=True, text_frontend=True): text = ''.join(texts) else: if contains_chinese(text): + if self.zh_tn_model is None: + self.zh_tn_model = ZhNormalizer(remove_erhua=False, full_to_half=False, overwrite_cache=False) text = self.zh_tn_model.normalize(text) text = text.replace("\n", "") text = replace_blank(text) @@ -141,6 +151,9 @@ def text_normalize(self, text, split=True, text_frontend=True): texts = list(split_paragraph(text, partial(self.tokenizer.encode, allowed_special=self.allowed_special), "zh", token_max_n=80, token_min_n=60, merge_len=20, comma_split=False)) else: + if self.en_tn_model is None: + self.en_tn_model = EnNormalizer() + self.inflect_parser = inflect.engine() text = self.en_tn_model.normalize(text) text = spell_out_number(text, self.inflect_parser) texts = list(split_paragraph(text, partial(self.tokenizer.encode, allowed_special=self.allowed_special), "en", token_max_n=80, diff --git a/extensions/Voice/vendor/cosyvoice/cli/model.py b/extensions/Voice/vendor/cosyvoice/cli/model.py index aa110b15..d0377104 100644 --- a/extensions/Voice/vendor/cosyvoice/cli/model.py +++ b/extensions/Voice/vendor/cosyvoice/cli/model.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import os +import zipfile from typing import Generator import queue import torch @@ -68,14 +69,22 @@ def __init__(self, self.hift_cache_dict = {} def load(self, llm_model, flow_model, hift_model): - self.llm.load_state_dict(torch.load(llm_model, map_location=self.device), strict=True) - self.llm.to(self.device).eval() - self.flow.load_state_dict(torch.load(flow_model, map_location=self.device), strict=True) - self.flow.to(self.device).eval() - # in case hift_model is a hifigan model - hift_state_dict = {k.replace('generator.', ''): v for k, v in torch.load(hift_model, map_location=self.device).items()} + # Move each module before reading its checkpoint to avoid simultaneous + # resident CPU copies of both the model and the deserialized weights. + def checkpoint(path): + return torch.load(path, map_location='cpu', weights_only=True, + mmap=zipfile.is_zipfile(path)) + + self.llm.to(self.device) + self.llm.load_state_dict(checkpoint(llm_model), strict=True) + self.llm.eval() + self.flow.to(self.device) + self.flow.load_state_dict(checkpoint(flow_model), strict=True) + self.flow.eval() + self.hift.to(self.device) + hift_state_dict = {k.replace('generator.', ''): v for k, v in checkpoint(hift_model).items()} self.hift.load_state_dict(hift_state_dict, strict=True) - self.hift.to(self.device).eval() + self.hift.eval() def load_jit(self, llm_text_encoder_model, llm_llm_model, flow_encoder_model): llm_text_encoder = torch.jit.load(llm_text_encoder_model, map_location=self.device) diff --git a/extensions/Voice/vendor/cosyvoice/llm/llm.py b/extensions/Voice/vendor/cosyvoice/llm/llm.py index 670ae69c..c80474af 100644 --- a/extensions/Voice/vendor/cosyvoice/llm/llm.py +++ b/extensions/Voice/vendor/cosyvoice/llm/llm.py @@ -226,7 +226,7 @@ def inference( class Qwen2Encoder(torch.nn.Module): def __init__(self, pretrain_path): super().__init__() - self.model = Qwen2ForCausalLM.from_pretrained(pretrain_path) + self.model = Qwen2ForCausalLM.from_pretrained(pretrain_path, low_cpu_mem_usage=True) def forward(self, xs: torch.Tensor, xs_lens: torch.Tensor): T = xs.size(1) diff --git a/package.json b/package.json index e9db2131..c7de477c 100644 --- a/package.json +++ b/package.json @@ -170,7 +170,8 @@ "test:desktop:linux": "node scripts/test_linux_desktop.cjs", "package:linux": "yarn build:frontend && yarn build:extension_builder && yarn ext:package && yarn build:desktop --bundles appimage", "ext:package_3D": "cd extensions/3D-Model && node ../../extension_builder/dist/index.js package -o ../../desktop/src-tauri/resources/extensions/", - "ext:package_Motion": "cd extensions/Motion && node ../../extension_builder/dist/index.js package -o ../../desktop/src-tauri/resources/extensions/" + "ext:package_Motion": "cd extensions/Motion && node ../../extension_builder/dist/index.js package -o ../../desktop/src-tauri/resources/extensions/", + "test:cosyvoice": "node dependencies/venv.cjs python scripts/cosyvoice_smoke.py" }, "devDependencies": { "@axe-core/playwright": "^4.10.2", diff --git a/scripts/cosyvoice_smoke.py b/scripts/cosyvoice_smoke.py new file mode 100644 index 00000000..57799900 --- /dev/null +++ b/scripts/cosyvoice_smoke.py @@ -0,0 +1,70 @@ +"""Run real CosyVoice2 inference from the repository's shared environment.""" +import argparse +import json +import sys +import time +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +sys.path[:0] = [str(ROOT), str(ROOT / 'extensions/Voice'), str(ROOT / 'extensions/Voice/vendor')] + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--model', help='Local CosyVoice2 snapshot; otherwise download into models/CosyVoice2-0.5B') + parser.add_argument('--prompt', required=True, help='Reference WAV, at most 30 seconds') + parser.add_argument('--prompt-text', required=True, help='Exact reference transcript') + parser.add_argument('--text', default='你好,这是使用 CosyVoice 二进行的语音合成测试。') + parser.add_argument('--text-frontend', action='store_true', help='Enable text normalization (first FST build can use substantial RAM)') + parser.add_argument('--device', choices=['auto', 'cpu', 'cuda'], default='auto') + parser.add_argument('--output', default='artifacts/cosyvoice2/output.wav') + args = parser.parse_args() + if args.device == 'cpu': + import os + os.environ['CUDA_VISIBLE_DEVICES'] = '' + import torch + import soundfile as sf + if args.device == 'cuda' and not torch.cuda.is_available(): + raise RuntimeError('CUDA was requested but PyTorch cannot access an NVIDIA GPU') + from ssui_voice.Cosyvoice import CosyVoiceModel, GenVoice + from ssui.base import Audio + from ssui.config import SSUIConfig + if not args.model: + from huggingface_hub import snapshot_download + args.model = snapshot_download('FunAudioLLM/CosyVoice2-0.5B', local_dir=ROOT / 'models/CosyVoice2-0.5B', + ignore_patterns=['*.zip', '*.plan', '*.engine', '*.trt', 'llm.onnx', 'flow.decoder*.onnx']) + torch.set_num_threads(4) + model = CosyVoiceModel.load(args.model) + devices = {name: str(next(getattr(model.model.model, name).parameters()).device) + for name in ('llm', 'flow', 'hift')} + if args.device == 'cuda' and any(not value.startswith('cuda') for value in devices.values()): + raise RuntimeError(f'Models did not load on CUDA: {devices}') + if args.device == 'cuda' and 'CUDAExecutionProvider' not in model.model.frontend.speech_tokenizer_session.get_providers(): + raise RuntimeError('CUDA was requested but ONNX Runtime did not activate CUDAExecutionProvider') + config = SSUIConfig() + config('speech') + config._is_prepare = True + GenVoice(config, model, args.text) + config._is_prepare = False + started = time.perf_counter() + result = GenVoice(config, model, args.text, Audio('wav', Path(args.prompt).read_bytes()), args.prompt_text, text_frontend=args.text_frontend) + inference_seconds = time.perf_counter() - started + output = Path(args.output).resolve() + output.parent.mkdir(parents=True, exist_ok=True) + output.write_bytes(result._audio) + audio, rate = sf.read(output) + import numpy as np + if audio.size == 0 or not np.isfinite(audio).all() or np.max(np.abs(audio)) < 1e-5: + raise RuntimeError('Generated audio is empty, invalid, or silent') + report = {'model': str(args.model), 'torch': torch.__version__, 'device': str(model.model.model.device), + 'gpu_name': torch.cuda.get_device_name(0) if model.model.model.device.type == 'cuda' else None, + 'inference_seconds': inference_seconds, 'model_devices': devices, 'onnx_providers': model.model.frontend.speech_tokenizer_session.get_providers(), + 'sample_rate': rate, 'duration_seconds': len(audio) / rate, + 'peak': float(np.max(np.abs(audio))), 'rms': float(np.sqrt(np.mean(audio**2))), + 'output': str(output)} + output.with_suffix('.json').write_text(json.dumps(report, ensure_ascii=False, indent=2)) + print(json.dumps(report, ensure_ascii=False, indent=2)) + + +if __name__ == '__main__': + main() diff --git a/tests/cosyvoice_adapter_test.py b/tests/cosyvoice_adapter_test.py new file mode 100644 index 00000000..8666edb9 --- /dev/null +++ b/tests/cosyvoice_adapter_test.py @@ -0,0 +1,65 @@ +"""Exercise the SSUI Audio boundary without model downloads.""" +import io +import unittest +from unittest.mock import patch +from types import SimpleNamespace + +import numpy as np +import soundfile as sf +import torch + + +class TestCosyVoiceAdapter(unittest.TestCase): + def generate(self, outputs, prompt_text='参考语音。', use_zero_shot=True, path=None, text_frontend=True): + from ssui_voice.Cosyvoice import CosyVoiceModel, GenVoice + from ssui.base import Audio + buffer = io.BytesIO() + sf.write(buffer, np.ones(16000, dtype=np.float32) * 0.1, 16000, format='WAV') + class Config(dict): + def is_prepare(self): + return False + config = Config(seed=42, use_zero_shot=use_zero_shot, zero_shot_prompt=True, speaker_id=0) + with patch('ssui_voice.Cosyvoice.torchaudio.load', return_value=(torch.ones(1, 16000), 16000)) as load: + result = GenVoice(config, CosyVoiceModel(model=outputs), '测试。', Audio('wav', buffer.getvalue(), path=path), prompt_text, text_frontend=text_frontend) + if path: + self.assertEqual(load.call_args.args[0], path) + return result + + def test_preserves_all_chunks_and_returns_serialized_audio(self): + from unittest.mock import Mock + model = Mock(sample_rate=24000) + model.inference_zero_shot.return_value = iter([{'tts_speech': torch.ones(1, 100) * .2}, + {'tts_speech': torch.ones(1, 200) * .3}]) + result = self.generate(model) + audio, rate = sf.read(io.BytesIO(result._audio)) + self.assertEqual((len(audio), rate, result._format), (300, 24000, 'wav')) + self.assertEqual(model.inference_zero_shot.call_args.args[1], '参考语音。') + self.assertEqual(result._text, '测试。') + + def test_requires_reference_transcript(self): + with self.assertRaisesRegex(ValueError, 'transcript'): + self.generate(SimpleNamespace(), prompt_text='') + + def test_rejects_empty_output(self): + from unittest.mock import Mock + model = Mock(sample_rate=24000) + model.inference_zero_shot.return_value = iter([]) + with self.assertRaisesRegex(RuntimeError, 'no audio'): + self.generate(model) + + def test_path_backed_prompt_and_explicit_normalization_bypass(self): + from unittest.mock import Mock + model = Mock(sample_rate=24000) + model.inference_zero_shot.return_value = iter([{'tts_speech': torch.ones(1, 100) * .2}]) + self.generate(model, path='/reference.wav', text_frontend=False) + self.assertFalse(model.inference_zero_shot.call_args.kwargs['text_frontend']) + + def test_load_preserves_opt_in_memory_controls(self): + from ssui_voice.Cosyvoice import CosyVoiceModel + with patch('ssui_voice.Cosyvoice.CosyVoice2') as factory, patch('ssui_voice.Cosyvoice.ModelMemoryOptions') as options: + CosyVoiceModel.load('/model') + options.return_value.configure.assert_not_called() + CosyVoiceModel.load('/model', quantization='int8', cpu_offload=True) + options.assert_called_with('int8', True) + runtime = factory.return_value.model + options.return_value.configure.assert_called_once_with([runtime.llm, runtime.flow, runtime.hift], device=runtime.device) diff --git a/tests/model/cosyvoice_model_test.py b/tests/model/cosyvoice_model_test.py index 05d7892a..5ad9ff6f 100644 --- a/tests/model/cosyvoice_model_test.py +++ b/tests/model/cosyvoice_model_test.py @@ -1,42 +1,30 @@ import os +from pathlib import Path +import subprocess +import sys import unittest +from urllib.request import urlretrieve -import torch - -from tests.utils import download_if_needed, should_run_model_tests, model_output_dir +from tests.utils import get_test_data_dir, should_run_model_tests @unittest.skipUnless(should_run_model_tests(), "需要 SSUI_RUN_MODEL_TESTS=1") class TestCosyVoiceModel(unittest.TestCase): def test_cosyvoice(self): - from cosyvoice.cli.cosyvoice import CosyVoice2 - - import torchaudio - - model_dir = str(download_if_needed("cosyvoice")) - cosyvoice = CosyVoice2( - model_dir, load_jit=False, load_trt=False, fp16=False - ) - prompt_speech_16k = torch.zeros(16000, dtype=torch.float32) - - assert cosyvoice.add_zero_shot_spk("你好", prompt_speech_16k, "my_spk") is True - - with model_output_dir("cosyvoice") as tmp: - saved = 0 - for i, chunk in enumerate( - cosyvoice.inference_zero_shot( - "收到好友从远方寄来的生日礼物。", - "希望你以后能够做的比我还好呦。", - prompt_speech_16k, - stream=False, - ) - ): - torchaudio.save( - os.path.join(tmp, f"zero_shot_{i}.wav"), - chunk["tts_speech"], - cosyvoice.sample_rate, - ) - saved += 1 - if saved >= 2: - break - self.assertGreaterEqual(saved, 1) + # A fresh interpreter prevents fake CosyVoice modules installed during + # ordinary test discovery from turning this into a mock-only test. + root = Path(__file__).resolve().parents[2] + artifacts = get_test_data_dir() / 'cosyvoice2-artifacts' + artifacts.mkdir(parents=True, exist_ok=True) + prompt = Path(os.environ.get('SSUI_COSYVOICE_PROMPT', str(artifacts / 'prompt.wav'))) + if not prompt.exists(): + urlretrieve('https://raw.githubusercontent.com/FunAudioLLM/CosyVoice/main/asset/zero_shot_prompt.wav', prompt) + command = [sys.executable, str(root / 'scripts/cosyvoice_smoke.py'), + '--prompt', str(prompt), '--prompt-text', + os.environ.get('SSUI_COSYVOICE_PROMPT_TEXT', '希望你以后能够做的比我还好呦。'), + '--device', os.environ.get('SSUI_COSYVOICE_DEVICE', 'auto'), + '--output', str(artifacts / 'output.wav')] + if os.environ.get('SSUI_COSYVOICE_MODEL'): + command += ['--model', os.environ['SSUI_COSYVOICE_MODEL']] + subprocess.run(command, cwd=root, check=True, timeout=900) + self.assertGreater((artifacts / 'output.wav').stat().st_size, 44) From bc98b5b812511a354b61dcaab921ef100689f5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E9=A3=8E=E9=80=8D=E9=81=A5=E6=B8=B8?= Date: Thu, 12 Nov 2026 00:17:16 +0800 Subject: [PATCH 2/3] Fix shared SoundFile dependency for cross-platform Voice tests --- dependencies/dependencies.yaml | 3 ++- dependencies/dependency_config.test.cjs | 9 +++++++++ dependencies/linux-amdgpu-dependencies.yaml | 6 ++++++ dependencies/linux-amdgpu.lock | 7 ++++++- dependencies/linux-arm64.lock | 5 +++++ dependencies/macosx-dependencies.yaml | 6 ++++++ dependencies/macosx.lock | 10 ++++++++-- dependencies/requirements-linux-amdgpu.txt | 1 + dependencies/requirements-linux-arm64.txt | 1 + dependencies/requirements-macosx.txt | 1 + dependencies/requirements-windows.txt | 2 +- 11 files changed, 46 insertions(+), 5 deletions(-) diff --git a/dependencies/dependencies.yaml b/dependencies/dependencies.yaml index bc775d5f..8ea11ebe 100644 --- a/dependencies/dependencies.yaml +++ b/dependencies/dependencies.yaml @@ -41,6 +41,8 @@ common: safetensors: ">=0.4.5" scipy: ">=1.15.2" spandrel: ">=0.4.1" + # Voice adapters encode WAV on every platform, including contract tests. + soundfile: ">=0.12.1" tokenizers: ">=0.20.0" torchsde: "==0.2.6" transformers: ">=4.51.3,<5" @@ -265,7 +267,6 @@ overrides: # HyperPyYAML 1.2.2 needs the pre-0.19 loader API. ruamel.yaml: "==0.18.6" conformer: ">=0.3.2" - soundfile: ">=0.12.1" librosa: "==0.11.0" openai-whisper: "==20240930" inflect: ">=7.3.1" diff --git a/dependencies/dependency_config.test.cjs b/dependencies/dependency_config.test.cjs index 3a5ab6dc..ac0ff1d3 100644 --- a/dependencies/dependency_config.test.cjs +++ b/dependencies/dependency_config.test.cjs @@ -198,3 +198,12 @@ test('CosyVoice CUDA dependencies use one ONNX runtime and retain native platfor assert.ok(os === 'windows' ? pynini.includes('win_amd64.whl') : pynini === 'pynini==2.1.6.post1'); } }); + + +test('all supported profiles include the shared Voice WAV dependency', () => { + const spec = loadConfig(); + for (const profile of config.profiles) { + const { requirements } = resolveDependencies(profile, spec); + assert.ok(requirements.some(line => /^soundfile[<>=@]/i.test(line))); + } +}); diff --git a/dependencies/linux-amdgpu-dependencies.yaml b/dependencies/linux-amdgpu-dependencies.yaml index b88a5236..502c56d5 100644 --- a/dependencies/linux-amdgpu-dependencies.yaml +++ b/dependencies/linux-amdgpu-dependencies.yaml @@ -95,6 +95,7 @@ cffi: dependents: - argon2-cffi-bindings - sounddevice + - soundfile charset-normalizer: version: "2.1.1" dependents: @@ -568,6 +569,7 @@ numpy: - rembg - scikit-image - scipy + - soundfile - spandrel - tifffile - torchsde @@ -941,6 +943,9 @@ sounddevice: version: "0.5.5" dependents: - mediapipe +soundfile: + version: "0.14.0" + isRoot: true soupsieve: version: "2.8.4" dependents: @@ -1091,6 +1096,7 @@ typing-extensions: - pyvista - referencing - rich-toolkit + - soundfile - spandrel - starlette - torch diff --git a/dependencies/linux-amdgpu.lock b/dependencies/linux-amdgpu.lock index c44ae778..006b577b 100644 --- a/dependencies/linux-amdgpu.lock +++ b/dependencies/linux-amdgpu.lock @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile dependencies\requirements-linux-amdgpu.txt -o dependencies\linux-amdgpu.lock --python-platform x86_64-unknown-linux-gnu --python-version 3.12.8 +# uv pip compile dependencies/requirements-linux-amdgpu.txt -o dependencies/linux-amdgpu.lock --python-platform x86_64-unknown-linux-gnu --python-version 3.12.8 absl-py==2.4.0 # via mediapipe accelerate==1.14.0 @@ -63,6 +63,7 @@ cffi==2.0.0 # via # argon2-cffi-bindings # sounddevice + # soundfile charset-normalizer==2.1.1 # via requests click==8.4.2 @@ -383,6 +384,7 @@ numpy==2.4.4 # rembg # scikit-image # scipy + # soundfile # spandrel # tifffile # torchsde @@ -660,6 +662,8 @@ six==1.17.0 # rfc3339-validator sounddevice==0.5.5 # via mediapipe +soundfile==0.14.0 + # via -r dependencies/requirements-linux-amdgpu.txt soupsieve==2.8.4 # via beautifulsoup4 spandrel==0.4.2 @@ -775,6 +779,7 @@ typing-extensions==4.15.0 # pyvista # referencing # rich-toolkit + # soundfile # spandrel # starlette # torch diff --git a/dependencies/linux-arm64.lock b/dependencies/linux-arm64.lock index 7697c2ea..3e5cf52e 100644 --- a/dependencies/linux-arm64.lock +++ b/dependencies/linux-arm64.lock @@ -70,6 +70,7 @@ cffi==2.1.1 # argon2-cffi-bindings # cryptography # sounddevice + # soundfile charset-normalizer==3.5.2 # via requests click==8.5.0 @@ -397,6 +398,7 @@ numpy==2.5.4 # rembg # scikit-image # scipy + # soundfile # spandrel # tifffile # torchsde @@ -683,6 +685,8 @@ six==1.17.0 # rfc3339-validator sounddevice==0.5.6 # via mediapipe +soundfile==0.14.0 + # via -r dependencies/requirements-linux-arm64.txt soupsieve==3.0.4 # via beautifulsoup4 spandrel==0.4.2 @@ -810,6 +814,7 @@ typing-extensions==4.16.0 # pyvista-validation # referencing # rich-toolkit + # soundfile # spandrel # starlette # torch diff --git a/dependencies/macosx-dependencies.yaml b/dependencies/macosx-dependencies.yaml index 8e03b855..2662d6f2 100644 --- a/dependencies/macosx-dependencies.yaml +++ b/dependencies/macosx-dependencies.yaml @@ -57,6 +57,7 @@ cffi: version: "1.17.1" dependents: - sounddevice + - soundfile charset-normalizer: version: "3.4.1" dependents: @@ -350,6 +351,7 @@ numpy: - rembg - scikit-image - scipy + - soundfile - spandrel - tifffile - torchsde @@ -606,6 +608,9 @@ sounddevice: version: "0.5.1" dependents: - mediapipe +soundfile: + version: "0.14.0" + isRoot: true spandrel: version: "0.4.1" isRoot: true @@ -710,6 +715,7 @@ typing-extensions: - pyvista - referencing - rich-toolkit + - soundfile - spandrel - torch - typer diff --git a/dependencies/macosx.lock b/dependencies/macosx.lock index 59a0dc3e..d4c75256 100644 --- a/dependencies/macosx.lock +++ b/dependencies/macosx.lock @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile dependencies\requirements-macosx.txt -o dependencies\macosx.lock --python-platform aarch64-apple-darwin --python-version 3.12.8 +# uv pip compile dependencies/requirements-macosx.txt -o dependencies/macosx.lock --python-platform aarch64-apple-darwin --python-version 3.12.8 absl-py==2.2.1 # via mediapipe accelerate==1.5.2 @@ -38,7 +38,9 @@ certifi==2025.1.31 # httpx # requests cffi==1.17.1 - # via sounddevice + # via + # sounddevice + # soundfile charset-normalizer==3.4.1 # via requests click==8.1.8 @@ -243,6 +245,7 @@ numpy==1.26.4 # rembg # scikit-image # scipy + # soundfile # spandrel # tifffile # torchsde @@ -434,6 +437,8 @@ sniffio==1.3.1 # via anyio sounddevice==0.5.1 # via mediapipe +soundfile==0.14.0 + # via -r dependencies/requirements-macosx.txt spandrel==0.4.1 # via -r dependencies/requirements-macosx.txt starlette==0.46.1 @@ -513,6 +518,7 @@ typing-extensions==4.13.0 # pyvista # referencing # rich-toolkit + # soundfile # spandrel # torch # typer diff --git a/dependencies/requirements-linux-amdgpu.txt b/dependencies/requirements-linux-amdgpu.txt index be798486..3600f815 100644 --- a/dependencies/requirements-linux-amdgpu.txt +++ b/dependencies/requirements-linux-amdgpu.txt @@ -40,6 +40,7 @@ rocm_sdk_devel @ https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/rocm_sdk_de rocm_sdk_libraries_custom @ https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/rocm_sdk_libraries_custom-7.2.1-py3-none-win_amd64.whl safetensors>=0.4.5 scipy>=1.15.2 +soundfile>=0.12.1 spandrel>=0.4.1 tokenizers>=0.20.0 torch @ https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torch-2.9.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl diff --git a/dependencies/requirements-linux-arm64.txt b/dependencies/requirements-linux-arm64.txt index 755a7bcf..ef5cc8a1 100644 --- a/dependencies/requirements-linux-arm64.txt +++ b/dependencies/requirements-linux-arm64.txt @@ -37,6 +37,7 @@ RestrictedPython>=8.0 safetensors>=0.4.5 scipy>=1.15.2 sentencepiece==0.2.0 +soundfile>=0.12.1 spandrel>=0.4.1 tokenizers>=0.20.0 torch==2.8.0 diff --git a/dependencies/requirements-macosx.txt b/dependencies/requirements-macosx.txt index 73717e40..167befdb 100644 --- a/dependencies/requirements-macosx.txt +++ b/dependencies/requirements-macosx.txt @@ -42,6 +42,7 @@ safetensors>=0.4.5 scikit-image>=0.25.2 scipy>=1.15.2 sentencepiece==0.2.0 +soundfile>=0.12.1 spandrel>=0.4.1 tiktoken>=0.9.0 tokenizers>=0.20.0 diff --git a/dependencies/requirements-windows.txt b/dependencies/requirements-windows.txt index d53c5730..aeb9c3ef 100644 --- a/dependencies/requirements-windows.txt +++ b/dependencies/requirements-windows.txt @@ -60,7 +60,7 @@ safetensors>=0.4.5 scipy>=1.15.2 scipy>=1.15 sentencepiece==0.2.0 -soundfile>=0.12.1 +soundfile==0.12.1 spandrel>=0.4.1 spconv-cu124>=2.3.8 tiktoken>=0.9.0 From 66830d4f9e8fa862918708aac3d19d7f678f7505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E9=A3=8E=E9=80=8D=E9=81=A5=E6=B8=B8?= Date: Thu, 12 Nov 2026 15:02:48 +0800 Subject: [PATCH 3/3] Stabilize Ubuntu CI package sources and bound APT retries --- .github/workflows/ci.yml | 33 +++++--- .github/workflows/windows-arm64-wheels.yml | 8 +- scripts/ci_apt.py | 66 ++++++++++++++++ tests/ci_apt_test.py | 87 ++++++++++++++++++++++ 4 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 scripts/ci_apt.py create mode 100644 tests/ci_apt_test.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0cb8fed3..8b0d3464 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ env: jobs: frontend-tests: name: Frontend and browser tests - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 timeout-minutes: 20 steps: - name: Checkout @@ -62,6 +62,9 @@ jobs: run: yarn install --frozen-lockfile - name: Frontend unit tests run: yarn test:frontend + - name: Prepare Ubuntu package sources + timeout-minutes: 6 + run: sudo --preserve-env=GITHUB_ACTIONS /usr/bin/python3 scripts/ci_apt.py - name: Install Chromium run: yarn test:ui:install --with-deps - name: Browser interaction tests @@ -83,7 +86,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-24.04, windows-latest, macos-latest] steps: - name: Checkout uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 @@ -105,10 +108,14 @@ jobs: activate-environment: true - name: File snapshot and conflict tests run: yarn test:file-service + - name: Prepare Ubuntu package sources + if: runner.os == 'Linux' + timeout-minutes: 6 + run: sudo --preserve-env=GITHUB_ACTIONS /usr/bin/python3 scripts/ci_apt.py - name: Native Linux libraries + timeout-minutes: 10 if: runner.os == 'Linux' run: | - sudo apt-get update sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev libdbus-1-dev xvfb - name: Setup Rust uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 @@ -119,7 +126,7 @@ jobs: uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 with: workspaces: "desktop/src-tauri -> target" - shared-key: "tauri-native-${{ runner.os }}" + shared-key: "tauri-native-${{ runner.os }}${{ runner.os == 'Linux' && '-ubuntu-24.04' || '' }}" - name: Prepare resources run: yarn workspace ssui-desktop copy-resources - name: Rust command tests @@ -165,7 +172,7 @@ jobs: frontend-e2e: name: Frontend contracts and Chromium E2E - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 timeout-minutes: 25 steps: - name: Checkout @@ -199,6 +206,9 @@ jobs: # Resolve together so MCP cannot upgrade Starlette past FastAPI's constraint. run: uv pip install -r tests/mock_api/requirements.txt ".[mcp]" + - name: Prepare Ubuntu package sources + timeout-minutes: 6 + run: sudo --preserve-env=GITHUB_ACTIONS /usr/bin/python3 scripts/ci_apt.py - name: Install Chromium if: github.event_name != 'schedule' timeout-minutes: 10 @@ -260,7 +270,7 @@ jobs: platform: windows - os: macOS-latest platform: macosx - - os: ubuntu-latest + - os: ubuntu-24.04 platform: linux steps: - name: Checkout @@ -324,12 +334,15 @@ jobs: timeout-minutes: 20 run: uv pip install -r dependencies/${{ steps.runtime.outputs.lock }} --index-strategy unsafe-best-match --build-constraint dependencies/build-constraints.txt + - name: Prepare Ubuntu package sources + if: runner.os == 'Linux' + timeout-minutes: 6 + run: sudo --preserve-env=GITHUB_ACTIONS /usr/bin/python3 scripts/ci_apt.py - name: Install system dependencies if: ${{ matrix.platform == 'linux' }} - timeout-minutes: 30 + timeout-minutes: 10 run: | - sudo apt-get -o Acquire::Retries=3 update - sudo apt-get -o Acquire::Retries=3 install -y --no-install-recommends libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf libglib2.0-dev pkg-config gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-libav + sudo apt-get install -y --no-install-recommends libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf libglib2.0-dev pkg-config gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-libav - name: Restore Rust compilation cache id: rust-cache @@ -337,7 +350,7 @@ jobs: uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1 with: workspaces: "desktop/src-tauri -> target" - shared-key: "tauri-release-${{ matrix.platform }}" + shared-key: "tauri-release-${{ matrix.platform }}${{ runner.os == 'Linux' && '-ubuntu-24.04' || '' }}" cache-on-failure: "true" - name: Report Rust cache status diff --git a/.github/workflows/windows-arm64-wheels.yml b/.github/workflows/windows-arm64-wheels.yml index 8f726f02..33ee7b95 100644 --- a/.github/workflows/windows-arm64-wheels.yml +++ b/.github/workflows/windows-arm64-wheels.yml @@ -16,6 +16,7 @@ on: - 'scripts/audit_native_binaries.py' - 'scripts/runtime_config.py' - 'scripts/check_runtime.py' + - 'scripts/ci_apt.py' - '.github/workflows/windows-arm64-wheels.yml' - '.github/workflows/macos-intel-wheels.yml' - 'scripts/build_macos_intel_wheels.py' @@ -27,6 +28,7 @@ on: - 'scripts/audit_native_binaries.py' - 'scripts/runtime_config.py' - 'scripts/check_runtime.py' + - 'scripts/ci_apt.py' - '.github/workflows/windows-arm64-wheels.yml' - '.github/workflows/macos-intel-wheels.yml' - 'scripts/build_macos_intel_wheels.py' @@ -108,10 +110,14 @@ jobs: - name: Install pinned standalone Python timeout-minutes: 15 run: node dependencies/bootstrap.cjs --github-env + - name: Prepare Ubuntu package sources + if: runner.os == 'Linux' + timeout-minutes: 6 + run: sudo --preserve-env=GITHUB_ACTIONS /usr/bin/python3 scripts/ci_apt.py - name: Install Linux native build dependencies + timeout-minutes: 10 if: runner.os == 'Linux' run: | - sudo apt-get update sudo apt-get install -y libgl1-mesa-dev libx11-dev - name: Download verified Intel wheels if: matrix.id == 'macos-x86_64' diff --git a/scripts/ci_apt.py b/scripts/ci_apt.py new file mode 100644 index 00000000..793a2d32 --- /dev/null +++ b/scripts/ci_apt.py @@ -0,0 +1,66 @@ +"""Prepare Ubuntu APT on disposable GitHub runners without accepting stale indexes.""" +import os +from pathlib import Path +import re +import subprocess + + +UBUNTU_URI = re.compile( + r"https?://(?:(?:[\w-]+\.)?archive\.ubuntu\.com/ubuntu|" + r"security\.ubuntu\.com/ubuntu|ports\.ubuntu\.com/ubuntu-ports)/?" + r"(?=\s|$)|mirror\+file:/etc/apt/(?:apt-mirrors\.txt|mirrors/ubuntu(?:-security)?\.list)" +) +MIRRORS = { + 'amd64': ('https://mirror.math.princeton.edu/pub/ubuntu/', + 'https://archive.ubuntu.com/ubuntu/'), + 'arm64': ('https://mirrors.aliyun.com/ubuntu-ports/', + 'https://ports.ubuntu.com/ubuntu-ports/'), +} +APT_CONFIG = '''Acquire::Retries "1"; +Acquire::http::Timeout "20"; +Acquire::https::Timeout "20"; +APT::Update::Error-Mode "any"; +''' + + +def rewrite_sources(text, mirror): + # Retain suites, components, architecture restrictions and Signed-By keys. + return ''.join(line if line.lstrip().startswith('#') else UBUNTU_URI.sub(mirror, line) + for line in text.splitlines(keepends=True)) + + +def prepare(apt_root, arch, run=subprocess.run): + mirrors = MIRRORS[arch] + paths = [apt_root / 'sources.list', *(apt_root / 'sources.list.d').glob('*.list'), + *(apt_root / 'sources.list.d').glob('*.sources')] + originals = {p: p.read_text() for p in paths if p.is_file()} + if not any(UBUNTU_URI.search(text) for text in originals.values()): + raise RuntimeError('No Ubuntu package source found; refusing to guess repository configuration') + config = apt_root / 'apt.conf.d' / '80ssui-ci-network' + config.parent.mkdir(parents=True, exist_ok=True) + config.write_text(APT_CONFIG) + for mirror in mirrors: + for path, text in originals.items(): + path.write_text(rewrite_sources(text, mirror)) + print(f'Updating signed Ubuntu indexes from {mirror}', flush=True) + try: + result = run(['apt-get', '-o', 'APT::Update::Error-Mode=any', 'update'], + timeout=120, check=False) + if result.returncode == 0: + return + except subprocess.TimeoutExpired: + print('APT index update exceeded 120 seconds', flush=True) + raise RuntimeError('Ubuntu index updates failed on both HTTPS mirrors; package installation stopped') + + +def main(): + if os.environ.get('GITHUB_ACTIONS') != 'true' or os.geteuid() != 0: + raise RuntimeError('This setup is only for root on disposable GitHub Actions runners') + if 'ID=ubuntu' not in Path('/etc/os-release').read_text().splitlines(): + raise RuntimeError('Ubuntu runner required') + arch = subprocess.check_output(['dpkg', '--print-architecture'], text=True).strip() + prepare(Path('/etc/apt'), arch) + + +if __name__ == '__main__': + main() diff --git a/tests/ci_apt_test.py b/tests/ci_apt_test.py new file mode 100644 index 00000000..aefabb01 --- /dev/null +++ b/tests/ci_apt_test.py @@ -0,0 +1,87 @@ +import importlib.util +from pathlib import Path +import subprocess +import tempfile +from types import SimpleNamespace +import unittest + + +spec = importlib.util.spec_from_file_location('ci_apt', Path(__file__).resolve().parents[1] / 'scripts/ci_apt.py') +apt = importlib.util.module_from_spec(spec) +spec.loader.exec_module(apt) + +SOURCE = '''Types: deb +URIs: mirror+file:/etc/apt/apt-mirrors.txt +Suites: noble noble-updates noble-backports noble-security +Components: main restricted universe multiverse +Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg +''' + + +class TestCIApt(unittest.TestCase): + def test_preserves_signed_suites_and_third_party_sources(self): + source = SOURCE + '\nURIs: https://packages.microsoft.com/ubuntu/24.04/prod\n' + rewritten = apt.rewrite_sources(source, apt.MIRRORS['amd64'][0]) + self.assertIn('URIs: https://mirror.math.princeton.edu/pub/ubuntu/', rewritten) + for line in source.splitlines(): + if not line.startswith('URIs: mirror+'): + self.assertIn(line, rewritten) + self.assertNotIn('trusted=yes', rewritten) + + def test_legacy_sources_and_arm64_use_https(self): + source = 'deb [arch=arm64 signed-by=/key.gpg] http://ports.ubuntu.com/ubuntu-ports noble main\n' + rewritten = apt.rewrite_sources(source, apt.MIRRORS['arm64'][0]) + self.assertEqual(rewritten, 'deb [arch=arm64 signed-by=/key.gpg] https://mirrors.aliyun.com/ubuntu-ports/ noble main\n') + legacy = 'deb http://azure.archive.ubuntu.com/ubuntu/ noble main\n' + self.assertNotIn('azure.archive', apt.rewrite_sources(legacy, apt.MIRRORS['amd64'][0])) + + def exercise(self, outcomes, arch='amd64'): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + (root / 'sources.list.d').mkdir() + source = root / 'sources.list.d/ubuntu.sources' + source.write_text(SOURCE) + calls = [] + def run(command, **kwargs): + calls.append((command, kwargs, source.read_text())) + outcome = outcomes.pop(0) + if isinstance(outcome, Exception): + raise outcome + return SimpleNamespace(returncode=outcome) + try: + apt.prepare(root, arch, run=run) + finally: + self.assertIn('APT::Update::Error-Mode "any"', (root / 'apt.conf.d/80ssui-ci-network').read_text()) + self.assertTrue(all(call[1]['timeout'] == 120 for call in calls)) + self.calls = calls + + def test_success_does_not_retry(self): + self.exercise([0]) + self.assertEqual(len(self.calls), 1) + + def test_failed_index_update_uses_independent_fallback(self): + self.exercise([100, 0]) + self.assertEqual(len(self.calls), 2) + self.assertIn(apt.MIRRORS['amd64'][1], self.calls[-1][2]) + self.assertIn('Signed-By:', self.calls[-1][2]) + + def test_timeout_is_bounded_and_can_recover(self): + self.exercise([subprocess.TimeoutExpired('apt-get', 120), 0]) + self.assertEqual(len(self.calls), 2) + + def test_two_failures_stop_instead_of_using_stale_indexes(self): + with self.assertRaisesRegex(RuntimeError, 'package installation stopped'): + self.exercise([100, 100]) + self.assertEqual(len(self.calls), 2) + + def test_arm64_fallback_keeps_ports_repository(self): + self.exercise([100, 0], arch='arm64') + self.assertIn(apt.MIRRORS['arm64'][0], self.calls[0][2]) + self.assertIn(apt.MIRRORS['arm64'][1], self.calls[1][2]) + + def test_missing_sources_fail_before_writing_configuration(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + with self.assertRaisesRegex(RuntimeError, 'No Ubuntu package source'): + apt.prepare(root, 'amd64') + self.assertFalse((root / 'apt.conf.d').exists())