(p: processing.StableDiffusionProcessing)
| 571 | |
| 572 | |
| 573 | def process_diffusers(p: processing.StableDiffusionProcessing): |
| 574 | results = [] |
| 575 | if debug: |
| 576 | log.trace(f'Process diffusers args: {vars(p)}') |
| 577 | if not validate_pipeline(p): |
| 578 | return results |
| 579 | |
| 580 | p = restore_state(p) |
| 581 | global orig_pipeline # pylint: disable=global-statement |
| 582 | orig_pipeline = shared.sd_model |
| 583 | |
| 584 | if shared.state.interrupted or shared.state.skipped: |
| 585 | shared.sd_model = orig_pipeline |
| 586 | return results |
| 587 | |
| 588 | # sanitize init_images |
| 589 | if hasattr(p, 'init_images') and not isinstance(getattr(p, 'init_images', []), list): |
| 590 | p.init_images = [p.init_images] |
| 591 | if hasattr(p, 'init_images') and isinstance(getattr(p, 'init_images', []), list): |
| 592 | p.init_images = [i for i in p.init_images if i is not None] |
| 593 | if len(getattr(p, 'init_images', [])) > 0: |
| 594 | while len(p.init_images) < len(p.prompts): |
| 595 | p.init_images.append(p.init_images[-1]) |
| 596 | |
| 597 | # pipeline type is set earlier in processing, but check for sanity |
| 598 | is_control = getattr(p, 'is_control', False) is True |
| 599 | has_images = len(getattr(p, 'init_images', [])) > 0 |
| 600 | if (sd_models.get_diffusers_task(shared.sd_model) != sd_models.DiffusersTaskType.TEXT_2_IMAGE) and (not has_images) and (not is_control): |
| 601 | shared.sd_model = sd_models.set_diffuser_pipe(shared.sd_model, sd_models.DiffusersTaskType.TEXT_2_IMAGE) # reset pipeline |
| 602 | if hasattr(shared.sd_model, 'unet') and hasattr(shared.sd_model.unet, 'config') and hasattr(shared.sd_model.unet.config, 'in_channels') and shared.sd_model.unet.config.in_channels == 9 and not is_control: |
| 603 | shared.sd_model = sd_models.set_diffuser_pipe(shared.sd_model, sd_models.DiffusersTaskType.INPAINTING) # force pipeline |
| 604 | if len(getattr(p, 'init_images', [])) == 0: |
| 605 | p.init_images = [convert.to_pil(torch.rand((3, getattr(p, 'height', 512), getattr(p, 'width', 512))))] |
| 606 | if not p.prompts: |
| 607 | p.prompts = p.all_prompts[p.iteration * p.batch_size:(p.iteration+1) * p.batch_size] |
| 608 | if not p.negative_prompts: |
| 609 | p.negative_prompts = p.all_negative_prompts[p.iteration * p.batch_size:(p.iteration+1) * p.batch_size] |
| 610 | |
| 611 | sd_models_compile.openvino_recompile_model(p, hires=False, refiner=False) # recompile if a parameter changes |
| 612 | |
| 613 | if hasattr(p, 'dummy'): |
| 614 | images = [Image.new(mode='RGB', size=(p.width, p.height))] |
| 615 | return images |
| 616 | if 'base' not in p.skip: |
| 617 | output = process_base(p) |
| 618 | else: |
| 619 | # images, _index = shared.history.selected |
| 620 | images = shared.history.last_latent |
| 621 | output = SimpleNamespace(images=images) if images is not None else None |
| 622 | |
| 623 | if (output is None or (hasattr(output, 'images') and len(output.images) == 0)) and has_images: |
| 624 | if output is not None: |
| 625 | log.debug('Processing: using input as base output') |
| 626 | output.images = p.init_images |
| 627 | |
| 628 | if shared.state.interrupted or shared.state.skipped: |
| 629 | shared.sd_model = orig_pipeline |
| 630 | return results |
no test coverage detected