mirror of
https://github.com/openvinotoolkit/stable-diffusion-webui.git
synced 2025-01-05 19:34:33 +03:00
eliminate duplicated code from #5095
This commit is contained in:
parent
997ac57020
commit
5b2c316890
@ -24,17 +24,18 @@ def extract_device_id(args, name):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_cuda_device_string():
|
||||||
|
from modules import shared
|
||||||
|
|
||||||
|
if shared.cmd_opts.device_id is not None:
|
||||||
|
return f"cuda:{shared.cmd_opts.device_id}"
|
||||||
|
|
||||||
|
return "cuda"
|
||||||
|
|
||||||
|
|
||||||
def get_optimal_device():
|
def get_optimal_device():
|
||||||
if torch.cuda.is_available():
|
if torch.cuda.is_available():
|
||||||
from modules import shared
|
return torch.device(get_cuda_device_string())
|
||||||
|
|
||||||
device_id = shared.cmd_opts.device_id
|
|
||||||
|
|
||||||
if device_id is not None:
|
|
||||||
cuda_device = f"cuda:{device_id}"
|
|
||||||
return torch.device(cuda_device)
|
|
||||||
else:
|
|
||||||
return torch.device("cuda")
|
|
||||||
|
|
||||||
if has_mps():
|
if has_mps():
|
||||||
return torch.device("mps")
|
return torch.device("mps")
|
||||||
@ -44,16 +45,7 @@ def get_optimal_device():
|
|||||||
|
|
||||||
def torch_gc():
|
def torch_gc():
|
||||||
if torch.cuda.is_available():
|
if torch.cuda.is_available():
|
||||||
from modules import shared
|
with torch.cuda.device(get_cuda_device_string()):
|
||||||
|
|
||||||
device_id = shared.cmd_opts.device_id
|
|
||||||
|
|
||||||
if device_id is not None:
|
|
||||||
cuda_device = f"cuda:{device_id}"
|
|
||||||
else:
|
|
||||||
cuda_device = "cuda"
|
|
||||||
|
|
||||||
with torch.cuda.device(cuda_device):
|
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
torch.cuda.ipc_collect()
|
torch.cuda.ipc_collect()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user