Simplify small functions

This commit is contained in:
Ftps
2023-11-17 18:09:35 +09:00
parent d1cf32dc16
commit 95b7ce430b

View File

@@ -99,20 +99,13 @@ class Config:
# check `getattr` and try it for compatibility # check `getattr` and try it for compatibility
@staticmethod @staticmethod
def has_mps() -> bool: def has_mps() -> bool:
if not torch.backends.mps.is_available(): return torch.backends.mps.is_available() and not torch.zeros(1).to(
return False torch.device("mps")
try: )
torch.zeros(1).to(torch.device("mps"))
return True
except Exception:
return False
@staticmethod @staticmethod
def has_xpu() -> bool: def has_xpu() -> bool:
if hasattr(torch, "xpu") and torch.xpu.is_available(): return hasattr(torch, "xpu") and torch.xpu.is_available()
return True
else:
return False
def use_fp32_config(self) -> None: def use_fp32_config(self) -> None:
for config_file, data in self.json_config.items(): for config_file, data in self.json_config.items():