fix vae decode for backend original

This commit is contained in:
Vladimir Mandic
2024-09-02 08:23:40 -04:00
parent 7f2e30576d
commit 045b24c060
5 changed files with 25 additions and 3 deletions
+2 -1
View File
@@ -8,5 +8,6 @@
"./repositories/taming"
],
"python.analysis.typeCheckingMode": "off",
"editor.formatOnSave": false
"editor.formatOnSave": false,
"python.REPL.enableREPLSmartSend": false
}
+3
View File
@@ -38,7 +38,10 @@ Other improvements:
improves quality of the flow-matching samplers
- t5 support manually downloaded models
applies to all models that use t5 transformer
Fixes:
- fix handling of model configs if offline config is not available
- fix vae decode in backend original
Work-in-progress:
- flux controlnet support: (*1)
+2 -1
View File
@@ -196,7 +196,8 @@ def decode_first_stage(model, x, full_quality=True):
try:
if full_quality:
if hasattr(model, 'decode_first_stage'):
x_sample = model.decode_first_stage(x) * 0.5 + 0.5
# x_sample = model.decode_first_stage(x) * 0.5 + 0.5
x_sample = model.decode_first_stage(x)
elif hasattr(model, 'vae'):
x_sample = processing_vae.vae_decode(latents=x, model=model, output_type='np', full_quality=full_quality)
else:
-1
View File
@@ -265,7 +265,6 @@ class EmbeddingsWithFixes(torch.nn.Module):
def forward(self, input_ids):
batch_fixes = self.embeddings.fixes
self.embeddings.fixes = None
inputs_embeds = self.wrapped(input_ids)
if batch_fixes is None or len(batch_fixes) == 0 or max([len(x) for x in batch_fixes]) == 0:
+18
View File
@@ -737,6 +737,9 @@ def set_diffuser_options(sd_model, vae = None, op: str = 'model', offload=True):
set_diffuser_offload(sd_model, op)
def set_diffuser_offload(sd_model, op: str = 'model'):
if not shared.native:
shared.log.warning('Attempting to use offload with backend=original')
return
if sd_model is None:
shared.log.warning(f'{op} is not loaded')
return
@@ -837,6 +840,8 @@ def apply_balanced_offload(sd_model):
shared.log.error(f'Balanced offload: module={module_name} {e}')
devices.torch_gc(fast=True)
if not shared.native:
return
apply_balanced_offload_to_module(sd_model)
if hasattr(sd_model, "prior_pipe"):
apply_balanced_offload_to_module(sd_model.prior_pipe)
@@ -859,6 +864,19 @@ def normalize_device(device):
def move_model(model, device=None, force=False):
if model is None or device is None:
return
if not shared.native:
if type(model).__name__ == 'LatentDiffusion':
model = model.to(device)
if hasattr(model, 'model'):
model.model = model.model.to(device)
if hasattr(model, 'first_stage_model'):
model.first_stage_model = model.first_stage_model.to(device)
if hasattr(model, 'cond_stage_model'):
model.cond_stage_model = model.cond_stage_model.to(device)
devices.torch_gc()
return
if getattr(model, 'vae', None) is not None and get_diffusers_task(model) != DiffusersTaskType.TEXT_2_IMAGE:
if device == devices.device and model.vae.device.type != "meta": # force vae back to gpu if not in txt2img mode
model.vae.to(device)