From 74e1d4627bb9e2093767dbc21ea84fe8a2a3ddaf Mon Sep 17 00:00:00 2001 From: Mangio621 Date: Sun, 14 May 2023 03:41:15 +1000 Subject: [PATCH] Fixed optimal torch device for crepe computation with the new upstream conflict resolve. --- vc_infer_pipeline.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/vc_infer_pipeline.py b/vc_infer_pipeline.py index 06e2906..14f744b 100644 --- a/vc_infer_pipeline.py +++ b/vc_infer_pipeline.py @@ -45,6 +45,17 @@ class VC(object): self.t_max = self.sr * self.x_max # 免查询时长阈值 self.device = config.device + # Fork Feature: Get the best torch device to use for f0 algorithms that require a torch device. Will return the type (torch.device) + def get_optimal_torch_device(self, index: int = 0) -> torch.device: + # Get cuda device + if torch.cuda.is_available(): + return torch.device(f"cuda:{index % torch.cuda.device_count()}") # Very fast + elif torch.backends.mps.is_available(): + return torch.device("mps") + # Insert an else here to grab "xla" devices if available. TO DO later. Requires the torch_xla.core.xla_model library + # Else wise return the "cpu" as a torch device, + return torch.device("cpu") + def get_f0_crepe_computation( self, x,