refactor InvokeAIAppConfig

This commit is contained in:
Lincoln Stein
2023-08-17 13:47:26 -04:00
parent 503e3bca54
commit ed38eaa10c
10 changed files with 498 additions and 393 deletions

View File

@ -17,13 +17,17 @@ config = InvokeAIAppConfig.get_config()
def choose_torch_device() -> torch.device:
"""Convenience routine for guessing which GPU device to run model on"""
if config.always_use_cpu:
if config.use_cpu: # legacy setting - force CPU
return CPU_DEVICE
if torch.cuda.is_available():
return torch.device("cuda")
if hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
return torch.device("mps")
return CPU_DEVICE
elif config.device == "auto":
if torch.cuda.is_available():
return torch.device("cuda")
if hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
return torch.device("mps")
else:
return CPU_DEVICE
else:
return torch.device(config.device)
def choose_precision(device: torch.device) -> str: