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]: Final Sampling step ruin the image, very visible in DPM2 a #3483

Closed
1 task done
fernicar opened this issue Oct 23, 2022 · 16 comments
Closed
1 task done

[Bug]: Final Sampling step ruin the image, very visible in DPM2 a #3483

fernicar opened this issue Oct 23, 2022 · 16 comments
Labels
bug-report Report of a bug, yet to be confirmed upstream Issue or feature that must be resolved upstream

Comments

@fernicar
Copy link

fernicar commented Oct 23, 2022

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits

What happened?

Second to Last Sampling step is better than final result, very visible in DPM2 a and similar sampler Karras,
Changing the amount of steps does not fix it, it is always the second to last sampling the one with good results.
Sad to see underrated [DPM2 a] sampler just because a bug, Here is a comparison from current build 6bd6154
Comparisons

Steps to reproduce the problem

  1. Select DPM2 a
  2. Generate

What should have happened?

Perhaps shared.state.sampling_step is not updated and the sample process goes one more step when it shouldn't.

Commit where the problem happens

the good: perhaps there is no good commit yet...
the bad: 7ce7fb0 it ruins last step since Sep 6 2022!
and the ugly: 5766ce2 it defeats "Clip skip: 2" feature since Oct 11 2022

What platforms do you use to access UI ?

Windows

What browsers do you use to access the UI ?

Mozilla Firefox

Command Line Arguments

--deepdanbooru --xformers --medvram

Additional information, context and logs

This custom script will help you save Sampling steps during testing:
https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts#saving-steps-of-the-sampling-process
however, the iteration of steps is not counting from 1, but 0

The other problem is in sd_samplers.py > def store_latent(decoded)
This function access shared.state.sampling_step before its update.
For this reason [Show image creation progress every N sampling steps. Set 0 to disable.] will display step 1 and step 2 regardless of bigger N interval, say 5 or 6.
Perhaps this is the reason for the OP bug.

@fernicar fernicar added the bug-report Report of a bug, yet to be confirmed label Oct 23, 2022
@Hangover3832
Copy link

Could be related to this, I can confirm similar behavior when using outpainting. The step preview images look promising, the final image gets hugely color distorted. No matter what model, sampler or outpainting script is used.

@shadinx2
Copy link

Could it be that img2img color correction is enabled? Try the same prompts and settings without out to see if that was it.

@Hangover3832
Copy link

You are right. Disabling color correction seems to solve this issue.

@jmp909
Copy link

jmp909 commented Oct 24, 2022

I think this might be a related issue #3465 (regarding color correction)

@bucketcat
Copy link

I'm having this happen, but with black screen. Not every image. Stopping generation gives me an image. Started happening a few days ago. The regular black output bug does not apply in my case (20 series card, happened last weeks). Happens only on some samplers, all DPM samplers and K_euler_a, but not K_euler.

mcmonkey4eva added a commit to mcmonkey4eva/stable-diffusion-webui that referenced this issue Dec 16, 2022
DPM2 a and DPM2 a Karras samplers are both affected by an issue described by AUTOMATIC1111#3483 and can be resolved by a workaround suggested by the k-diffusion author at crowsonkb/k-diffusion#43 (comment)
@mcmonkey4eva
Copy link
Contributor

The issue is discussed in k-diffusion @ crowsonkb/k-diffusion#43

I have submitted the workaround recommended there as a PR: #5797

Oncorporation pushed a commit to Oncorporation/stable-diffusion-webui that referenced this issue Jan 2, 2023
DPM2 a and DPM2 a Karras samplers are both affected by an issue described by AUTOMATIC1111#3483 and can be resolved by a workaround suggested by the k-diffusion author at crowsonkb/k-diffusion#43 (comment)
@bosbrand
Copy link

I'm having the same thing, in the last two or three steps my image gets ruined. It is very apparent in LMS, where it complety glitches out faces.
sample-00011
sample-00014

@hoodady
Copy link

hoodady commented Feb 13, 2023

Same issue I have. Is there any fix to this?
image

@ExoFi-Labs
Copy link

Been frustrated with this for so long - there is a solution! Antiburn Extension in A1111 Extensions

Skip x number of last steps and much more

image

https://github.com/klimaleksus/stable-diffusion-webui-anti-burn

@bosbrand
Copy link

bosbrand commented Mar 11, 2023

@TheExodus90 oh my god, thank you!

@SebastiaanVW1984
Copy link

SebastiaanVW1984 commented Mar 16, 2023

I left a comment with hints on where this problem may lie in the sister thread for people that have the same issue that isn't the vea or fixed by anti-burn:
#7244 (comment)

@mcmonkey4eva
Copy link
Contributor

mcmonkey4eva commented Mar 17, 2023

@SebastiaanVW1984

I left a comment with hints on where this problem may lie in the sister thread for people that have the same issue that isn't the vea or fixed by anti-burn: #7244 (comment)

That thread is a bit of a mess, it looks like everyone in there has a different root issue - some have unwanted scale/noise param combos, at least one somehow had a corrupted checkpoint model file? some are seeing changes that came from not-so-specific webui updates, some are just the classic case of "the last step is ugly!! the preview is better!!" but it's just because the preview is soft n blurry while the final image has details (that they happen to not like), you have ... I'll be honest I don't even know what going on as you described your steps to resolve your issue but not what your issue was (demonstration images are essential for diagnosing things like this).


This thread was about a bug with DPM2 that was essentially the input noise parameters being janked in such a way as to add a dirty/speckled/noisy effect over an image that wasn't meant to be there (detail-step data was being hyperemphasized).

LMS appears to have a similar issue as bosbrand showed, but more specifically corruption that consistently generates blue/cyan distorted noise over top of things. This is likely a fundamental bug in the sampler/noise params as happened with DPM2, but unfortunately iirc last i poked at it, it wasn't so easily resolved as the DPM2 issue was (the issue noticeably varies based on your total step count, and tricks like skipping semifinal step work for some step counts but not others).

Honestly with the LMS issue I'm at the point where the best idea of how to deal with it I can suggest is just, ignore it, don't use LMS, use a more stable sampler. DPM++ 2M Karras and UniPC are the current best samplers we have available. SDE is popular if you like randomized results (small changes to input get amplified significantly more than other samplers do, SDE is very similar to the a ancestral samplers in this regard).

Antiburn is a decent trick to sorta resolve the LMS issue, and also is a powerful tool for the "last step is subjectively ugly" users to get what they subjectively prefer. (DynThres can also help for both of these, particularly in the case where a user wants a large CFG Scale).


The DPM2 issue was able to be resolved because

  • There was clear demonstration of the issue
  • The issue was not subjective, it's clearly just wrong output
  • it was easily replicable by others
  • it was consistently and narrowly just DPM2 that did it, you could change other variables without unbreaking it, you could use other samplers and the issue wasn't present
  • Several users went around actively gathering support to get it fixed - including this issue being posted, a k-diffusion issue being posted to get solution fixes from the original author, and a discord user sending me details to get me replicating it until finally I searched and tested and managed to get katherine's ideas to solve it fully working and merged into the webui itself.

But so, re that other thread, none of the issues in there are going to be properly solvable until they're able to narrow down to very specific sub-issues in the way this thread was able to identify a precise and replicable fault, with exact input data + result images + clear reason as to why the 'bad' output is genuinely worse at a technical level (as opposed to subjectively uglier) + the same output break is seen by other users in the exact same way when they try the same thing + it applies consistently when irrelevant variables are changed (eg seed, prompt, etc should be able to change and still have the issue)

If you think you're onto a genuine technical fault that could be resolved, I'd encourage you to gather full details and validation - verify that every detail that shouldn't be relevant can be changed and still replicate the issue and all - and post a new issue thread that includes full issue-demonstrating details and enables others to replicate the issue, at which point we can see about genuinely solving it. (note: avoid reusing existing threads as there are so many "similar sounding" but fundamentally different issues going on in them).


ps. apologies for overly long post and apologies if my tone comes across wrong, the purpose of this post is to hopefully help you know how to take your research into that issue and push it towards being something we can actually completely resolve and fix.

@janwilmans
Copy link

janwilmans commented Apr 19, 2023

See also #7244, If have provided a reproduction scenario here: #7244 (comment), I will follow up with more investigation bi-secting through git history too see if I can find an introduction point.

@bryanray
Copy link

bryanray commented May 8, 2023

same here
#10193

@catboxanon catboxanon added asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance bug-report Report of a bug, yet to be confirmed and removed bug-report Report of a bug, yet to be confirmed asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance labels Aug 5, 2023
@catboxanon
Copy link
Collaborator

catboxanon commented Aug 5, 2023

Duplicate of #1973

Root issue that this issue was opened for was fixed many months ago (#5797). There's a good summary here that explains the remaining issues are very situational, only apply to certain samplers, and/or are not easily solvable. Another use has also commented this issue persists for these samplers in other software (ComfyUI), so it is not something webui specific. It's related to the k-diffusion implementation. If and when it is fixed in k-diffusion, it will be fixed in the webui.

tl;dr: Use the Always discard next-to-last sigma option in settings if you continue to have issues (this returns the step before the last step of the image as many of you describe fixes the problem, but thus far that option is never mentioned in these issues). If that still does not work, consider reading the post by mcmonkey I have linked above, and to use a different sampler.

@catboxanon catboxanon added the upstream Issue or feature that must be resolved upstream label Aug 5, 2023
Repository owner locked as resolved and limited conversation to collaborators Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug-report Report of a bug, yet to be confirmed upstream Issue or feature that must be resolved upstream
Projects
None yet
Development

No branches or pull requests

14 participants