Merge pull request #5095 from mlmcgoogan/master

torch.cuda.empty_cache() defaults to cuda:0 device unless explicitly …
This commit is contained in:
AUTOMATIC1111 2022-11-27 12:56:02 +03:00 committed by GitHub
commit 997ac57020
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,8 +44,18 @@ def get_optimal_device():
def torch_gc():
if torch.cuda.is_available():
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
from modules import shared
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.ipc_collect()
def enable_tf32():