Compare commits

..

8 Commits

Author SHA1 Message Date
XXXXRT666
dc97fbbd24
Merge a8dc94ebb05b5f26c757a29bd32ea6616b6a9aea into 11aa78bd9bda8b53047cfcae03abf7ca94d27391 2025-09-29 20:24:07 +00:00
XXXXRT666
a8dc94ebb0 . 2025-09-29 21:24:00 +01:00
XXXXRT666
dbbc4f4b48 . 2025-09-29 21:21:56 +01:00
XXXXRT666
54541033e2 . 2025-09-29 21:15:04 +01:00
XXXXRT666
1059fc3858 . 2025-09-29 21:12:37 +01:00
XXXXRT666
72a9c1daba . 2025-09-29 19:50:05 +01:00
XXXXRT666
0690743347 Draft 2025-09-29 19:21:25 +01:00
RVC-Boss
11aa78bd9b
修复环境变量可能不为str的问题
修复环境变量可能不为str的问题
2025-09-10 15:01:04 +08:00
10 changed files with 72 additions and 51 deletions

View File

@ -24,6 +24,29 @@ if (-not [string]::IsNullOrWhiteSpace($suffix)) {
$pkgName = "$pkgName-$cuda"
$SevenZipPath = "C:\Program Files\7-Zip\7z.exe"
$SevenZipDir = Split-Path $SevenZipPath
$CodecsDir = Join-Path $SevenZipDir "Codecs"
$Url = "https://github.com/mcmilk/7-Zip-zstd/releases/download/v25.01-v1.5.7-R1/Codecs-x64.7z"
$TempArchive = "$env:TEMP\Codecs-x64.7z"
Write-Host "Downloading 7-Zip Zstd plugin..."
Invoke-WebRequest -Uri $Url -OutFile $TempArchive
if (-not (Test-Path $CodecsDir)) {
New-Item -Path $CodecsDir -ItemType Directory | Out-Null
Write-Host "Created Codecs directory: $CodecsDir"
}
Write-Host "Extracting plugin..."
& $SevenZipPath x $TempArchive "-o$CodecsDir" -y | Out-Null
Remove-Item $TempArchive -Force
Write-Host "Patch complete. Installed plugins in $CodecsDir"
$baseHF = "https://huggingface.co/XXXXRT/GPT-SoVITS-Pretrained/resolve/main"
$PRETRAINED_URL = "$baseHF/pretrained_models.zip"
$G2PW_URL = "$baseHF/G2PWModel.zip"
@ -118,14 +141,14 @@ Write-Host "[INFO] Installing PyTorch..."
switch ($cuda) {
"cu126" {
& ".\runtime\python.exe" -m pip install psutil ninja packaging wheel "setuptools>=42" --no-warn-script-location
& ".\runtime\python.exe" -m pip install torch --index-url https://download.pytorch.org/whl/cu126 --no-warn-script-location
& ".\runtime\python.exe" -m pip install flash-attn -i https://xxxxrt666.github.io/PIP-Index/ --no-build-isolation
& ".\runtime\python.exe" -m pip install psutil ninja packaging wheel "setuptools>=42" --no-warn-script-location --no-cache-dir
& ".\runtime\python.exe" -m pip install torch --index-url https://download.pytorch.org/whl/cu126 --no-warn-script-location --no-cache-dir
& ".\runtime\python.exe" -m pip install flash-attn -i https://xxxxrt666.github.io/PIP-Index/ --no-build-isolation --no-cache-dir
}
"cu128" {
& ".\runtime\python.exe" -m pip install psutil ninja packaging wheel "setuptools>=42" --no-warn-script-location
& ".\runtime\python.exe" -m pip install torch --index-url https://download.pytorch.org/whl/cu128 --no-warn-script-location
& ".\runtime\python.exe" -m pip install flash-attn -i https://xxxxrt666.github.io/PIP-Index/ --no-build-isolation
& ".\runtime\python.exe" -m pip install psutil ninja packaging wheel "setuptools>=42" --no-warn-script-location --no-cache-dir
& ".\runtime\python.exe" -m pip install torch --index-url https://download.pytorch.org/whl/cu128 --no-warn-script-location --no-cache-dir
& ".\runtime\python.exe" -m pip install flash-attn -i https://xxxxrt666.github.io/PIP-Index/ --no-build-isolation --no-cache-dir
}
default {
Write-Error "Unsupported CUDA version: $cuda"
@ -168,7 +191,7 @@ Copy-Item -Path $curr -Destination $pkgName -Recurse
$7zPath = "$pkgName.7z"
$start = Get-Date
Write-Host "Compress Starting at $start"
& "C:\Program Files\7-Zip\7z.exe" a -t7z "$7zPath" "$pkgName" -m0=lzma2 -mx=9 -mmt=on -bsp1
& "C:\Program Files\7-Zip\7z.exe" a -t7z "$7zPath" "$pkgName" -m0=bcj -m1=zstd -mx=22 -mmt=on -bsp1
$end = Get-Date
Write-Host "Elapsed time: $($end - $start)"
Get-ChildItem .

View File

@ -28,9 +28,6 @@ jobs:
PKG_SUFFIX: ${{ github.event.inputs.suffix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Windows CUDA 12.9
uses: Jimver/cuda-toolkit@v0.2.24
id: cuda-toolkit-win-129
@ -39,6 +36,17 @@ jobs:
method: "network"
sub-packages: '["nvcc", "cudart", "visual_studio_integration"]'
- name: Checkout
uses: actions/checkout@v4
- name: Cache pip
uses: actions/cache@v4
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Run Build and Upload Script
shell: pwsh
run: |

View File

@ -1,7 +1,5 @@
from __future__ import annotations
from typing import cast
import mlx.core as mx
import mlx.nn as nn
@ -43,7 +41,7 @@ class Attention(AttentionABC):
return out
def __call__(self, x: Array, input_pos: Array, kv_cache: KVCache | KVCacheQ, cache_idx: Array, attn_mask: Array):
bsz, seqlen, _ = cast(tuple[int, ...], x.shape)
bsz, seqlen, _ = x.shape
q, k, v = self.in_proj(x).split(3, axis=-1)
@ -69,7 +67,7 @@ class Attention(AttentionABC):
return attn
# def __call__(self, x: Array, input_pos: Array, kv_cache: KVCache | KVCacheQ, cache_idx: Array, attn_mask: Array):
# bsz, seqlen, _ = cast(tuple[int, ...], x.shape)
# bsz, seqlen, _ = x.shape
# q, k, v = self.in_proj(x).split(3, axis=-1)

View File

@ -1,7 +1,5 @@
from __future__ import annotations
from typing import cast
import mlx.core as mx
from ..structs_mlx import KVCache, KVCacheQ
@ -22,7 +20,7 @@ class Attention(AttentionABC):
self.kc_class = KVCacheHND
def __call__(self, x: Array, input_pos: Array, kv_cache: KVCache | KVCacheQ, cache_idx: Array, attn_mask: Array):
bsz, seqlen, _ = cast(tuple[int, ...], x.shape)
bsz, seqlen, _ = x.shape
q, k, v = self.in_proj(x).split(3, axis=-1)

View File

@ -1,7 +1,5 @@
from __future__ import annotations
from typing import cast
import mlx.core as mx
from ..structs_mlx import KVCache, KVCacheQ
@ -22,7 +20,7 @@ class Attention(AttentionABC):
self.kc_class = KVCacheHND
def __call__(self, x: Array, input_pos: Array, kv_cache: KVCache | KVCacheQ, cache_idx: Array, attn_mask: Array):
bsz, seqlen, _ = cast(tuple[int, ...], x.shape)
bsz, seqlen, _ = x.shape
q, k, v = self.in_proj(x).split(3, axis=-1)

View File

@ -1,4 +1,4 @@
from typing import Protocol, cast
from typing import Protocol
import mlx.core as mx
@ -33,7 +33,7 @@ class sample_naive(SampleProtocolMLX):
return mx.argmax(probs, axis=-1, keepdims=True).astype(mx.int32)
if repetition_penalty != 1.0:
batch_idx = mx.arange(cast(tuple[int, ...], previous_tokens.shape)[0])
batch_idx = mx.arange(previous_tokens.shape[0])
previous_tokens = previous_tokens.astype(mx.int64)
selected_logists = logits[batch_idx, previous_tokens]
selected_logists = mx.where(
@ -48,7 +48,7 @@ class sample_naive(SampleProtocolMLX):
sorted_indices_to_remove = cum_probs > top_p
sorted_indices_to_remove[:, -1] = False
indices_to_remove = mx.zeros_like(logits).astype(mx.bool_)
batch_indices = mx.arange(cast(tuple[int, ...], logits.shape)[0])[:, None]
batch_indices = mx.arange(logits.shape[0])[:, None]
indices_to_remove[batch_indices, sorted_indices] = sorted_indices_to_remove
logits = mx.where(indices_to_remove, -mx.inf, logits)
@ -59,7 +59,7 @@ class sample_naive(SampleProtocolMLX):
pivot = mx.expand_dims(v[:, 0], -1)
logits = mx.where(logits < pivot, -mx.inf, logits)
gumbel_noise = mx.random.gumbel(shape=cast(tuple[int, ...], logits.shape), dtype=logits.dtype)
gumbel_noise = mx.random.gumbel(shape=logits.shape, dtype=logits.dtype)
idx_next = mx.argmax(logits + gumbel_noise, axis=-1, keepdims=True).astype(mx.int32)
return idx_next

View File

@ -5,7 +5,7 @@ Modified From https://github.com/XXXXRT666/GPT-SoVITS
from __future__ import annotations
from dataclasses import dataclass
from typing import List, MutableSequence, Protocol, TypeAlias, cast
from typing import List, MutableSequence, Protocol, TypeAlias
import mlx.core as mx
import torch
@ -32,10 +32,10 @@ class T2SRequestMLX:
@classmethod
def from_torch(cls, request: T2SRequest) -> T2SRequestMLX:
x = list(map(lambda tensor: mx.array(tensor.cpu()), request.x))
x_lens = mx.array(request.x_lens.cpu())
prompts = mx.array(request.prompts.cpu())
bert_feature = list(map(lambda tensor: mx.array(tensor.cpu()), request.bert_feature))
x = list(map(lambda tensor: mx.array(tensor.cpu()), request.x)) # type: ignore
x_lens = mx.array(request.x_lens.cpu()) # type: ignore
prompts = mx.array(request.prompts.cpu()) # type: ignore
bert_feature = list(map(lambda tensor: mx.array(tensor.cpu()), request.bert_feature)) # type: ignore
return cls(
x,
@ -99,7 +99,7 @@ class T2SSessionMLX:
self.dtype = dtype
bsz = len(request.x)
y_len: int = cast(tuple[int, ...], request.prompts.shape)[-1]
y_len: int = request.prompts.shape[-1]
self.bsz = bsz
self.y_len = y_len
@ -111,10 +111,10 @@ class T2SSessionMLX:
self.x = [i.astype(mx.int32) for i in request.x]
self.x_lens = request.x_lens.astype(mx.int32)
self.y = mx.zeros((bsz, decoder.max_seq_length)).astype(mx.int32)
self.y[:, : cast(tuple[int, ...], request.prompts.shape)[-1]] = request.prompts.astype(mx.int32)
self.y[:, : request.prompts.shape[-1]] = request.prompts.astype(mx.int32)
self.bert_feature = [i.astype(dtype) for i in request.bert_feature]
self.prefill_len = self.x_lens + cast(tuple[int, ...], request.prompts.shape)[1]
self.prefill_len = self.x_lens + request.prompts.shape[1]
self.input_pos = mx.zeros_like(self.prefill_len)
self.input_pos += self.prefill_len

View File

@ -140,7 +140,7 @@ class T2SEngine(T2SEngineProtocol):
logger.error("Bad Zero Prediction")
else:
logger.info(
f"T2S Decoding EOS {session.prefill_len.tolist().__str__().strip('[]')} -> {[cast(tuple[int, ...], i.shape)[-1] for i in session.y_results].__str__().strip('[]')}"
f"T2S Decoding EOS {session.prefill_len.tolist().__str__().strip('[]')} -> {[i.shape[-1] for i in session.y_results].__str__().strip('[]')}"
)
logger.info(f"Infer Speed: {(idx - 1) / (time.perf_counter() - t1):.2f} token/s")
infer_time = time.perf_counter() - t1
@ -199,7 +199,7 @@ class T2SEngine(T2SEngineProtocol):
.replace("norm1", "attention_norm")
.replace("norm2", "ffn_norm")
)
value_mlx = mx.array(value)
value_mlx = mx.array(value) # type: ignore
state_dict_mlx.append((key, value_mlx))
return state_dict_mlx

View File

@ -2,7 +2,7 @@ from __future__ import annotations
import math
from abc import ABC, abstractmethod
from typing import MutableSequence, cast
from typing import MutableSequence
import mlx.core as mx
import mlx.nn as nn
@ -85,7 +85,7 @@ class SinePositionalEmbedding(nn.Module):
embedded_x (Array): [batch_size, 1, embed_dim]
"""
batch_size = cast(tuple[int, ...], x.shape)[0]
batch_size = x.shape[0]
pe_values = self._pe[mx.arange(batch_size), input_pos - 1] # (batch_size, embed_dim)
return x * self.x_scale + self.alpha * mx.expand_dims(pe_values, 1) # (batch_size, 1, embed_dim)
@ -98,7 +98,7 @@ class SinePositionalEmbedding(nn.Module):
Returns:
embedded_x (Array): [batch_size, seq_len, embed_dim]
"""
pe_values = self._pe[:, : cast(tuple[int, ...], x.shape)[-2]]
pe_values = self._pe[:, : x.shape[-2]]
return x * self.x_scale + self.alpha * pe_values
@ -129,8 +129,8 @@ class KVCacheHND(KVCacheProtocol):
assert len(kv_cache) == 2
k_cache, v_cache = kv_cache
k_cache[..., : cast(tuple[int, ...], k_val.shape)[1], :] = k_val.swapaxes(1, 2)
v_cache[..., : cast(tuple[int, ...], v_val.shape)[1], :] = v_val.swapaxes(1, 2)
k_cache[..., : k_val.shape[1], :] = k_val.swapaxes(1, 2)
v_cache[..., : v_val.shape[1], :] = v_val.swapaxes(1, 2)
@staticmethod
def init_cache(batch_size: int, max_seq_length: int, n_heads: int, head_dim: int, dtype: mx.Dtype) -> KVCache:
@ -207,7 +207,7 @@ class KVCacheHNDQuantized(KVCacheProtocol):
assert len(kv_cache) == 3
(k_q_out, k_s_out, k_b_out), (v_q_out, v_s_out, v_b_out), (group_size, bits) = kv_cache
S = cast(tuple[int, ...], k_val.shape)[1]
S = k_val.shape[1]
k_sw = k_val.swapaxes(1, 2)
v_sw = v_val.swapaxes(1, 2)
@ -276,7 +276,7 @@ class AttentionABC(ABC, nn.Module):
) -> Array: ...
def prefill(self, x: Array, kv_cache: KVCache | KVCacheQ, attn_mask: Array):
bsz, seqlen, _ = cast(tuple[int, ...], x.shape)
bsz, seqlen, _ = x.shape
q, k, v = self.in_proj(x).split(3, axis=-1)
@ -481,15 +481,13 @@ class T2SDecoderABC(nn.Module, T2SDecoderProtocol):
y: Array,
bert_features: list[Array],
):
x_len: list[int] = [cast(tuple[int, ...], i.shape)[0] for i in x]
x_len: list[int] = [i.shape[0] for i in x]
x_len_max = max(x_len)
xy_pos = mx.zeros((len(x), x_len_max + cast(tuple[int, ...], y.shape)[1], self.embedding_dim)).astype(
bert_features[0].dtype
)
xy_pos = mx.zeros((len(x), x_len_max + y.shape[1], self.embedding_dim)).astype(bert_features[0].dtype)
bert_features = list(map(lambda x: x.swapaxes(0, 1), bert_features))
y_len = cast(tuple[int, ...], y.shape)[1]
y_len = y.shape[1]
y_emb = self.ar_audio_embedding(y)
y_pos = self.ar_audio_position.prefill(y_emb)

View File

@ -7,7 +7,7 @@ import traceback
import warnings
from functools import partial
from pathlib import Path
from time import time as ttime
from time import perf_counter as ttime
from typing import Any
import gradio as gr
@ -69,7 +69,6 @@ def set_high_priority():
p = psutil.Process(os.getpid())
with contextlib.suppress(psutil.AccessDenied):
p.nice(psutil.HIGH_PRIORITY_CLASS)
print("已将进程优先级设为 High")
_LANG_RE = re.compile(r"^[a-z]{2}[_-][A-Z]{2}$")
@ -723,7 +722,6 @@ def get_tts_wav(
prompt_text += "" if prompt_language != "en" else "."
print(">>", i18n("实际输入的参考文本:"), prompt_text)
text = text.strip("\n")
# if (text[0] not in splits and len(get_first(text)) < 4): text = "。" + text if text_language != "en" else "." + text
print(">>", i18n("实际输入的目标文本:"), text)
zero_wav = np.zeros(
@ -813,7 +811,7 @@ def get_tts_wav(
top_p=top_p,
temperature=temperature,
early_stop_num=1500,
use_cuda_graph=torch.cuda.is_available(),
use_cuda_graph=torch.cuda.is_available(), # Try to use CUDA Graph for all backend, fallback to normal if not applicapble
# debug=True,
)
assert t2s_engine
@ -1300,7 +1298,7 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False, js=js, css=css
if __name__ == "__main__":
set_high_priority()
app.queue(api_open=False, default_concurrency_limit=512, max_size=1024).launch(
app.queue(api_open=False, default_concurrency_limit=1, max_size=1024).launch(
server_name="0.0.0.0",
inbrowser=True,
share=is_share,