mcmonkeyprojects / sd-dynamic-thresholding Goto Github PK
View Code? Open in Web Editor NEWDynamic Thresholding (CFG Scale Fix) for Stable Diffusion (StableSwarmUI, ComfyUI, and Auto WebUI)
License: MIT License
Dynamic Thresholding (CFG Scale Fix) for Stable Diffusion (StableSwarmUI, ComfyUI, and Auto WebUI)
License: MIT License
extension fails to load
currently using colab
Error loading script: dynamic_thresholding.py Traceback (most recent call last): File "/content/stable-diffusion-webui/modules/scripts.py", line 229, in load_scripts script_module = script_loading.load_module(scriptfile.path) File "/content/stable-diffusion-webui/modules/script_loading.py", line 11, in load_module module_spec.loader.exec_module(module) File "<frozen importlib._bootstrap_external>", line 850, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/content/stable-diffusion-webui/extensions/sd-dynamic-thresholding/scripts/dynamic_thresholding.py", line 15, in <module> import dynthres_unipc, dynthres_core File "/content/stable-diffusion-webui/extensions/sd-dynamic-thresholding/dynthres_unipc.py", line 6, in <module> from modules.models.diffusion import uni_pc ImportError: cannot import name 'uni_pc' from 'modules.models.diffusion' (unknown location)
I installed it using webUI's built in extensions tab and it isn't showing up even after restarting.
I just installed the extension, updated and relaunched the webui. I received this error each time I tried to enable Dynamic Thresholding:
Error completing request
Arguments: ('task(rsa3qrt092fsaik)', 'picture of a cat eating a pizza, yellow eyes, bushy tail, stripes, grey and white, pepperoni on the pizza', 'easynegative', [], 88, 15, False, False, 1, 1, 20, -1.0, -1.0, 0, 0, 0, False, 768, 512, True, 0.6, 2, 'Lanczos', 30, 0, 0, [], 0, False, '', 0, True, 8, 99, 'Half Cosine Up', 4, 'Half Cosine Up', 3.5, 4, False, False, 'LoRA', 'None', 0, 0, 'LoRA', 'None', 0, 0, 'LoRA', 'None', 0, 0, 'LoRA', 'None', 0, 0, 'LoRA', 'None', 0, 0, 'Refresh models', False, False, 'none', 'None', 1, None, False, 'Scale to Fit (Inner Fit)', False, False, 64, 64, 64, 0, 1, False, False, 'none', 'None', 1, None, False, 'Scale to Fit (Inner Fit)', False, False, 64, 64, 64, 0, 1, False, False, 'none', 'None', 1, None, False, 'Scale to Fit (Inner Fit)', False, False, 64, 64, 64, 0, 1, False, False, False, 3, 0, False, False, 0, False, False, False, False, False, '1:1,1:2,1:2', '0:0,0:0,0:1', '0.2,0.8,0.8', 20, False, False, 'positive', 'comma', 0, False, False, '', 1, '', 0, '', 0, '', True, False, False, False, 0, None, None, None, 50) {}
Traceback (most recent call last):
File "K:\stable-diffusion\stable-diffusion-webui\modules\call_queue.py", line 56, in f
res = list(func(*args, **kwargs))
File "K:\stable-diffusion\stable-diffusion-webui\modules\call_queue.py", line 37, in f
res = func(*args, **kwargs)
File "K:\stable-diffusion\stable-diffusion-webui\modules\txt2img.py", line 56, in txt2img
processed = process_images(p)
File "K:\stable-diffusion\stable-diffusion-webui\modules\processing.py", line 486, in process_images
res = process_images_inner(p)
File "K:\stable-diffusion\stable-diffusion-webui\modules\processing.py", line 636, in process_images_inner
samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts)
File "K:\stable-diffusion\stable-diffusion-webui\modules\processing.py", line 836, in sample
samples = self.sampler.sample(self, x, conditioning, unconditional_conditioning, image_conditioning=self.txt2img_image_conditioning(x))
File "K:\stable-diffusion\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 351, in sample
samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args={
File "K:\stable-diffusion\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 227, in launch_sampling
return func()
File "K:\stable-diffusion\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 351, in
samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args={
File "K:\stable-diffusion\stable-diffusion-webui\venv\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "K:\stable-diffusion\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\sampling.py", line 594, in sample_dpmpp_2m
denoised = model(x, sigmas[i] * s_in, **extra_args)
File "K:\stable-diffusion\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "K:\stable-diffusion\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 153, in forward
denoised = self.combine_denoised(x_out, conds_list, uncond, cond_scale)
File "K:\stable-diffusion\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 259, in combine_denoised
return self.main_class.dynthresh(x_out[:-uncond.shape[0]], denoised_uncond, cond_scale, weights)
File "K:\stable-diffusion\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 164, in dynthresh
mimicScale = self.interpretScale(self.mimic_scale, self.mimic_mode, self.mimic_scale_min)
File "K:\stable-diffusion\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 153, in interpretScale
scale *= 1.0 - math.cos((self.step / max))
AttributeError: 'DynThresh' object has no attribute 'step'
If an output that used this extension was sent to img2img/inpaint, could it stay enabled? Currently it doesn't.
How to create Lora or a model to work with the dynamic thresholding? Does it need to be a specific type or setting? Some Loras work but some overbake quickly, is there an underlying reason for that? If there is, can you please add info to the main repository readme? Great extension btw.
Can you please consider changing the interface to have the whole thing nested in a dropdown instead of how it currently is?
example: (I have no idea how to actually implement this, I just used inspect to show what I mean)
This is how it currently is. (You can make it smaller by closing the adv options dropdown)
How I think it should look:
The second one looks much cleaner imo and follows the same format as all the other extensions.
Thanks.
p.s I'm sorry, I don't know how to assign a label
Hi there. I've just installed your extension using both methods of installation. Available and from URL (https://github.com/mcmonkeyprojects/sd-dynamic-thresholding). In both cases, I get the same error. Since I have the coding ability of an inebriated chimpanzee, I thought I'd ask for help here. Any clue as to what my issue is? Thank you for your time and effort.
Error loading script: dynamic_thresholding.py
Traceback (most recent call last):
File "C:\Users\Snow\stable-diffusion-webui\modules\scripts.py", line 229, in load_scripts
script_module = script_loading.load_module(scriptfile.path)
File "C:\Users\Snow\stable-diffusion-webui\modules\script_loading.py", line 11, in load_module
module_spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\Snow\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 15, in <module>
import dynthres_unipc, dynthres_core
File "C:\Users\Snow\stable-diffusion-webui\extensions\sd-dynamic-thresholding\dynthres_unipc.py", line 6, in <module>
from modules.models.diffusion import uni_pc
ImportError: cannot import name 'uni_pc' from 'modules.models.diffusion' (unknown location)
Power Scheduler Value not being saved into png info.
Hi, I would like to use this in diffusers, but I lack the overall understanding of the code. Could you implement this or teach me the code so I could do so myself?
Thanks in advance :)
is it possible to implement it in ComfyUI?
I tried but I didn't have the skills to do it
Steps: 20, Sampler: DPM++ 2M Karras, CFG scale: 30, Seed: 1615917251, Size: 544x800, Model hash: 51710d9efa, Model: 0.7(Si28-negz)+0.3(dreamlike1.0), Denoising strength: 0.65, Hires upscale: 1.5, Hires steps: 24, Hires upscaler: Latent (bicubic antialiased), Dynamic thresholding enabled: True, Mimic scale: 13.5, Threshold percentile: 98.7, Mimic mode: Half Cosine Up, Mimic scale minimum: 6, CFG mode: Half Cosine Up, CFG scale minimum: 9
Power Scheduler Value is not stored in image metadata, so it is not restored when using PNG info tab, instead is set to a default value of 4.
I'm using webui-directml variation of webui since I'm using rx 6000 gpu on Windows. I didn't notice this issue in other samplers.
Traceback (most recent call last):
File "X:\stable-diffusion-webui-directml\modules\call_queue.py", line 56, in f
res = list(func(*args, **kwargs))
File "X:\stable-diffusion-webui-directml\modules\call_queue.py", line 37, in f
res = func(*args, **kwargs)
File "X:\stable-diffusion-webui-directml\modules\txt2img.py", line 56, in txt2img
processed = process_images(p)
File "X:\stable-diffusion-webui-directml\modules\processing.py", line 503, in process_images
res = process_images_inner(p)
File "X:\stable-diffusion-webui-directml\modules\processing.py", line 653, in process_images_inner
samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts)
File "X:\stable-diffusion-webui-directml\modules\processing.py", line 869, in sample
samples = self.sampler.sample(self, x, conditioning, unconditional_conditioning, image_conditioning=self.txt2img_image_conditioning(x))
File "X:\stable-diffusion-webui-directml\modules\sd_samplers_compvis.py", line 218, in sample
samples_ddim = self.launch_sampling(steps, lambda: self.sampler.sample(S=steps, conditioning=conditioning, batch_size=int(x.shape[0]), shape=x[0].shape, verbose=False, unconditional_guidance_scale=p.cfg_scale, unconditional_conditioning=unconditional_conditioning, x_T=x, eta=self.eta)[0])
File "X:\stable-diffusion-webui-directml\modules\sd_samplers_compvis.py", line 51, in launch_sampling
return func()
File "X:\stable-diffusion-webui-directml\modules\sd_samplers_compvis.py", line 218, in <lambda>
samples_ddim = self.launch_sampling(steps, lambda: self.sampler.sample(S=steps, conditioning=conditioning, batch_size=int(x.shape[0]), shape=x[0].shape, verbose=False, unconditional_guidance_scale=p.cfg_scale, unconditional_conditioning=unconditional_conditioning, x_T=x, eta=self.eta)[0])
File "X:\stable-diffusion-webui-directml\venv\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "X:\stable-diffusion-webui-directml\extensions\sd-dynamic-thresholding\dynthres_unipc.py", line 56, in sample
x = uni_pc_inst.sample(img, steps=S, skip_type=shared.opts.uni_pc_skip_type, method="multistep", order=shared.opts.uni_pc_order, lower_order_final=shared.opts.uni_pc_lower_order_final)
File "X:\stable-diffusion-webui-directml\modules\models\diffusion\uni_pc\uni_pc.py", line 758, in sample
model_prev_list = [self.model_fn(x, vec_t)]
File "X:\stable-diffusion-webui-directml\modules\models\diffusion\uni_pc\uni_pc.py", line 453, in model_fn
return self.data_prediction_fn(x, t)
File "X:\stable-diffusion-webui-directml\modules\models\diffusion\uni_pc\uni_pc.py", line 437, in data_prediction_fn
noise = self.noise_prediction_fn(x, t)
File "X:\stable-diffusion-webui-directml\modules\models\diffusion\uni_pc\uni_pc.py", line 431, in noise_prediction_fn
return self.model(x, t)
File "X:\stable-diffusion-webui-directml\modules\models\diffusion\uni_pc\uni_pc.py", line 417, in model
res = self.model_fn_(x, t, cond, uncond)
File "X:\stable-diffusion-webui-directml\extensions\sd-dynamic-thresholding\dynthres_unipc.py", line 107, in model_fn
return dtData.dynthresh(noise, noise_uncond, guidance_scale, None)
File "X:\stable-diffusion-webui-directml\extensions\sd-dynamic-thresholding\dynthres_core.py", line 70, in dynthresh
cfg_max = torch.quantile(cfg_centered.abs(), self.threshold_percentile, dim=2).unsqueeze(2).double()
RuntimeError: quantile() input tensor must be either float or double dtype
Hi, amazing extension, love using it, and it provides amazing results.
My issue is that the default values in the advanced tab dont yield good results, and I always have to change them to optimized
"Half cosine up" + Minimum scheduler 5
Can this be changed to default to these?
Error loading script: dynamic_thresholding.py
Traceback (most recent call last):
File "/content/stable-diffusion-webui/modules/scripts.py", line 229, in load_scripts
script_module = script_loading.load_module(scriptfile.path)
File "/content/stable-diffusion-webui/modules/script_loading.py", line 11, in load_module
module_spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/content/stable-diffusion-webui/extensions/sd-dynamic-thresholding/scripts/dynamic_thresholding.py", line 91, in <module>
class CustomCFGDenoiser(sd_samplers.CFGDenoiser):
AttributeError: module 'modules.sd_samplers' has no attribute 'CFGDenoiser'
More info:
Failed to add support for X/Y/Z Plot Script because: list index out of range
using colab, python 3.8
I inspected .py but couldnt find reason since I dont know how add xyz plot works.
Just a heads up. Looks like a recent SD update may have crashed your great extension...at least on my mac it did.
getting the following error:
File "/Users/ai/stable-diffusion-webui/extensions/sd-dynamic-thresholding/dynthres_unipc.py", line 6, in
from modules.models.diffusion import uni_pc
ImportError: cannot import name 'uni_pc' from 'modules.models.diffusion' (unknown location)
How to pass parameters in this api ' sdapi/v1/text2img'?
File "D:\stable-diffusion-webui\modules\scripts.py", line 229, in load_scripts
script_module = script_loading.load_module(scriptfile.path)
File "D:\stable-diffusion-webui\modules\script_loading.py", line 11, in load_module
module_spec.loader.exec_module(module)
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "D:\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 15, in
import dynthres_unipc, dynthres_core
File "D:\stable-diffusion-webui\extensions\sd-dynamic-thresholding\dynthres_unipc.py", line 6, in
from modules.models.diffusion import uni_pc
ImportError: cannot import name 'uni_pc' from 'modules.models.diffusion' (unknown location)
Hi there, really nice extension! Was wondering if this issue is known.
When trying to use UniPC Sampler with dynamic-thresholding and hi-res fix, it gives the following issue when it should start applyng the hi-res fix.
Traceback (most recent call last):
File "G:\Stable difussion\stable-diffusion-webui\modules\call_queue.py", line 56, in f
res = list(func(*args, **kwargs))
File "G:\Stable difussion\stable-diffusion-webui\modules\call_queue.py", line 37, in f
res = func(*args, **kwargs)
File "G:\Stable difussion\stable-diffusion-webui\modules\txt2img.py", line 56, in txt2img
processed = process_images(p)
File "G:\Stable difussion\stable-diffusion-webui\modules\processing.py", line 486, in process_images
res = process_images_inner(p)
File "G:\Stable difussion\stable-diffusion-webui\modules\processing.py", line 636, in process_images_inner
samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts)
File "G:\Stable difussion\stable-diffusion-webui\modules\processing.py", line 908, in sample
samples = self.sampler.sample_img2img(self, samples, noise, conditioning, unconditional_conditioning, steps=self.hr_second_pass_steps or self.steps, image_conditioning=image_conditioning)
File "G:\Stable difussion\stable-diffusion-webui\modules\sd_samplers_compvis.py", line 179, in sample_img2img
self.sampler.make_schedule(ddim_num_steps=steps, ddim_eta=self.eta, ddim_discretize=p.ddim_discretize, verbose=False)
AttributeError: 'CustomUniPCSampler' object has no attribute 'make_schedule'
I've tested with R-ESRGAN 4X+ and others upscalers, but all seem to suffer the same issue.
Thanks!
Error running process: G:\stable-diffusion-webui\extensions\sd-dynamic-prompts\scripts\dynamic_prompting.py
Traceback (most recent call last):
File "G:\stable-diffusion-webui\modules\scripts.py", line 417, in process
script.process(p, *script_args)
File "G:\stable-diffusion-webui\extensions\sd-dynamic-prompts\sd_dynamic_prompts\dynamic_prompting.py", line 400, in process
# is only available in AUTOMATIC1111 1.3.0+, but might not be in forks.
AttributeError: 'StableDiffusionProcessingTxt2Img' object has no attribute 'hr_prompt'
Hello, love the extension. But I've been losing my mind trying to make it work correctly with API and the advanced settings.. please provide the API docs... PLEASE.
Thanks in advance, hope it can happen.
Hey, I need some guidance.
I recently got this extension and what I see is a bit different from the readme.
Hey, where can I change the default settings? I'm usually using the same configuration as stated in the "Usage Tips", so it feels cumbersome to adjust the settings every time. I've tried poking dynamic_thresholding.py and changed the values there (I have no coding experience) and it didn't work.
threshold_percentile = gr.Slider(minimum=90.0, value=95, maximum=100.0, step=0.05, label='Top percentile of latents to clamp')
mimic_mode = gr.Dropdown(VALID_MODES, value="Half Cosine Up", label="Mimic Scale Scheduler")
mimic_scale_min = gr.Slider(minimum=0.0, maximum=30.0, step=0.5, value=3, label="Minimum value of the Mimic Scale Scheduler")
cfg_mode = gr.Dropdown(VALID_MODES, value="Half Cosine Up", label="CFG Scale Scheduler")
cfg_scale_min = gr.Slider(minimum=0.0, maximum=30.0, step=0.5, value=3, label="Minimum value of the CFG Scale Scheduler")
Error running process_batch: E:\StableDiffusion\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py
Traceback (most recent call last):
File "E:\StableDiffusion\stable-diffusion-webui\modules\scripts.py", line 395, in process_batch
script.process_batch(p, *script_args, **kwargs)
File "E:\StableDiffusion\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 59, in process_batch
raise RuntimeError(f"Cannot use sampler {p.sampler_name} with Dynamic Thresholding")
RuntimeError: Cannot use sampler DDIM with Dynamic Thresholding
It doesn't seem to like DDIM. Is it slightly possible to add support for DDIM?
Your extension works wonders btw. I've always been haunted by contrast issues with high cfg. I even trained a negative embedding just to counter the problem but without success. You literally saved my eyes thank you!
Im trying to add some values from this extension to Config-Presets but it needs a unique elem_id to save each item values
Hi. Just a quick question. Does Dynamic Thresholding affect the CFG Scale settings of other Automatic1111 extensions, in any way?
There are many examples of these popular extensions, but off the top of my head, how about ADetailer/After Detailer? And if yes, how so? Does Dynamic Thresholding "add" to their settings, or does it completely override them, or is the effect something else entirely?
Anyway, thanks in advance.
Hello, first thank you for the extension
As it is now if you were to copy the generation data contained in the image and run it in a different instance that don't have it enabled with the exact same settings of the original , the resulting image would be different
It would be helpful if the images generated while the extension is enabled contained all the settings of the extensions .
thank you.
Error line:
*** Error running postprocess_batch: D:\AI\webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py
Traceback (most recent call last):
File "D:\AI\webui\modules\scripts.py", line 506, in postprocess_batch
script.postprocess_batch(p, *script_args, images=images, **kwargs)
TypeError: Script.postprocess_batch() missing 8 required positional arguments: 'enabled', 'mimic_scale', 'threshold_percentile', 'mimic_mode', 'mimic_scale_min', 'cfg_mode', 'cfg_scale_min', and 'sched_val'
This is after the new update, 1.4.0 version. Before the update everything was fine.
I tried deleting the extension and installing it again. Tried downloading a clear webui and running it there, still the same.
Any ideas?
This causes mimic and cfg scale scheduler settings being left unchanged and results in a different image when you load data from an image with default values after generating an image with different settings. It is a bit annoying.
I did a fork and added tangent function just to test ... I'm curious to use complex numbers processing ... maybe just tie in x and y for a single operation ?
Do I need to be on the latest Auto1111 commit? I installed the extension and it fails to load with the following:
"from modules import scripts, script_callbacks, sd_samplers, sd_samplers_kdiffusion, sd_samplers_common
ImportError: cannot import name 'sd_samplers_kdiffusion' from 'modules' (unknown location)"
I checked the folder and don't see sd_samplers_kdiffusion or sd_samplers_common.
EDIT: I checked and my commit is from earlier January, before the original sd_samplers were split. Is it needed? Could the code be updated to simply import sd_samplers if kdfiffusion/common are not located? I don't want to upgrade as I am getting faster speeds and stability with this old commit but I do want to try this extension.
Hello, one of the best extension out there.
Id normally run multidifussion alongside dynamic thresholding but after todays update I get this message. Any idea how to fix it?
Error running process_batch: F:\AI\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py
Traceback (most recent call last):
File "F:\AI\stable-diffusion-webui\modules\scripts.py", line 436, in process_batch
script.process_batch(p, *script_args, **kwargs)
File "F:\AI\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 127, in process_batch
p.sampler = sd_samplers.create_sampler(fixed_sampler_name, p.sd_model)
File "F:\AI\stable-diffusion-webui\extensions\multidiffusion-upscaler-for-automatic1111\scripts\tilediffusion.py", line 364, in
sd_samplers.create_sampler = lambda name, model: self.create_sampler_hijack(
File "F:\AI\stable-diffusion-webui\extensions\multidiffusion-upscaler-for-automatic1111\scripts\tilediffusion.py", line 434, in create_sampler_hijack
sampler = sd_samplers.create_sampler_original_md(name, model)
AttributeError: module 'modules.sd_samplers' has no attribute 'create_sampler_original_md'
This issue seems to have reappeared.
On my M2 MacBook Air, when I try to generate an image with Dynamic Thresholding enabled, I get the following error:
Error completing request00, ?it/s]
Arguments: ('task(q1b5sqs9msl08ij)', 'female, looking at viewer, frown, blond, updo haircut, huge breasts, curvy, sundress, flower hair ornament, flower field, blue sky, complex background, beautiful lighting, deep shadow, best quality, masterpiece, ultra highres, photorealistic,', 'bad-picture-chill-75v, badhandv4, easynegative, CyberRealistic_Negative-neg, bokeh,', [], 30, 15, False, False, 1, 1, 12, 2906325223.0, -1.0, 0, 0, 0, False, 768, 512, True, 0.4, 1.4, '4x-UltraSharp', 10, 0, 0, 0, '', '', [], 0, False, {'ad_model': 'face_yolov8n.pt', 'ad_prompt': '', 'ad_negative_prompt': '', 'ad_confidence': 0.3, '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_restore_face': False, 'ad_controlnet_model': 'None', 'ad_controlnet_weight': 1, 'ad_controlnet_guidance_start': 0, 'ad_controlnet_guidance_end': 1}, {'ad_model': 'None', 'ad_prompt': '', 'ad_negative_prompt': '', 'ad_confidence': 0.3, '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_restore_face': False, 'ad_controlnet_model': 'None', 'ad_controlnet_weight': 1, 'ad_controlnet_guidance_start': 0, 'ad_controlnet_guidance_end': 1}, 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, 512, 64, True, True, True, False, True, 8, 100, 'Constant', 0, 'Constant', 0, 4, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x28ae9c520>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x28ae9fd30>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x28ae9c640>, False, '1:1,1:2,1:2', '0:0,0:0,0:1', '0.2,0.8,0.8', 20, False, False, 'positive', 'comma', 0, False, False, '', 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, None, None, False, None, None, False, None, None, False, 50) {}
Traceback (most recent call last):
File "/Users/USERNAME/stable-diffusion-webui/modules/call_queue.py", line 57, in f
res = list(func(*args, **kwargs))
File "/Users/USERNAME/stable-diffusion-webui/modules/call_queue.py", line 37, in f
res = func(*args, **kwargs)
File "/Users/USERNAME/stable-diffusion-webui/modules/txt2img.py", line 57, in txt2img
processed = processing.process_images(p)
File "/Users/USERNAME/stable-diffusion-webui/modules/processing.py", line 610, in process_images
res = process_images_inner(p)
File "/Users/USERNAME/stable-diffusion-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 "/Users/USERNAME/stable-diffusion-webui/modules/processing.py", line 728, 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 "/Users/USERNAME/stable-diffusion-webui/modules/processing.py", line 976, in sample
samples = self.sampler.sample(self, x, conditioning, unconditional_conditioning, image_conditioning=self.txt2img_image_conditioning(x))
File "/Users/USERNAME/stable-diffusion-webui/modules/sd_samplers_kdiffusion.py", line 383, in sample
samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args={
File "/Users/USERNAME/stable-diffusion-webui/modules/sd_samplers_kdiffusion.py", line 257, in launch_sampling
return func()
File "/Users/USERNAME/stable-diffusion-webui/modules/sd_samplers_kdiffusion.py", line 383, in <lambda>
samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args={
File "/Users/USERNAME/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/Users/USERNAME/stable-diffusion-webui/repositories/k-diffusion/k_diffusion/sampling.py", line 594, in sample_dpmpp_2m
denoised = model(x, sigmas[i] * s_in, **extra_args)
File "/Users/USERNAME/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/Users/USERNAME/stable-diffusion-webui/modules/sd_samplers_kdiffusion.py", line 181, in forward
denoised = self.combine_denoised(x_out, conds_list, uncond, cond_scale)
File "/Users/USERNAME/stable-diffusion-webui/extensions/sd-dynamic-thresholding/scripts/dynamic_thresholding.py", line 171, in combine_denoised
return self.main_class.dynthresh(x_out[:-uncond.shape[0]], denoised_uncond, cond_scale, weights)
File "/Users/USERNAME/stable-diffusion-webui/extensions/sd-dynamic-thresholding/dynthres_core.py", line 85, in dynthresh
cfg_clamped = cfg_centered.clamp(-actualMax, actualMax)
RuntimeError: impl: min and input tensors must be of the same shape
The solution offered under the previous bug report does not work for me. My webui-macos-env.sh already calls for a newer version of torch: export TORCH_COMMAND="pip install torch==2.0.1 torchvision==0.15.2"
.
The generated image has extremely low contrast, as if there were no VAE involved, and the image tends to be burned out at low resolutions. This problem occurs with various sampling methods. The plugin and CFG settings are as follows:
(CFG Scale)
24
Mimic CFG Scale
9
Dynamic Thresholding Advanced Options
▼
Top percentile of latents to clamp
100
Mimic Scale Scheduler
Constant
Minimum value of the Mimic Scale Scheduler
0
CFG Scale Scheduler
Half Cosine Up
Minimum value of the CFG Scale Scheduler
4
I've changed the title of the extension to dynamic_thresholding. No errors occur, it just doesn't do anything. Am I sending the right fields?
//alwayson_scripts = new
//{
// dynamic_thresholding = new
// {
// args = new object[]
// {
// new
// {
// enabled = true,
// mimic_scale = 17.5,
// threshold_percentile = 100,
// mimic_mode = "Linear Down",
// mimic_scale_min = 17.5,
// cfg_mode = "Linear Down",
// cfg_scale_min = 17.5,
// powerscale_power = 4.0
// }
// }
// }
//}
I cant activate it in the UI because it doesnt appear. I get the following error message in the console
Error loading script: dynamic_thresholding.py
Traceback (most recent call last):
File "C:\sd\stable-diffusion-webui-master\modules\scripts.py", line 229, in load_scripts
script_module = script_loading.load_module(scriptfile.path)
File "C:\sd\stable-diffusion-webui-master\modules\script_loading.py", line 11, in load_module
module_spec.loader.exec_module(module)
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "C:\sd\stable-diffusion-webui-master\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 17, in
from modules import scripts, sd_samplers, sd_samplers_kdiffusion, sd_samplers_common
ImportError: cannot import name 'sd_samplers_kdiffusion' from 'modules' (unknown location)
I've been having issues getting this setup. I tried uninstalling both Dynamic prompts and dynamic thresholding 3 times by deleting the folders inside the SD webui Extensions folder and reinstalling it from within webui, but it has yet to appear in my webui.
It only shows up as dynamic prompts and nothing from dynamic thresholding shows up.
If anyone has any idea why, I would appreciate the help! Thank you!
Traceback (most recent call last):
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\modules\call_queue.py", line 57, in f
res = list(func(*args, **kwargs))
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\modules\call_queue.py", line 37, in f
res = func(*args, **kwargs)
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\modules\img2img.py", line 182, in img2img
processed = process_images(p)
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\modules\processing.py", line 526, in process_images
res = process_images_inner(p)
File "H:\Stablediff\Automatic1111\stable-diffusion-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 "H:\Stablediff\Automatic1111\stable-diffusion-webui\modules\processing.py", line 680, in process_images_inner
samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts)
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\modules\processing.py", line 1135, in sample
samples = self.sampler.sample_img2img(self, self.init_latent, x, conditioning, unconditional_conditioning, image_conditioning=self.image_conditioning)
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 350, in sample_img2img
samples = self.launch_sampling(t_enc + 1, lambda: self.func(self.model_wrap_cfg, xi, extra_args=extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 251, in launch_sampling
return func()
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 350, in
samples = self.launch_sampling(t_enc + 1, lambda: self.func(self.model_wrap_cfg, xi, extra_args=extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\venv\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "H:\Stablediff\Automatic1111\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 "H:\Stablediff\Automatic1111\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 179, in forward
denoised = self.combine_denoised(x_out, conds_list, uncond, cond_scale)
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 170, in combine_denoised
return self.main_class.dynthresh(x_out[:-uncond.shape[0]], denoised_uncond, cond_scale, weights)
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\extensions\sd-dynamic-thresholding\dynthres_core.py", line 42, in dynthresh
mimicScale = self.interpretScale(self.mimic_scale, self.mimic_mode, self.mimic_scale_min)
File "H:\Stablediff\Automatic1111\stable-diffusion-webui\extensions\sd-dynamic-thresholding\dynthres_core.py", line 18, in interpretScale
scale -= min
TypeError: unsupported operand type(s) for -=: 'bool' and 'str'
I've tried it with different samplers, and it works with some better than others (and with some doesn't work at all).
What I've noticed about SDE, it outputs amazing (!) results half way through (I have set the option to output the intermediate results), but at about last 3rd of the process the image gets kinda totally destroyed - turnes into cartoonish garbage. And it happens with all images, prompts and the script settings. It's almost like if SDE tweaks CFG on its own and interferes with the script at the last steps, making it maybe... negative? I don't know the whole math behind it, but that's how it feels.
Is it possible to fix? The intermediate SDE results that I see are sooo good, I really would like to have this script working with that sampler (Karras or non-Karras). Please)
I started using this extension recently and she's very nice, but (i'm not a expert) i think i got memory leak after couple of generations & got the cuda out of memory and need to relaunch the web ui. If i disable the extension in the extension tab i got no worries at all and can generate for hours.
Copying straight from vladmandic/automatic#641:
In text2img, when using UniPC with HiRes fix enabled, you still get the following warning:
╭───────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────╮
│ C:\Users\source\repos\automatic\modules\scripts.py:372 in process_batch │
│ │
│ 371 │ │ │ │ args = p.per_script_args.get(script.title(), p.script_args[script.args_f │
│ ❱ 372 │ │ │ │ script.process_batch(p, *args, **kwargs) │
│ 373 │ │ │ except Exception as e: │
│ │
│ C:\Users\source\repos\automatic\extensions-builtin\sd-dynamic-thresholding\scripts\dynamic_thresholding.py:80 │
│ in process_batch │
│ │
│ 79 │ │ if p.sampler_name == 'UniPC' and p.enable_hr: │
│ ❱ 80 │ │ │ raise RuntimeError(f"UniPC does not support Hires Fix. Auto WebUI silently s │
│ 81 │ │ mimic_scale = getattr(p, 'dynthres_mimic_scale', mimic_scale) │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
RuntimeError: UniPC does not support Hires Fix. Auto WebUI silently swaps to DDIM for this, which DynThresh does not
support. Please swap to a sampler capable of img2img processing for HR Fix to work.
However, at this point, UniPC is already a valid img2img sampler, and as of vladmandic/automatic@ba50dbb, a given secondary sampler that is capable of img2img shouldn't cause this error in the first place.
So in my case, there are two reasons why this error is inapproriate:
I can see where the error is coming from, due to multiple different separate modules coming in conflict with each other, and it's unrealistic to expect support for different forks, but maybe it's possible to call this error only once the webui selected a sampler incompatible with this extension.
Hello!
I'm trying to test out your extension for the first time. I'm on the latest A1111 commit and installed via the extension tab. When restarting the Webui I get the following error. Any idea how I can resolve this? Sorry if it's a newbie question or due to a modification I made in the past. I appreciate any help and your work. Thx!
BTW: Using a CPU search tool I don't have a file called sd_samplers_kdiffusion, but I do have one in modules called sd_samplers_kdiffusion.cpython-310.pyc (C:\stable-diffusion-webui\modules_pycache_\sd_samplers_kdiffusion.cpython-310.pyc)
Error:
Closing server running on port: 7860
Restarting UI...
Error loading script: dynamic_thresholding.py
Traceback (most recent call last):
File "C:\stable-diffusion-webui\modules\scripts.py", line 229, in load_scripts
script_module = script_loading.load_module(scriptfile.path)
File "C:\stable-diffusion-webui\modules\script_loading.py", line 11, in load_module
module_spec.loader.exec_module(module)
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "C:\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 16, in
from modules import scripts, sd_samplers, sd_samplers_kdiffusion, sd_samplers_common
ImportError: cannot import name 'sd_samplers_kdiffusion' from 'modules' (unknown location)
IIUC, it would be nice to have a checkbox in the settings or generation parameters that scales the slider back to linear behavior.
Traceback (most recent call last): File "C:\Users\dimap\Documents\A1111 Web UI Autoinstaller\stable-diffusion-webui\modules\scripts.py", line 218, in load_scripts script_module = script_loading.load_module(scriptfile.path) File "C:\Users\dimap\Documents\A1111 Web UI Autoinstaller\stable-diffusion-webui\modules\script_loading.py", line 13, in load_module exec(compiled, module.__dict__) File "C:\Users\dimap\Documents\A1111 Web UI Autoinstaller\stable-diffusion-webui\extensions\sd-dynamic-thresholding\scripts\dynamic_thresholding.py", line 15, in <module> import dynthres_unipc, dynthres_core File "C:\Users\A1111 Web UI Autoinstaller\stable-diffusion-webui\extensions\sd-dynamic-thresholding\dynthres_unipc.py", line 6, in <module> from modules.models.diffusion import uni_pc ModuleNotFoundError: No module named 'modules.models'
When dynamic thresholding is enabled, the sampler returned by "return generation parameters from prompt or last generation" is affixed with _dynthres<num>
This appears to happen here.
After copypasting the previous generation data, the sampler must be edited manually to remove the suffix, or generation will fail, as e.g. DPM++ SDE Karras_dynthres1
is not a valid sampler.
mac OS Ventura 13.2.1
Error completing request
Arguments: ('task(v51c2r1ev29upey)', 0, 'fantasy land lora:samdoesartsSamYang_offsetRightFilesize:0.6 lora:epiNoiseoffset_v2:0.6', '', [], <PIL.Image.Image image mode=RGBA size=512x512 at 0x223C990F0>, None, None, None, None, None, None, 20, 15, 4, 0, 1, False, False, 1, 1, 16, 1.5, 0.3, -1.0, -1.0, 0, 0, 0, False, 512, 512, 0, 0, 32, 0, '', '', '', [], 0, False, '', 0, True, 5.5, 98, 'Half Cosine Up', 4, 'Half Cosine Up', 4, 4, <scripts.external_code.ControlNetUnit object at 0x22c66dd80>, <scripts.external_code.ControlNetUnit object at 0x22c66d2d0>, <scripts.external_code.ControlNetUnit object at 0x22c66c130>, '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', False, 0, 'values', '0,0.25,0.5,0.75,1', 'Block ID', 'IN05-OUT05', 'none', '', '0.5,1', 'BASE,IN01,IN02,IN04,IN05,IN07,IN08,M00,OUT03,OUT04,OUT05,OUT06,OUT07,OUT08,OUT09,OUT10,OUT11', 'black', '20', False, True, True, True, '
CFG Scale
should be 2 or lower.Recommended settings: Sampling Steps: 80-100, Sampler: Euler a, Denoising strength: 0.8
', 128, 8, ['left', 'right', 'up', 'down'], 1, 0.05, 128, 4, 0, ['left', 'right', 'up', 'down'], False, False, 'positive', 'comma', 0, False, False, '', 'Will upscale the image by the selected scale factor; use width and height sliders to set tile size
', 64, 0, 2, 1, '', 0, '', 0, '', True, False, False, False, 0, 'Blur First V1', 0.25, 10, 10, 10, 10, 1, False, '', '', 0.5, 1, False, False, 0, True, 384, 384, False, 2, True, True, False, False, '', False, 'Normal', 1, True, 1, 1, 'None', False, False, False, 'YuNet', 512, 1024, 0.5, 1.5, False, 'face close up,', 0.5, 0.5, False, True, None, False, None, False, None, False, 50, 0, 0, 512, 512, False, False, True, True, True, False, False, 1, False, False, False, 2.5, 4, 0, False, 0, 1, False, False, 'u2net', False, False, False, False) {}A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.