Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Input shape must be divisible by 64 in both dimensions. Hires Fix error. #15

Closed
AndreyRGW opened this issue Oct 17, 2023 · 19 comments
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@AndreyRGW
Copy link

100%|██████████████████████████████████████████████████████████████████████████████████| 36/36 [00:04<00:00,  7.89it/s]
  0%|                                                                                            | 0/8 [00:00<?, ?it/s]
*** Error completing request
*** Arguments: ('task(o6gp9seri8repp8)', 'RAW photo, Fujifilm XT3, lighthouse, <lora:epiCRealLife:1>', 'deformed, oversaturated, overcontrasted, asian, chinese, cartoon, cgi, render, illustration, painting, drawing, statue, anime, 2d,', [], 36, 'DPM++ 3M SDE Karras', 1, 1, 10, 512, 768, True, 0.5, 1.65, '4xLSDIR', 8, 0, 0, 'Use same checkpoint', 'DPM++ 2M Karras', '', '', [], <gradio.routes.Request object at 0x0000000F8005F5B0>, 0, False, '', 0.8, 3952135377, False, -1, 0, 0, 0, 0, False, 1, False, 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': 'DPM++ 2M Karras', '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': 'DPM++ 2M Karras', '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': ()}, False, 1448, 0, 8, 'DF2K', '4x-UniScaleV2_Sharp', 0.3, 0.1, '', '', 2, 'Noise sync (sharp)', 0.3, 0.05, 0, 'DPM++ 3M SDE', False, 'MultiDiffusion', False, True, 1024, 1024, 96, 96, 48, 4, 'None', 2, False, 10, 1, 1, 64, False, False, False, False, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 2048, 128, True, True, True, False, False, 7, 100, 'Constant', 0, 'Constant', 0, 4, True, 'MEAN', 'AD', 1, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x00000000670B9CC0>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x00000000670B8D00>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x00000000670B9BA0>, False, '', 0.5, True, False, '', 'Lerp', False, [], [], False, 0, 0.8, 0, 0.8, 0.5, False, False, 0.5, 8192, -1.0, None, '', None, True, False, False, False, False, False, 0, 0, '0', 0, False, True, 0, 'Portrait of a [gender]', 'blurry', 20, ['DPM++ 2M Karras'], '', None, 1, 1, None, False, False, False, 1, 0, 'Portrait of a [gender]', 'blurry', 20, ['DPM++ 2M Karras'], '', None, '', None, True, False, False, False, False, False, 0, 0, '0', 0, False, True, 0, 'Portrait of a [gender]', 'blurry', 20, ['DPM++ 2M Karras'], '', None, 1, 1, None, False, False, False, 1, 0, 'Portrait of a [gender]', 'blurry', 20, ['DPM++ 2M Karras'], '', None, '', None, True, False, False, False, False, False, 0, 0, '0', 0, False, True, 0, 'Portrait of a [gender]', 'blurry', 20, ['DPM++ 2M Karras'], '', None, 1, 1, None, False, False, False, 1, 0, 'Portrait of a [gender]', 'blurry', 20, ['DPM++ 2M Karras'], '', 'CodeFormer', 1, 1, None, 1, 1, ['After Upscaling/Before Restore Face'], 0, 'Portrait of a [gender]', 'blurry', 20, ['DPM++ 2M Karras'], '', True, 0, 1, 0, 1.2, 0.9, 0, 0.5, 0, 1, 1.4, 0.2, 0, 0.5, 0, 1, 1, 1, 0, 0.5, 0, 1, 0, None, False, '0', '0', 'inswapper_128.onnx', 'CodeFormer', 1, True, 'None', 1, 1, False, True, 1, 0, 0, False, 0.5, False, False, 0, 1, 1, 0, 0, 0, 0, False, 'Straight Abs.', 'Flat', False, 0.75, 1, False, False, 3, 0, False, False, 0, False, False, False, 'positive', 'comma', 0, False, False, '', 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, False, None, None, False, None, None, False, None, None, False, 50) {}
    Traceback (most recent call last):
      File "F:\WBC\automatic1111_dev\modules\call_queue.py", line 57, in f
        res = list(func(*args, **kwargs))
      File "F:\WBC\automatic1111_dev\modules\call_queue.py", line 36, in f
        res = func(*args, **kwargs)
      File "F:\WBC\automatic1111_dev\modules\txt2img.py", line 55, in txt2img
        processed = processing.process_images(p)
      File "F:\WBC\automatic1111_dev\modules\processing.py", line 734, in process_images
        res = process_images_inner(p)
      File "F:\WBC\automatic1111_dev\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 "F:\WBC\automatic1111_dev\modules\processing.py", line 869, 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 "F:\WBC\automatic1111_dev\modules\processing.py", line 1161, in sample
        return self.sample_hr_pass(samples, decoded_samples, seeds, subseeds, subseed_strength, prompts)
      File "F:\WBC\automatic1111_dev\modules\processing.py", line 1247, in sample_hr_pass
        samples = self.sampler.sample_img2img(self, samples, noise, self.hr_c, self.hr_uc, steps=self.hr_second_pass_steps or self.steps, image_conditioning=image_conditioning)
      File "F:\WBC\automatic1111_dev\modules\sd_samplers_kdiffusion.py", line 188, in sample_img2img
        samples = self.launch_sampling(t_enc + 1, lambda: self.func(self.model_wrap_cfg, xi, extra_args=self.sampler_extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))
      File "F:\WBC\automatic1111_dev\modules\sd_samplers_common.py", line 261, in launch_sampling
        return func()
      File "F:\WBC\automatic1111_dev\modules\sd_samplers_kdiffusion.py", line 188, in <lambda>
        samples = self.launch_sampling(t_enc + 1, lambda: self.func(self.model_wrap_cfg, xi, extra_args=self.sampler_extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))
      File "F:\WBC\automatic1111_dev\venv\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
        return func(*args, **kwargs)
      File "F:\WBC\automatic1111_dev\repositories\k-diffusion\k_diffusion\sampling.py", line 594, in sample_dpmpp_2m
        denoised = model(x, sigmas[i] * s_in, **extra_args)
      File "F:\WBC\automatic1111_dev\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "F:\WBC\automatic1111_dev\modules\sd_samplers_cfg_denoiser.py", line 169, in forward
        x_out = self.inner_model(x_in, sigma_in, cond=make_condition_dict(cond_in, image_cond_in))
      File "F:\WBC\automatic1111_dev\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "F:\WBC\automatic1111_dev\repositories\k-diffusion\k_diffusion\external.py", line 112, in forward
        eps = self.get_eps(input * c_in, self.sigma_to_t(sigma), **kwargs)
      File "F:\WBC\automatic1111_dev\repositories\k-diffusion\k_diffusion\external.py", line 138, in get_eps
        return self.inner_model.apply_model(*args, **kwargs)
      File "F:\WBC\automatic1111_dev\modules\sd_hijack_utils.py", line 17, in <lambda>
        setattr(resolved_obj, func_path[-1], lambda *args, **kwargs: self(*args, **kwargs))
      File "F:\WBC\automatic1111_dev\modules\sd_hijack_utils.py", line 28, in __call__
        return self.__orig_func(*args, **kwargs)
      File "F:\WBC\automatic1111_dev\repositories\stable-diffusion-stability-ai\ldm\models\diffusion\ddpm.py", line 858, in apply_model
        x_recon = self.model(x_noisy, t, **cond)
      File "F:\WBC\automatic1111_dev\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "F:\WBC\automatic1111_dev\repositories\stable-diffusion-stability-ai\ldm\models\diffusion\ddpm.py", line 1335, in forward
        out = self.diffusion_model(x, t, context=cc)
      File "F:\WBC\automatic1111_dev\venv\lib\site-packages\torch\nn\modules\module.py", line 1538, in _call_impl
        result = forward_call(*args, **kwargs)
      File "F:\WBC\automatic1111_dev\modules\sd_unet.py", line 89, in UNetModel_forward
        return current_unet.forward(x, timesteps, context, *args, **kwargs)
      File "F:\WBC\automatic1111_dev\extensions\Stable-Diffusion-WebUI-TensorRT\scripts\trt.py", line 84, in forward
        raise ValueError(
    ValueError: Input shape must be divisible by 64 in both dimensions.

---

Error when using hires fix.

@AndreyRGW AndreyRGW changed the title [BUG] Input shape must be divisible by 64 in both dimensions. [BUG] Input shape must be divisible by 64 in both dimensions. Hires Fix error. Oct 17, 2023
@contentis
Copy link
Collaborator

Currently, there is a limitation: the resolution needs to be a multiple of 64. Hires fix is something I wasn't aware of when I developed this. And probably requires some work to run performant.
From the error, I assume that both the low-res and high-res resolutions need to be divisible by 64. Is that the case?

@AndreyRGW
Copy link
Author

Currently, there is a limitation: the resolution needs to be a multiple of 64. Hires fix is something I wasn't aware of when I developed this. And probably requires some work to run performant.
From the error, I assume that both the low-res and high-res resolutions need to be divisible by 64. Is that the case?

Yes it is.

@contentis contentis added documentation Improvements or additions to documentation bug Something isn't working labels Oct 18, 2023
@contentis
Copy link
Collaborator

Can you post your engine config and the hires.fix settings you have used?

@contentis contentis self-assigned this Oct 18, 2023
@AndreyRGW
Copy link
Author

Can you post your engine config and the hires.fix settings you have used?

Okay, but I can post only after 3pm GMT 0

@AndreyRGW
Copy link
Author

AndreyRGW commented Oct 18, 2023

Can you post your engine config and the hires.fix settings you have used?

Although, I remember the settings of my hires.fix: 768x512 base resolution, upscale by 1,65x, upscaler - 4XLSDIR, denoising strength- 0,5

@contentis
Copy link
Collaborator

I'm not sure how SD Webui handles decimals but using the info provided: 768x512 * 1.65 = 1267.2x844.8
No matter how this will be rounded, the upscaled resolution is not divisible by 64.

@AndreyRGW
Copy link
Author

I'm not sure how SD Webui handles decimals but using the info provided: 768x512 * 1.65 = 1267.2x844.8
No matter how this will be rounded, the upscaled resolution is not divisible by 64.

As far as I remember, these values ​​are rounded to 1267x845 (but I could be wrong, I’ll give more accurate information when I’m home)

@Asinin3
Copy link

Asinin3 commented Oct 18, 2023

Ran into this as well even when highres fix was set to 1 (aka not to upscale) and using 712x712. Had to drop it down to 640x640.

@contentis
Copy link
Collaborator

712 isn't divisible by 64, either. Can you try running 512 (low res) with a 1.5x scale factor?

@Asinin3
Copy link

Asinin3 commented Oct 18, 2023

I know 712 isn't divisible by 64, but when you wrote:

Currently, there is a limitation: the resolution needs to be a multiple of 64. Hires fix is something I wasn't aware of when I developed this

I was under the impression that it only needed to be divisible when using the Highres fix. But it happens even when Highres fix isn't being used.

If I try 640x640 it works fine when not using HighRes fix, but if I do use 2x it gives this error:
ValueError: No valid profile found. Please go to the TensorRT tab and generate an engine with the necessary profile. If using hires.fix, you need an engine for both the base and upscaled resolutions. Otherwise, use the default (torch) U-Net.
If I try 512x512 with 1.5x scale though.. it works.

@Asinin3
Copy link

Asinin3 commented Oct 18, 2023

Actually, the 640x640 + 2x scale error might be caused by max-width/height in the tensorrt engine not being set to 1280x1280. Give me a moment while I check that.

@contentis
Copy link
Collaborator

That is most likely the case. I tried adding some more information in the readme on the hot_fix branch.

If you don't mind I would appreciate it if you could take a look and let me know if that does a better job at explaining it.

@Asinin3
Copy link

Asinin3 commented Oct 18, 2023

Actually, the 640x640 + 2x scale error might be caused by max-width/height in the tensorrt engine not being set to 1280x1280. Give me a moment while I check that.

Yeah, that was the problem. Max height/width needs to account for whatever the output is, even if its being scaled after-the-fact. If we have to use resolutions divisible by 64 even without the highres fix/scaler, then the default profiles should probably be updated to resolutions that are divisible by 64 (dynamic profile could be 512 -1024 or 512 - 640 for instance.

I like the readme change, just think a note about requiring divisible by 64 resolutions would be good (or better yet, make the slider that sets the min/max res only be able to set to resolutions that are divisible by 64?

@contentis
Copy link
Collaborator

or better yet, make the slider that sets the min/max res only be able to set to resolutions that are divisible by 64?

Wait, isn't that the case? The steps size should be set to 64 in the UI. But good idea to add the 64x requirement to the readme.

@Asinin3
Copy link

Asinin3 commented Oct 18, 2023

Wait, isn't that the case? The steps size should be set to 64 in the UI

Sorry, you're right. If it could do the same for the res slider on the generation tab that would be neat.

@contentis
Copy link
Collaborator

We cannot modify the behaviour in the main UI. Raising a ValueError is the best I can do at the moment.

@AndreyRGW
Copy link
Author

Can you post your engine config and the hires.fix settings you have used?

image image

@contentis
Copy link
Collaborator

As mentioned earlier, using a scale factor of 1.65 will result in a non-mulitple-of 64 resolution. If you set it to 1.5x it should work just fine with your set-up

@contentis
Copy link
Collaborator

Closing as this is expected behaviour. Feel free to reopen if you encounter further issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants