hitmare-patch-1 #2

Merged
Hitmare merged 7 commits from hitmare-patch-1 into main 2023-12-23 15:10:34 +00:00
1 changed files with 107 additions and 101 deletions
Showing only changes of commit cc119297ba - Show all commits

View File

@ -1,12 +1,11 @@
import torch.nn
import ldm.modules.diffusionmodules.openaimodel
import time
from modules import script_callbacks, shared, devices
unet_options = []
current_unet_option = None
current_unet = None
original_forward = None # not used, only left temporarily for compatibility
def list_unets():
new_unets = script_callbacks.list_unets_callback()
@ -84,18 +83,25 @@ class SdUnet(torch.nn.Module):
pass
def UNetModel_forward(self, x, timesteps=None, context=None, *args, **kwargs):
try:
if current_unet is not None and shared.current_prompt != shared.skip_unet_prompt:
if '[TRT]' in shared.opts.sd_unet and '<lora:' in shared.current_prompt:
raise Exception('LoRA unsupported in TRT UNet')
f = current_unet.forward(x, timesteps, context, *args, **kwargs)
return f
except Exception as e:
start = time.time()
print('[UNet] Skipping TRT UNet for this request:', e, '-', shared.current_prompt)
shared.sd_model.model.diffusion_model.to(devices.device)
shared.skip_unet_prompt = shared.current_prompt
print('[UNet] Used', time.time() - start, 'seconds')
def create_unet_forward(original_forward):
def UNetModel_forward(self, x, timesteps=None, context=None, *args, **kwargs):
if current_unet is not None:
return current_unet.forward(x, timesteps, context, *args, **kwargs)
try:
if current_unet is not None and shared.current_prompt != shared.skip_unet_prompt:
if '[TRT]' in shared.opts.sd_unet and '<lora:' in shared.current_prompt:
raise Exception('LoRA unsupported in TRT UNet')
f = current_unet.forward(x, timesteps, context, *args, **kwargs)
return f
except Exception as e:
start = time.time()
print('[UNet] Skipping TRT UNet for this request:', e, '-', shared.current_prompt)
shared.sd_model.model.diffusion_model.to(devices.device)
shared.skip_unet_prompt = shared.current_prompt
print('[UNet] Used', time.time() - start, 'seconds')
return original_forward(self, x, timesteps, context, *args, **kwargs)
return UNetModel_forward
return ldm.modules.diffusionmodules.openaimodel.copy_of_UNetModel_forward_for_webui(self, x, timesteps, context, *args, **kwargs)