Improve: when cuda is unavailable, use cpu device

This commit is contained in:
litagin02
2024-02-07 15:58:43 +09:00
parent d51c8bf639
commit 6762c654ac

View File

@@ -1,15 +1,19 @@
""" """
@Desc: 全局配置文件读取 @Desc: 全局配置文件读取
""" """
import argparse
import os import os
import shutil import shutil
from typing import Dict, List from typing import Dict, List
import torch
import yaml import yaml
from common.log import logger from common.log import logger
# If not cuda available, set possible devices to cpu
cuda_available = torch.cuda.is_available()
class Resample_config: class Resample_config:
"""重采样配置""" """重采样配置"""
@@ -44,13 +48,23 @@ class Preprocess_text_config:
max_val_total: int = 10000, max_val_total: int = 10000,
clean: bool = True, clean: bool = True,
): ):
self.transcription_path: str = transcription_path # 原始文本文件路径,文本格式应为{wav_path}|{speaker_name}|{language}|{text}。 self.transcription_path: str = (
self.cleaned_path: str = cleaned_path # 数据清洗后文本路径,可以不填。不填则将在原始文本目录生成 transcription_path # 原始文本文件路径,文本格式应为{wav_path}|{speaker_name}|{language}|{text}。
self.train_path: str = train_path # 训练集路径,可以不填。不填则将在原始文本目录生成 )
self.val_path: str = val_path # 验证集路径,可以不填。不填则将在原始文本目录生成 self.cleaned_path: str = (
cleaned_path # 数据清洗后文本路径,可以不填。不填则将在原始文本目录生成
)
self.train_path: str = (
train_path # 训练集路径,可以不填。不填则将在原始文本目录生成
)
self.val_path: str = (
val_path # 验证集路径,可以不填。不填则将在原始文本目录生成
)
self.config_path: str = config_path # 配置文件路径 self.config_path: str = config_path # 配置文件路径
self.val_per_lang: int = val_per_lang # 每个speaker的验证集条数 self.val_per_lang: int = val_per_lang # 每个speaker的验证集条数
self.max_val_total: int = max_val_total # 验证集最大条数,多于的会被截断并放到训练集中 self.max_val_total: int = (
max_val_total # 验证集最大条数,多于的会被截断并放到训练集中
)
self.clean: bool = clean # 是否进行数据清洗 self.clean: bool = clean # 是否进行数据清洗
@classmethod @classmethod
@@ -83,6 +97,8 @@ class Bert_gen_config:
): ):
self.config_path = config_path self.config_path = config_path
self.num_processes = num_processes self.num_processes = num_processes
if not cuda_available:
device = "cpu"
self.device = device self.device = device
self.use_multi_device = use_multi_device self.use_multi_device = use_multi_device
@@ -104,6 +120,8 @@ class Style_gen_config:
): ):
self.config_path = config_path self.config_path = config_path
self.num_processes = num_processes self.num_processes = num_processes
if not cuda_available:
device = "cpu"
self.device = device self.device = device
@classmethod @classmethod
@@ -143,7 +161,7 @@ class Train_ms_config:
class Webui_config: class Webui_config:
"""webui 配置""" """webui 配置 (for webui.py, not supported now)"""
def __init__( def __init__(
self, self,
@@ -155,6 +173,8 @@ class Webui_config:
share: bool = False, share: bool = False,
debug: bool = False, debug: bool = False,
): ):
if not cuda_available:
device = "cpu"
self.device: str = device self.device: str = device
self.model: str = model # 端口号 self.model: str = model # 端口号
self.config_path: str = config_path # 是否公开部署,对外网开放 self.config_path: str = config_path # 是否公开部署,对外网开放
@@ -182,6 +202,8 @@ class Server_config:
origins: List[str] = None, origins: List[str] = None,
): ):
self.port: int = port self.port: int = port
if not cuda_available:
device = "cpu"
self.device: str = device self.device: str = device
self.language: str = language self.language: str = language
self.limit: int = limit self.limit: int = limit