CoolFace
Apppublic

ChazzyG/Retrieval-based-Voice-Conversion-WebUI

sourceHugging Faceapache-2.0updated 9mo agoView on Hugging Face
0likes
config.py118 linesDownload Raw Back to root
1import argparse2import glob3import sys4import torch5from multiprocessing import cpu_count6 7 8class Config:9    def __init__(self):10        self.device = "cuda:0"11        self.is_half = True12        self.n_cpu = 013        self.gpu_name = None14        self.gpu_mem = None15        (16            self.python_cmd,17            self.listen_port,18            self.iscolab,19            self.noparallel,20            self.noautoopen,21        ) = self.arg_parse()22        self.x_pad, self.x_query, self.x_center, self.x_max = self.device_config()23 24    def arg_parse(self) -> tuple:25        parser = argparse.ArgumentParser()26        parser.add_argument("--port", type=int, default=7865, help="Listen port")27        parser.add_argument(28            "--pycmd", type=str, default="python", help="Python command"29        )30        parser.add_argument("--colab", action="store_true", help="Launch in colab")31        parser.add_argument(32            "--noparallel", action="store_true", help="Disable parallel processing"33        )34        parser.add_argument(35            "--noautoopen",36            action="store_true",37            help="Do not open in browser automatically",38        )39        cmd_opts = parser.parse_args()40 41        cmd_opts.port = cmd_opts.port if 0 <= cmd_opts.port <= 65535 else 786542 43        return (44            cmd_opts.pycmd,45            cmd_opts.port,46            cmd_opts.colab,47            cmd_opts.noparallel,48            cmd_opts.noautoopen,49        )50 51    def device_config(self) -> tuple:52        if torch.cuda.is_available():53            i_device = int(self.device.split(":")[-1])54            self.gpu_name = torch.cuda.get_device_name(i_device)55            if (56                ("16" in self.gpu_name and "V100" not in self.gpu_name.upper())57                or "P40" in self.gpu_name.upper()58                or "1060" in self.gpu_name59                or "1070" in self.gpu_name60                or "1080" in self.gpu_name61            ):62                print("16系/10系显卡和P40强制单精度")63                self.is_half = False64                for config_file in ["32k.json", "40k.json", "48k.json"]:65                    with open(f"configs/{config_file}", "r") as f:66                        strr = f.read().replace("true", "false")67                    with open(f"configs/{config_file}", "w") as f:68                        f.write(strr)69                with open("trainset_preprocess_pipeline_print.py", "r") as f:70                    strr = f.read().replace("3.7", "3.0")71                with open("trainset_preprocess_pipeline_print.py", "w") as f:72                    f.write(strr)73            else:74                self.gpu_name = None75            self.gpu_mem = int(76                torch.cuda.get_device_properties(i_device).total_memory77                / 102478                / 102479                / 102480                + 0.481            )82            if self.gpu_mem <= 4:83                with open("trainset_preprocess_pipeline_print.py", "r") as f:84                    strr = f.read().replace("3.7", "3.0")85                with open("trainset_preprocess_pipeline_print.py", "w") as f:86                    f.write(strr)87        elif torch.backends.mps.is_available():88            print("没有发现支持的N卡, 使用MPS进行推理")89            self.device = "mps"90        else:91            print("没有发现支持的N卡, 使用CPU进行推理")92            self.device = "cpu"93            self.is_half = True94 95        if self.n_cpu == 0:96            self.n_cpu = cpu_count()97 98        if self.is_half:99            # 6G显存配置100            x_pad = 3101            x_query = 10102            x_center = 60103            x_max = 65104        else:105            # 5G显存配置106            x_pad = 1107            x_query = 6108            x_center = 38109            x_max = 41110 111        if self.gpu_mem != None and self.gpu_mem <= 4:112            x_pad = 1113            x_query = 5114            x_center = 30115            x_max = 32116 117        return x_pad, x_query, x_center, x_max118