MCPcopy Index your code
hub / github.com/vladmandic/sdnext / process_decode

Function process_decode

modules/processing_diffusers.py:470–527  ·  view source on GitHub ↗
(p: processing.StableDiffusionProcessing, output)

Source from the content-addressed store, hash-verified

468
469
470def process_decode(p: processing.StableDiffusionProcessing, output):
471 shared.sd_model = sd_models.apply_balanced_offload(shared.sd_model, exclude=['vae'])
472 if output is not None:
473 if hasattr(output, 'bytes') and output.bytes is not None:
474 log.debug(f'Generated: bytes={len(output.bytes)}')
475 return output
476 audio = getattr(output, 'audio', None)
477 if not hasattr(output, 'images') and hasattr(output, 'frames'):
478 log.debug(f'Generated: frames={len(output.frames[0])}')
479 output.images = output.frames[0]
480 if output.images is not None and len(output.images) > 0 and isinstance(output.images[0], Image.Image):
481 return attach_audio(output.images, audio)
482 model = shared.sd_model if not is_refiner_enabled(p) else shared.sd_refiner
483 if not hasattr(model, 'vae'):
484 if hasattr(model, 'pipe') and hasattr(model.pipe, 'vae'):
485 model = model.pipe
486 if (hasattr(model, "vae") or hasattr(model, "vqgan")) and (output.images is not None) and (len(output.images) > 0):
487 if p.hr_resize_mode > 0 and (p.hr_upscaler != 'None' or p.hr_resize_mode == 5):
488 width = max(getattr(p, 'width', 0), getattr(p, 'hr_upscale_to_x', 0))
489 height = max(getattr(p, 'height', 0), getattr(p, 'hr_upscale_to_y', 0))
490 else:
491 width = getattr(p, 'width', 0)
492 height = getattr(p, 'height', 0)
493 frames = p.task_args.get('num_frames', None) or getattr(p, 'frames', None)
494 if isinstance(output.images, list):
495 results = []
496 for i in range(len(output.images)):
497 result_batch = processing_vae.vae_decode(
498 latents = output.images[i],
499 model = model,
500 vae_type = p.vae_type,
501 width = width,
502 height = height,
503 frames = frames,
504 )
505 for result in list(result_batch):
506 results.append(result)
507 else:
508 results = processing_vae.vae_decode(
509 latents = output.images,
510 model = model,
511 vae_type = p.vae_type,
512 width = width,
513 height = height,
514 frames = frames,
515 )
516 if not isinstance(results, list):
517 results = list(results)
518 elif hasattr(output, 'images'):
519 results = output.images
520 else:
521 log.warning('Processing: no results')
522 results = []
523 else:
524 log.warning('Processing: no results')
525 audio = None
526 results = []
527 return attach_audio(results, audio)

Callers 1

process_diffusersFunction · 0.85

Calls 4

is_refiner_enabledFunction · 0.90
attach_audioFunction · 0.85
getMethod · 0.45
vae_decodeMethod · 0.45

Tested by

no test coverage detected