From e2a88844735b330b2045abcd6c72fb74199357b2 Mon Sep 17 00:00:00 2001 From: wang Date: Wed, 30 Jul 2025 08:56:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=80=E4=BA=9B=E6=8B=BC?= =?UTF-8?q?=E5=86=99=E9=94=99=E8=AF=AF=E3=80=82=201.AttributeError:=20modu?= =?UTF-8?q?le=20'torch.serialization'=20has=20no=20attribute=20'FILE=5FLIK?= =?UTF-8?q?E'=202.CosyVoiceModel=20changed=20cosyvoice.yaml=20to=20cosyvoi?= =?UTF-8?q?ce2.yaml=203.cached=20for=20robust=5Fdownloader.downloader=20-?= =?UTF-8?q?=20INFO=20-=20Downloading=204.Dockerfile=20ignore=20.git=20caus?= =?UTF-8?q?e=20git=20report=20error=20in=20the=20config.py=205.RuntimeErro?= =?UTF-8?q?r:=20Cannot=20add=20middleware=20after=20an=20application=20has?= =?UTF-8?q?=20started.=20By:=20@self.app.middleware("http")=206.FireRedTts?= =?UTF-8?q?:=20Exception:=20Unknown=20model=20id:=20fireredtts=20in=20modu?= =?UTF-8?q?les/core/pipeline/factory.py=207.The=20WebUI=20repeatly=20repor?= =?UTF-8?q?ts=20error=20when=20using=20CPU=20only:=20RuntimeError:=20Found?= =?UTF-8?q?=20no=20NVIDIA=20driver=20on=20your=20system.=208.Remap=20torch?= =?UTF-8?q?.load=20to=20device('cpu').?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wang --- modules/api/Api.py | 2 +- modules/config.py | 7 ++++--- modules/core/models/tts/CosyVoiceModel.py | 2 +- modules/core/pipeline/factory.py | 2 +- modules/devices/devices.py | 11 ++++++++--- modules/repos_static/ChatTTS/ChatTTS/core.py | 4 ++-- .../repos_static/ChatTTS/ChatTTS/model/tokenizer.py | 2 +- .../FireRedTTS/fireredtts/modules/codec/speaker.py | 2 +- .../GPT_SoVITS/text/LangSegmenter/langsegmenter.py | 2 +- 9 files changed, 20 insertions(+), 14 deletions(-) diff --git a/modules/api/Api.py b/modules/api/Api.py index 7b3bfb68..a9861fcc 100644 --- a/modules/api/Api.py +++ b/modules/api/Api.py @@ -98,7 +98,7 @@ async def _set_cors_headers(response: Response, origin: str = None): if allow_credentials: response.headers["Access-Control-Allow-Credentials"] = "true" - @self.app.middleware("http") +# @self.app.middleware("http") async def cors_handler(request: Request, call_next): response: Response = await call_next(request) diff --git a/modules/config.py b/modules/config.py index 3427686a..9258d7be 100644 --- a/modules/config.py +++ b/modules/config.py @@ -1,3 +1,4 @@ +import os import sys import torch @@ -17,9 +18,9 @@ "python_version": ".".join([str(x) for x in sys.version_info[0:3]]), "torch_version": getattr(torch, "__long_version__", torch.__version__), # "gradio_version":gr.__version__, - "git_tag": git.git_tag(), - "git_branch": git.branch_name(), - "git_commit": git.commit_hash(), + "git_tag": os.environ.get("V_GIT_TAG") or git.git_tag(), + "git_branch": os.environ.get("V_GIT_BRANCH") or git.branch_name(), + "git_commit": os.environ.get("V_GIT_COMMIT") or git.commit_hash(), "ffmpeg_version": ffmpeg.ffmpeg_version(), } ) diff --git a/modules/core/models/tts/CosyVoiceModel.py b/modules/core/models/tts/CosyVoiceModel.py index cb7e0b26..2250fad2 100644 --- a/modules/core/models/tts/CosyVoiceModel.py +++ b/modules/core/models/tts/CosyVoiceModel.py @@ -100,7 +100,7 @@ def load( # instruct = True if "-Instruct" in str(model_dir) else False instruct = True - with open(model_dir / "cosyvoice.yaml", "r") as f: + with open(model_dir / "cosyvoice2.yaml", "r") as f: configs = load_hyperpyyaml(f, overrides=self.hp_overrides) frontend = CosyVoiceFrontEnd( diff --git a/modules/core/pipeline/factory.py b/modules/core/pipeline/factory.py index 77159bba..56dfc06f 100644 --- a/modules/core/pipeline/factory.py +++ b/modules/core/pipeline/factory.py @@ -120,7 +120,7 @@ def create(cls, ctx: TTSPipelineContext) -> TTSPipeline: return cls.create_fishspeech_pipeline(ctx) elif model_id == "cosyvoice": return cls.create_cosyvoice_pipeline(ctx) - elif model_id == "firered": + elif model_id == "fireredtts": return cls.create_fire_red_tts_pipeline(ctx) elif model_id == "f5" or model_id == "f5tts": return cls.create_f5_tts_pipeline(ctx) diff --git a/modules/devices/devices.py b/modules/devices/devices.py index a047654b..5445c3e0 100644 --- a/modules/devices/devices.py +++ b/modules/devices/devices.py @@ -201,9 +201,14 @@ def get_cpu_memory(): def get_gpu_memory(): - total_memory = torch.cuda.get_device_properties(0).total_memory - reserved_memory = torch.cuda.memory_reserved(0) - allocated_memory = torch.cuda.memory_allocated(0) + if torch.cuda.is_available(): + total_memory = torch.cuda.get_device_properties(0).total_memory + reserved_memory = torch.cuda.memory_reserved(0) + allocated_memory = torch.cuda.memory_allocated(0) + else: + total_memory = 0 + reserved_memory = 0 + allocated_memory = 0 free_memory = total_memory - reserved_memory return MemUsage( device=cuda, diff --git a/modules/repos_static/ChatTTS/ChatTTS/core.py b/modules/repos_static/ChatTTS/ChatTTS/core.py index e9f295b9..e17b8e22 100644 --- a/modules/repos_static/ChatTTS/ChatTTS/core.py +++ b/modules/repos_static/ChatTTS/ChatTTS/core.py @@ -63,7 +63,7 @@ def download_models( self, source: Literal["huggingface", "local", "custom"] = "local", force_redownload=False, - custom_path: Optional[torch.serialization.FILE_LIKE] = None, + custom_path: Optional[torch.serialization.FileLike] = None, ) -> Optional[str]: if source == "local": download_path = os.getcwd() @@ -121,7 +121,7 @@ def load( source: Literal["huggingface", "local", "custom"] = "local", force_redownload=False, compile: bool = False, - custom_path: Optional[torch.serialization.FILE_LIKE] = None, + custom_path: Optional[torch.serialization.FileLike] = None, device: Optional[torch.device] = None, coef: Optional[torch.Tensor] = None, use_flash_attn=False, diff --git a/modules/repos_static/ChatTTS/ChatTTS/model/tokenizer.py b/modules/repos_static/ChatTTS/ChatTTS/model/tokenizer.py index e464929f..30190e72 100644 --- a/modules/repos_static/ChatTTS/ChatTTS/model/tokenizer.py +++ b/modules/repos_static/ChatTTS/ChatTTS/model/tokenizer.py @@ -16,7 +16,7 @@ class Tokenizer: def __init__( self, - tokenizer_path: torch.serialization.FILE_LIKE, + tokenizer_path: torch.serialization.FileLike, ): """ tokenizer: BertTokenizerFast = torch.load( diff --git a/modules/repos_static/FireRedTTS/fireredtts/modules/codec/speaker.py b/modules/repos_static/FireRedTTS/fireredtts/modules/codec/speaker.py index be691a31..eb7305f3 100644 --- a/modules/repos_static/FireRedTTS/fireredtts/modules/codec/speaker.py +++ b/modules/repos_static/FireRedTTS/fireredtts/modules/codec/speaker.py @@ -1037,7 +1037,7 @@ def __init__(self, ckpt_path, device="cuda"): global_context=True, batch_norm=True, ) - model.load_state_dict(torch.load(ckpt_path), strict=True) + model.load_state_dict(torch.load(ckpt_path, map_location=torch.device(device)), strict=True) model.eval() self.model = model self.model.to(device) diff --git a/modules/repos_static/GPT_SoVITS/GPT_SoVITS/text/LangSegmenter/langsegmenter.py b/modules/repos_static/GPT_SoVITS/GPT_SoVITS/text/LangSegmenter/langsegmenter.py index 1740a549..32a5af2a 100644 --- a/modules/repos_static/GPT_SoVITS/GPT_SoVITS/text/LangSegmenter/langsegmenter.py +++ b/modules/repos_static/GPT_SoVITS/GPT_SoVITS/text/LangSegmenter/langsegmenter.py @@ -12,7 +12,7 @@ fast_langdetect.infer._default_detector = fast_langdetect.infer.LangDetector( fast_langdetect.infer.LangDetectConfig( - cache_dir=Path(__file__).parent.parent.parent / "pretrained_models" / "fast_langdetect" + cache_dir="models/gpt_sovits_v4/fast_langdetect" ) )