adieyal / sd-dynamic-prompts

A custom script for AUTOMATIC1111/stable-diffusion-webui to implement a tiny template language for random prompt generation
MIT License
2k stars 259 forks source link

list index out of range error with Jinja for loop after updating to latest version of web UI #620

Open TarAlacrin opened 1 year ago

TarAlacrin commented 1 year ago

I absolutely love this extension, use it a ton. Unfortunately I updated my Web UI to latest version so I could mess with SDXL and now when I try to use jinja for loops to generate a bunch of images it gives me this error after generating only one image:

*** Error completing request
*** Arguments: ('task(hwccalymedg599r)', '    {% for colour in ["red", "blue", "green"] %}\n        {% if colour == "red" %}\n            {% prompt %}I love {{ colour }} roses{% endprompt %}\n        {% else %}\n            {% prompt %}I hate {{ colour }} roses{% endprompt %}\n        {% endif %}\n    {% endfor %}', '', [], 20, 'Euler a', 1, 1, 7, 512, 512, False, 0.7, 2, 'Latent', 0, 0, 0, 'Use same checkpoint', 'Use same sampler', '', '', [], <gradio.routes.Request object at 0x0000019AD94B5720>, 0, False, '', 0.8, -1, False, -1, 0, 0, 0, True, False, 1, False, False, False, 1.1, 1.5, 100, 0.7, False, False, True, True, False, 0, 'Gustavosta/MagicPrompt-Stable-Diffusion', '', False, False, 'positive', 'comma', 0, False, False, '', 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, False, 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, False) {}
    Traceback (most recent call last):
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\call_queue.py", line 57, in f
        res = list(func(*args, **kwargs))
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\call_queue.py", line 36, in f
        res = func(*args, **kwargs)
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\txt2img.py", line 55, in txt2img
        processed = processing.process_images(p)
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\processing.py", line 732, in process_images
        res = process_images_inner(p)
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\processing.py", line 867, in process_images_inner
        samples_ddim = p.sample(conditioning=p.c, unconditional_conditioning=p.uc, seeds=p.seeds, subseeds=p.subseeds, subseed_strength=p.subseed_strength, prompts=p.prompts)
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\processing.py", line 1140, in sample
        samples = self.sampler.sample(self, x, conditioning, unconditional_conditioning, image_conditioning=self.txt2img_image_conditioning(x))
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 235, in sample
        samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args=self.sampler_extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\sd_samplers_common.py", line 261, in launch_sampling
        return func()
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 235, in <lambda>
        samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args=self.sampler_extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\venv\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
        return func(*args, **kwargs)
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\sampling.py", line 145, in sample_euler_ancestral
        denoised = model(x, sigmas[i] * s_in, **extra_args)
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\sd_samplers_cfg_denoiser.py", line 104, in forward
        uncond = prompt_parser.reconstruct_cond_batch(uncond, self.step)
      File "C:\Users\samdr\Downloads\stable-diffusion-webui\modules\prompt_parser.py", line 282, in reconstruct_cond_batch
        param = c[0][0].cond
    IndexError: list index out of range

---

This example was reproduced from a test prompt of:

    {% for colour in ["red", "blue", "green"] %}
        {% if colour == "red" %}
            {% prompt %}I love {{ colour }} roses{% endprompt %}
        {% else %}
            {% prompt %}I hate {{ colour }} roses{% endprompt %}
        {% endif %}
    {% endfor %}

and no negative prompt

The error persists even with a fresh pulldown of the repo in a separate directory, disabling all other extensions, and having deleted and redownloaded sd-dynamic-prompts fresh.

This is with the default settings (+enabling jinja). But I have also messed around with changing settings for a while to see if anything works. Notably I do not have "Limit Jinja prompts" in the settings enabled, although when I enabled it, it didn't fix the problem.

The only way to get it to work is to manually set the batch count to a high number, at which point it will run that many times before throwing the error. This is not how it worked before, where if the batch count was set to 1, it would run once for every prompt jinja generates.

Upon further investigation. If I ask jinja to write the full list of prompts to a text file it only actually generates [batch count] number of prompts. So something might be going wrong there.

Also in case this is necessary, according to the dynamic prompts dialogue this is my version: You are using version 2.16.3 of the WebUI extension, and the underlying dynamicprompts library is version 0.29.0.

From the bottom of the webUI page my version is 1.6.0,  •  python: 3.10.9  •  torch: 2.0.1+cu118  •  xformers: 0.0.20  •  gradio: 3.41.2  

turbidsoul commented 12 months ago

I have the same problem as you.

the environment is the same as yours

akx commented 12 months ago

Ah, that looks like a conflict between webui's built-in prompt parser and Jinja syntax (but with pretty confusing symptoms). I'll take a look.

This also doesn't happen if there's only one image generated in the batch...

Saviio commented 11 months ago

I have same issue, but I dont think this is a conflict betwwen builtin prompt parser and Jinja syntax, if so, it should throw error when the first batch instead of second batch.

jjopport commented 11 months ago

i have that issue too

*** Error completing request *** Arguments: ('task(2ysvuj350okj2gb)', 'high quality, masterpiece, detail hair, detail eyes, (__seasons__ park:1.2), A girl (wearing __costume__), burst shot,', 'nsfw, low quality, bed quality, out of frame,', [], 55, 18, False, False, 1, 1, 11.5, 2036247144.0, -1.0, 0, 0, 0, False, 768, 512, True, 0.32, 1.5, 'R-ESRGAN 4x+ Anime6B', 10, 0, 0, 0, '', '', ['RNG: CPU'], <gradio.routes.Request object at 0x000001C691B17310>, 0, False, {'ad_model': 'face_yolov8n.pt', 'ad_prompt': '', 'ad_negative_prompt': '', 'ad_confidence': 0.3, 'ad_mask_k_largest': 0, 'ad_mask_min_ratio': 0, 'ad_mask_max_ratio': 1, 'ad_x_offset': 0, 'ad_y_offset': 0, 'ad_dilate_erode': 4, 'ad_mask_merge_invert': 'None', 'ad_mask_blur': 4, 'ad_denoising_strength': 0.4, 'ad_inpaint_only_masked': True, 'ad_inpaint_only_masked_padding': 32, 'ad_use_inpaint_width_height': False, 'ad_inpaint_width': 512, 'ad_inpaint_height': 512, 'ad_use_steps': False, 'ad_steps': 28, 'ad_use_cfg_scale': False, 'ad_cfg_scale': 7, 'ad_use_checkpoint': False, 'ad_checkpoint': 'Use same checkpoint', 'ad_use_vae': False, 'ad_vae': 'Use same VAE', 'ad_use_sampler': False, 'ad_sampler': 'Euler a', 'ad_use_noise_multiplier': False, 'ad_noise_multiplier': 1, 'ad_use_clip_skip': False, 'ad_clip_skip': 1, 'ad_restore_face': False, 'ad_controlnet_model': 'None', 'ad_controlnet_module': 'inpaint_global_harmonious', 'ad_controlnet_weight': 1, 'ad_controlnet_guidance_start': 0, 'ad_controlnet_guidance_end': 1, 'is_api': ()}, {'ad_model': 'None', 'ad_prompt': '', 'ad_negative_prompt': '', 'ad_confidence': 0.3, 'ad_mask_k_largest': 0, 'ad_mask_min_ratio': 0, 'ad_mask_max_ratio': 1, 'ad_x_offset': 0, 'ad_y_offset': 0, 'ad_dilate_erode': 4, 'ad_mask_merge_invert': 'None', 'ad_mask_blur': 4, 'ad_denoising_strength': 0.4, 'ad_inpaint_only_masked': True, 'ad_inpaint_only_masked_padding': 32, 'ad_use_inpaint_width_height': False, 'ad_inpaint_width': 512, 'ad_inpaint_height': 512, 'ad_use_steps': False, 'ad_steps': 28, 'ad_use_cfg_scale': False, 'ad_cfg_scale': 7, 'ad_use_checkpoint': False, 'ad_checkpoint': 'Use same checkpoint', 'ad_use_vae': False, 'ad_vae': 'Use same VAE', 'ad_use_sampler': False, 'ad_sampler': 'Euler a', 'ad_use_noise_multiplier': False, 'ad_noise_multiplier': 1, 'ad_use_clip_skip': False, 'ad_clip_skip': 1, 'ad_restore_face': False, 'ad_controlnet_model': 'None', 'ad_controlnet_module': 'inpaint_global_harmonious', 'ad_controlnet_weight': 1, 'ad_controlnet_guidance_start': 0, 'ad_controlnet_guidance_end': 1, 'is_api': ()}, True, True, 3, False, False, False, 1.1, 1.5, 100, 0.7, False, False, True, False, False, 3, 'Gustavosta/MagicPrompt-Stable-Diffusion', '', <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x000001C691AE5330>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x000001C691AE6560>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x000001C691AE4DC0>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x000001C691AE6FB0>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x000001C69443FF70>, 'NONE:0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\nALL:1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1\nINS:1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0\nIND:1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0\nINALL:1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0\nMIDD:1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0\nOUTD:1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0\nOUTS:1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1\nOUTALL:1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1\nALL0.5:0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5', True, 0, 'values', '0,0.25,0.5,0.75,1', 'Block ID', 'IN05-OUT05', 'none', '', '0.5,1', 'BASE,IN00,IN01,IN02,IN03,IN04,IN05,IN06,IN07,IN08,IN09,IN10,IN11,M00,OUT00,OUT01,OUT02,OUT03,OUT04,OUT05,OUT06,OUT07,OUT08,OUT09,OUT10,OUT11', 1.0, 'black', '20', False, 'ATTNDEEPON:IN05-OUT05:attn:1\n\nATTNDEEPOFF:IN05-OUT05:attn:0\n\nPROJDEEPOFF:IN05-OUT05:proj:0\n\nXYZ:::1', False, False, False, False, 'Matrix', 'Columns', 'Mask', 'Prompt', '1,1', '0.2', False, False, False, 'Attention', False, '0', '0', '0.4', None, '0', '0', False, False, False, 0, None, [], 0, False, [], [], False, 0, 1, False, False, 0, None, [], -2, False, [], False, 0, None, None, False, False, 'positive', 'comma', 0, False, False, '', 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, None, None, False, None, None, False, None, None, False, None, None, False, None, None, False, 50, [], 30, '', 4, [], 1, '', '', '', '') {} Traceback (most recent call last): File "D:\sd\webui\modules\call_queue.py", line 58, in f res = list(func(*args, **kwargs)) File "D:\sd\webui\modules\call_queue.py", line 37, in f res = func(*args, **kwargs) File "D:\sd\webui\modules\txt2img.py", line 62, in txt2img processed = processing.process_images(p) File "D:\sd\webui\modules\processing.py", line 677, in process_images res = process_images_inner(p) File "D:\sd\webui\extensions\sd-webui-controlnet\scripts\batch_hijack.py", line 42, in processing_process_images_hijack return getattr(processing, '__controlnet_original_process_images_inner')(p, *args, **kwargs) File "D:\sd\webui\modules\processing.py", line 794, in process_images_inner samples_ddim = p.sample(conditioning=p.c, unconditional_conditioning=p.uc, seeds=p.seeds, subseeds=p.subseeds, subseed_strength=p.subseed_strength, prompts=p.prompts) File "D:\sd\webui\modules\processing.py", line 1054, in sample samples = self.sampler.sample(self, x, conditioning, unconditional_conditioning, image_conditioning=self.txt2img_image_conditioning(x)) File "D:\sd\webui\modules\sd_samplers_kdiffusion.py", line 464, in sample samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args={ File "D:\sd\webui\modules\sd_samplers_kdiffusion.py", line 303, in launch_sampling return func() File "D:\sd\webui\modules\sd_samplers_kdiffusion.py", line 464, in <lambda> samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args={ File "D:\sd\webui\venv\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "D:\sd\webui\repositories\k-diffusion\k_diffusion\sampling.py", line 626, in sample_dpmpp_2m_sde denoised = model(x, sigmas[i] * s_in, **extra_args) File "D:\sd\webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "D:\sd\webui\modules\sd_samplers_kdiffusion.py", line 121, in forward uncond = prompt_parser.reconstruct_cond_batch(uncond, self.step) File "D:\sd\webui\modules\prompt_parser.py", line 256, in reconstruct_cond_batch param = c[0][0].cond IndexError: list index out of range

Hezow commented 11 months ago

I have this problem too, any solution ?

jdahlstrom commented 10 months ago

A workaround is to enable Limit Jinja prompts in settings and then set batch count to something suitable (I haven't tested what happens if batch count is larger than the number of prompts).

ansonxing23 commented 9 months ago

same problem, still waiting for the solutions

ansonxing23 commented 9 months ago

same problem, still waiting for the solutions

after tested on previous version, this won`t happen on 2.16.0

OscarPindaro commented 9 months ago

A workaround is to enable Limit Jinja prompts in settings and then set batch count to something suitable (I haven't tested what happens if batch count is larger than the number of prompts).

I can confirm that limiting Jinja prompt solves the issue. Maybe try to set this as the default option for a temporary fix?