From 149a4de3f2c0c20d0ab788f7153f29942b4cfe64 Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Fri, 3 Feb 2023 03:55:50 -0500 Subject: [PATCH] Fix potential issue if exception happens when patching model. --- nodes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nodes.py b/nodes.py index 37952e31..1b7afa10 100644 --- a/nodes.py +++ b/nodes.py @@ -289,6 +289,7 @@ def common_ksampler(device, model, seed, steps, cfg, sampler_name, scheduler, po else: noise = torch.randn(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, generator=torch.manual_seed(seed), device="cpu") + real_model = None try: real_model = model.patch_model() real_model.to(device) @@ -322,7 +323,8 @@ def common_ksampler(device, model, seed, steps, cfg, sampler_name, scheduler, po real_model.cpu() model.unpatch_model() except Exception as e: - real_model.cpu() + if real_model is not None: + real_model.cpu() model.unpatch_model() raise e