From 7346ef1e7dc0168c86183c5b2efad2f4fac95991 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Tue, 23 May 2023 10:08:35 +0100 Subject: [PATCH] Fix unbound local error. Fixes `UnboundLocalError: local variable 'hypernetwork' referenced before assignment` error in finally block if the code in the try-catch raises an exception before `hypernetwork` has been set. --- patches/external_pr/ui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/patches/external_pr/ui.py b/patches/external_pr/ui.py index 1bdaebe..1264d26 100644 --- a/patches/external_pr/ui.py +++ b/patches/external_pr/ui.py @@ -39,7 +39,8 @@ def train_hypernetwork_ui(*args): shared.loaded_hypernetwork = initial_hypernetwork else: shared.loaded_hypernetworks = [] - del hypernetwork + if 'hypernetwork' in locals(): + del hypernetwork gc.collect() shared.sd_model.cond_stage_model.to(devices.device) shared.sd_model.first_stage_model.to(devices.device)