Skip to content

Commit

Permalink
优化 config.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jun 24, 2023
1 parent f6051a1 commit 4e0d399
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from multiprocessing import cpu_count


def config_file_change_fp32():
def use_fp32_config():
for config_file in ["32k.json", "40k.json", "48k.json"]:
with open(f"configs/{config_file}", "r") as f:
strr = f.read().replace("true", "false")
Expand Down Expand Up @@ -58,6 +58,17 @@ def arg_parse() -> tuple:
cmd_opts.noparallel,
cmd_opts.noautoopen,
)

# has_mps is only available in nightly pytorch (for now) and MasOS 12.3+.
# check `getattr` and try it for compatibility
@staticmethod
def has_mps() -> bool:
if not torch.backends.mps.is_available(): return False
try:
torch.zeros(1).to(torch.device("mps"))
return True
except Exception:
return False

def device_config(self) -> tuple:
if torch.cuda.is_available():
Expand All @@ -70,9 +81,9 @@ def device_config(self) -> tuple:
or "1070" in self.gpu_name
or "1080" in self.gpu_name
):
print("16系/10系显卡和P40强制单精度")
print("16|10|P40 series, force to fp32")
self.is_half = False
config_file_change_fp32()
use_fp32_config()
else:
self.gpu_name = None
self.gpu_mem = int(
Expand All @@ -87,16 +98,16 @@ def device_config(self) -> tuple:
strr = f.read().replace("3.7", "3.0")
with open("trainset_preprocess_pipeline_print.py", "w") as f:
f.write(strr)
elif torch.backends.mps.is_available():
print("没有发现支持的N卡, 使用MPS进行推理")
elif self.has_mps():
print("No supported Nvidia GPU, use MPS instead")
self.device = "mps"
self.is_half = False
config_file_change_fp32()
use_fp32_config()
else:
print("没有发现支持的N卡, 使用CPU进行推理")
print("No supported Nvidia GPU, use CPU instead")
self.device = "cpu"
self.is_half = False
config_file_change_fp32()
use_fp32_config()

if self.n_cpu == 0:
self.n_cpu = cpu_count()
Expand Down

0 comments on commit 4e0d399

Please sign in to comment.