[Issue] Error when using adetailer with diffusers and DPM++ 2M Karras
An error is encountered when adetailer attempts to finalize changes to an image. This only occurs with the DPM++ 2M Karras sampler (has to be Karras). Only tested on diffusers/SDXL.
SDNext Version: app=sd.next updated=2023-11-07 hash=56cf80b8
Adetailer version 6b41b3db
Python version 3.10.11
Windows 11 23H2 OS build 22631.2506
Nvidia 4070 Driver Version 546.01
User extensions installed and enabled: https://github.com/AUTOMATIC1111/stable-diffusion-webui-wildcards https://github.com/Coyote-A/ultimate-upscale-for-automatic1111 https://github.com/hako-mikan/sd-webui-regional-prompter https://github.com/Bing-su/adetailer https://github.com/DominikDoom/a1111-sd-webui-tagcomplete
Steps to reproduce:
Prerequisites: diffusers, --medvram (CPU model offload), SDP with disable memory attention, adetailer extension
- Launch SDnext main
- Select any SDXL model
- Set size 1024*1024
- Select DPM++ 2M sampler
- Select Karras sampler option
- Enable Adetailer
- Select any Adetailer model
- Click generate (or ctrl+enter)
Notice that an error is encountered when adetailer processing completes
12:46:58-489748 INFO Browser session: client=127.0.0.1 agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
12:47:40-444385 DEBUG txt2img: id_task=task(0zm8cnblgli6gno)|prompt=girl in field,
|negative_prompt=|prompt_styles=[]|steps=20|sampler_index=10|latent_index=0|full_quality=True|r
estore_faces=False|tiling=False|n_iter=1|batch_size=1|cfg_scale=6|clip_skip=1|seed=-1.0|subseed
=-1.0|subseed_strength=0|seed_resize_from_h=0|seed_resize_from_w=0||height=1024|width=1024|enab
le_hr=False|denoising_strength=0.5|hr_scale=2|hr_upscaler=None|hr_force=False|hr_second_pass_st
eps=20|hr_resize_x=0|hr_resize_y=0|image_cfg_scale=6|diffusers_guidance_rescale=0.7|refiner_ste
ps=5|refiner_start=0.8|refiner_prompt=|refiner_negative=|override_settings_texts=[]
12:47:40-449385 INFO Applying hypertile: unet=256
12:47:40-720639 DEBUG Sampler: sampler="DPM++ 2M" config={'num_train_timesteps': 1000, 'beta_start': 0.00085,
'beta_end': 0.012, 'beta_schedule': 'scaled_linear', 'prediction_type': 'epsilon',
'thresholding': False, 'sample_max_value': 1.0, 'algorithm_type': 'sde-dpmsolver++',
'solver_type': 'midpoint', 'lower_order_final': True, 'use_karras_sigmas': True}
12:47:42-487943 DEBUG Diffuser pipeline: StableDiffusionXLPipeline task=DiffusersTaskType.TEXT_2_IMAGE
set={'prompt_embeds': torch.Size([1, 77, 2048]), 'pooled_prompt_embeds': torch.Size([1, 1280]),
'negative_prompt_embeds': torch.Size([1, 77, 2048]), 'negative_pooled_prompt_embeds':
torch.Size([1, 1280]), 'guidance_scale': 6, 'generator': device(type='cuda'), 'output_type':
'latent', 'num_inference_steps': 20, 'eta': 1.0, 'guidance_rescale': 0.7, 'denoising_end':
None, 'height': 1024, 'width': 1024, 'parser': 'Full parser'}
Progress 1.77it/s ████████▌ 25% 5/20 00:04 00:08 Base12:47:47-110253 DEBUG Load VAE decode approximate: model="models\VAE-approx\model.pt"
Progress 2.17it/s █████████████████████████████████ 100% 20/20 00:09 00:00 Base
12:47:58-305691 DEBUG VAE decode: name=baked dtype=torch.float32 upcast=True images=1 latents=torch.Size([1, 4, 128,
128]) time=4.939
0: 640x640 1 face, 9.0ms
Speed: 14.2ms preprocess, 9.0ms inference, 56.9ms postprocess per image at shape (1, 3, 640, 640)
12:47:59-211421 INFO Applying hypertile: unet=256
12:47:59-217694 DEBUG Pipeline class change: original=StableDiffusionXLPipeline
target=StableDiffusionXLInpaintPipeline
12:47:59-219698 DEBUG Sampler: sampler="DPM++ 2M" config={'num_train_timesteps': 1000, 'beta_start': 0.00085,
'beta_end': 0.012, 'beta_schedule': 'scaled_linear', 'prediction_type': 'epsilon',
'thresholding': False, 'sample_max_value': 1.0, 'algorithm_type': 'sde-dpmsolver++',
'solver_type': 'midpoint', 'lower_order_final': True, 'use_karras_sigmas': True}
12:47:59-283026 DEBUG Sampler: sampler="DPM++ 2M" config={'num_train_timesteps': 1000, 'beta_start': 0.00085,
'beta_end': 0.012, 'beta_schedule': 'scaled_linear', 'prediction_type': 'epsilon',
'thresholding': False, 'sample_max_value': 1.0, 'algorithm_type': 'sde-dpmsolver++',
'solver_type': 'midpoint', 'lower_order_final': True, 'use_karras_sigmas': True}
12:47:59-898487 DEBUG Diffuser pipeline: StableDiffusionXLInpaintPipeline task=DiffusersTaskType.INPAINTING
set={'prompt_embeds': torch.Size([1, 77, 2048]), 'pooled_prompt_embeds': torch.Size([1, 1280]),
'negative_prompt_embeds': torch.Size([1, 77, 2048]), 'negative_pooled_prompt_embeds':
torch.Size([1, 1280]), 'guidance_scale': 6, 'generator': device(type='cuda'), 'output_type':
'latent', 'num_inference_steps': 50, 'eta': 1.0, 'guidance_rescale': 0.7, 'denoising_start':
None, 'denoising_end': None, 'image': <class 'list'>, 'mask_image': <class 'PIL.Image.Image'>,
'strength': 0.4, 'height': 1024, 'width': 1024, 'parser': 'Full parser'}
12:48:00-467607 DEBUG Server alive=True jobs=1 requests=90 uptime=249 memory used=14.26 total=31.9 job="load" 0/0
Progress 2.36it/s ██████████████████████████▍ 80% 16/20 00:06 00:01 Base
12:48:08-961576 ERROR Running script postprocess image: extensions\adetailer\scripts\!adetailer.py: RuntimeError
╭───────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────╮
│ E:\automatic\modules\scripts.py:585 in postprocess_image │
│ │
│ 584 │ │ │ │ args = p.per_script_args.get(script.title(), p.script_args[script.args_f │
│ ❱ 585 │ │ │ │ script.postprocess_image(p, pp, *args) │
│ 586 │ │ │ except Exception as e: │
│ │
│ E:\automatic\extensions\adetailer\adetailer\traceback.py:159 in wrapper │
│ │
│ 158 │ │ │ │ error = RuntimeError(output) │
│ ❱ 159 │ │ │ raise error from None │
│ 160 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
RuntimeError:
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ System info │
│ ┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │
│ ┃ ┃ Value ┃ │
│ ┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │
│ │ Platform │ Windows-10-10.0.22631-SP0 │ │
│ │ Python │ 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] │ │
│ │ Version │ Unknown (too old or vladmandic) │ │
│ │ Commit │ Unknown │ │
│ │ Commandline │ ['launch.py', '--upgrade', '--use-cuda', '--debug'] │ │
│ │ Libraries │ {'torch': '2.1.0+cu121', 'torchvision': '0.16.0+cu121', 'ultralytics': '8.0.200', 'mediapipe': │ │
│ │ │ '0.10.7'} │ │
│ └─────────────┴────────────────────────────────────────────────────────────────────────────────────────────────┘ │
│ Inputs │
│ ┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │
│ ┃ ┃ Value ┃ │
│ ┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │
│ │ prompt │ girl in field, │ │
│ │ negative_prompt │ │ │
│ │ n_iter │ 1 │ │
│ │ batch_size │ 1 │ │
│ │ width │ 1024 │ │
│ │ height │ 1024 │ │
│ │ sampler_name │ DPM++ 2M │ │
│ │ enable_hr │ False │ │
│ │ hr_upscaler │ None │ │
│ │ checkpoint │ juggernautXL_version6Rundiffusion [1fe6c7ec54] │ │
│ │ vae │ Automatic │ │
│ │ unet │ ------ │ │
│ └─────────────────┴────────────────────────────────────────────────┘ │
│ ADetailer │
│ ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓ │
│ ┃ ┃ Value ┃ │
│ ┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩ │
│ │ version │ 23.11.0 │ │
│ │ ad_model │ face_yolov8n.pt │ │
│ │ ad_prompt │ │ │
│ │ ad_negative_prompt │ │ │
│ │ ad_controlnet_model │ None │ │
│ │ is_api │ False │ │
│ └─────────────────────┴─────────────────┘ │
│ ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │
│ │ E:\automatic\extensions\adetailer\adetailer\traceback.py:139 in wrapper │ │
│ │ │ │
│ │ 138 │ │ try: │ │
│ │ ❱ 139 │ │ │ return func(*args, **kwargs) │ │
│ │ 140 │ │ except Exception as e: │ │
│ │ │ │
│ │ E:\automatic\extensions\adetailer\scripts\!adetailer.py:745 in postprocess_image │ │
│ │ │ │
│ │ 744 │ │ │ │ │ continue │ │
│ │ ❱ 745 │ │ │ │ is_processed |= self._postprocess_image_inner(p, pp, args, n=n) │ │
│ │ 746 │ │
│ │ │ │
│ │ E:\automatic\extensions\adetailer\scripts\!adetailer.py:709 in _postprocess_image_inner │ │
│ │ │ │
│ │ 708 │ │ │ try: │ │
│ │ ❱ 709 │ │ │ │ processed = process_images(p2) │ │
│ │ 710 │ │ │ except NansException as e: │ │
│ │ │ │
│ │ E:\automatic\modules\processing.py:712 in process_images │ │
│ │ │ │
│ │ 711 │ │ │ with context_hypertile_vae(p), context_hypertile_unet(p): │ │
│ │ ❱ 712 │ │ │ │ res = process_images_inner(p) │ │
│ │ 713 │ finally: │ │
│ │ │ │
│ │ E:\automatic\modules\processing.py:859 in process_images_inner │ │
│ │ │ │
│ │ 858 │ │ │ │ from modules.processing_diffusers import process_diffusers │ │
│ │ ❱ 859 │ │ │ │ x_samples_ddim = process_diffusers(p, p.seeds, p.prompts, p.negative_pro │ │
│ │ 860 │ │ │ else: │ │
│ │ │ │
│ │ E:\automatic\modules\processing_diffusers.py:426 in process_diffusers │ │
│ │ │ │
│ │ 425 │ try: │ │
│ │ ❱ 426 │ │ output = shared.sd_model(**base_args) # pylint: disable=not-callable │ │
│ │ 427 │ except AssertionError as e: │ │
│ │ │ │
│ │ E:\automatic\venv\lib\site-packages\torch\utils\_contextlib.py:115 in decorate_context │ │
│ │ │ │
│ │ 114 │ │ with ctx_factory(): │ │
│ │ ❱ 115 │ │ │ return func(*args, **kwargs) │ │
│ │ 116 │ │
│ │ │ │
│ │ E:\automatic\venv\lib\site-packages\diffusers\pipelines\stable_diffusion_xl\pipeline_stable_diff │ │
│ │ usion_xl_inpaint.py:1511 in __call__ │ │
│ │ │ │
│ │ 1510 │ │ │ │ │ │ noise_timestep = timesteps[i + 1] │ │
│ │ ❱ 1511 │ │ │ │ │ │ init_latents_proper = self.scheduler.add_noise( │ │
│ │ 1512 │ │ │ │ │ │ │ init_latents_proper, noise, torch.tensor([noise_timestep]) │ │
│ │ │ │
│ │ E:\automatic\venv\lib\site-packages\diffusers\schedulers\scheduling_dpmsolver_multistep.py:888 │ │
│ │ in add_noise │ │
│ │ │ │
│ │ 887 │ │ │ │
│ │ ❱ 888 │ │ step_indices = [(schedule_timesteps == t).nonzero().item() for t in timesteps] │ │
│ │ 889 │ │
│ │ │ │
│ │ E:\automatic\venv\lib\site-packages\diffusers\schedulers\scheduling_dpmsolver_multistep.py:888 │ │
│ │ in <listcomp> │ │
│ │ │ │
│ │ 887 │ │ │ │
│ │ ❱ 888 │ │ step_indices = [(schedule_timesteps == t).nonzero().item() for t in timesteps] │ │
│ │ 889 │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ RuntimeError: a Tensor with 2 elements cannot be converted to Scalar │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
12:48:09-046299 DEBUG Saving: image="outputs\text\00913-juggernautXL_version6Rundiffusion-girl in field.jpg"
type=JPEG size=1024x1024
12:48:09-056812 INFO Processed: images=1 time=28.53 its=0.70 memory={'ram': {'used': 13.28, 'total': 31.9}, 'gpu':
{'used': 10.23, 'total': 11.99}, 'retries': 0, 'oom': 0}
Originally posted by @devils-shadow in https://github.com/vladmandic/automatic/issues/2461#issuecomment-1801698526
valid issue, but its really an edge case and solving it would result in almost no benefits (other than delaying other work). if someone contributes, great, otherwise this will remain as-is.
Seems to have been fixed on fba6a14c, closing ticket.