-
Notifications
You must be signed in to change notification settings - Fork 30k
Update sd_samplers_cfg_denoiser.py #16814
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
Update sd_samplers_cfg_denoiser.py #16814
Conversation
This commit introduces a safeguard to ensure that schedulers and samplers strictly adhere to the requested step count during iterative processing. The change prevents the system from exceeding the total number of steps, avoiding potential errors, inconsistencies, or unexpected behavior caused by unintended step overflows. A check is added to verify that the current step (self.step) does not exceed or equal the total allowed steps (self.total_steps). If the condition is met, an InterruptedException is raised, gracefully halting further processing.
|
I found this error while working with an advanced scheduler - though I fixed the code in the scheduler, I thought this would be easily fixed with a safeguard in this file, which is the next file up from parse_prompter.py. During the loop, if a scheduler or sampler modifies the steps (accidentally or on purpose), instead of erroring out it simply drops any steps that exceed the requested user steps and finishes the image. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change directly breaks Sampling method: DPM adaptive
which is by design to have a non-deterministic amount of steps
lets suppose this doesn't break stuff like DPM adaptive, I still don't really see a reason to add the safeguard
as this really is not a common issue, it's only happens if you're working with some advanced things
and the other side of "safeguarding" is "limiting possibilities"
it is totally possible that some extension may wish to developerly modify the steps was not updating the total steps, sp this safeguard will break those extensions
in my opinion, fixing the thing that is actually causing issue is better than adding unnecessary safeguards that potentially cause more issues of its own
It's true that advanced things like custom schedulers may modify steps without actually using that terminology "self.step" or self.steps" by manipulating the sigmas_karras in a loop without knowingly doing so. If DPM adaptive works by manipulating the sigmas instead of manipulating the steps, which would make the most sense, then it wouldn't effect it. For example, in my scheduler, I create a loop and inside it I manipulate things, ` sigmas_karras = get_sigmas_karras(n=n, sigma_min=sigma_min, sigma_max=sigma_max, device=device) ... for Hence....safety. You don't want to ever introduce the ability for new code to contradict what the user specified in the gui. I would think. You mentioned DPM adaptive not working when introducing this code. I would argue in that case, that DPM adaptive could be structured in a way which doesn't interfere with self.step or self.steps. If code is used to introduce a new sampler or scheduler which forces a particular number of steps, let's say 30 steps, and the user specifies 50 steps, then you'll get a bad image, because the noise generated from 50 steps is different than 30 steps and the program thinks it has time to get there...but if the program says that n=30 insteaad of the 50 that the person requested then they could think the program is bad....or if they set the number of steps to 1 or basically anything less than 20 for most things.... then no matter what the person puts 35, 40, 45 etc. you'll only get 1 step completed because you let a program modify the steps directly in code. A safeguard stops such programs in their tracks. You could even add a helpful message like: And when you say it breaks DPM Adaptive, are you referencing this code: https://github.com/CompVis/stable-diffusion/blob/main/ldm/models/diffusion/ddpm.py Where they do modify N internally - which wouldn't effect this safeguard, since self.step and self.steps changes via code. This safeguard would protect in the instance given above as an example. |
|
If you actually test "DPM adaptive ignores the user setp input" if your PR is going to be merged, then the things it breaks needs to be fixed in your PR As demonstrated you with when possible breaking change should be avoided
if you're saying this because your other PR was closed |
|
As I understand it, DPM adaptive modifies the sigmas to determine the appropriate count of steps. The issue I pointed out was the ability for a scheduler to change the number of steps and you have no safeguards against it. I suggested the code modification to protect the system, and DPM adaptive would not be effected because of the way it works. DPM adaptive does not attempt to change the steps that a uuser inputs, they instead adjust sigma / noise levels dynamically based on the noise schedule. As Chat GPT Summarizes the issue: DPM Adaptive (Denoising Diffusion Probabilistic Model Adaptive) works differently from traditional samplers because it dynamically adjusts the number of steps based on the target noise schedule and tolerance settings rather than strictly following the user-specified step count. How DPM Adaptive Works: DPM Adaptive would fail because it doesn’t track self.step in a predictable manner. |
|
did you use chat gpt to send this? also that version of the request I am no
longer concerned about. I made a valid suggestion and was ignored. So I've
learned not to try to update on this project because my suggestions are not
regarded as being helpful. So i'll take my suggestions somewhere else and
just work on my own projects.
…On Wed, Jun 25, 2025 at 11:53 AM dcq01 ***@***.***> wrote:
***@***.**** commented on this pull request.
Hi! I'm a grad student working on a research project about using large
language models to automate code review. Based on your commit 41ba1be
<41ba1be>
and the changes in modules/sd_samplers_cfg_denoiser.py, my tool generated
this comment:
1. *Exception Handling*: Ensure that
sd_samplers_common.InterruptedException is properly handled in the
calling context to avoid unhandled exceptions.
2. *Logical Flow*: The new check for self.step >= self.total_steps is
a good addition to prevent further processing when the maximum number of
steps has been reached.
3. *Testing*: Add unit tests that cover scenarios where self.step is
equal to or exceeds self.total_steps to verify that the exception is
raised as expected.
4. *Boundary Testing*: Test the condition where self.step is exactly
equal to self.total_steps to confirm that the exception is raised
correctly.
5. *Indentation Error*: The line raise
sd_samplers_common.InterruptedException is incorrectly indented. It
should align with the if statement above it.
6. *Comment Clarity*: The comment added before the if statement could
be improved by explaining the purpose of self.step and self.total_steps
.
7. *Comment Style Consistency*: The comment style should be consistent
throughout the code. The new comment should follow the same format as other
comments in the file.
8. *Logging*: Log the occurrence of the InterruptedException for
debugging and monitoring purposes to help identify potential misuse or
unexpected behavior in production environments.
9. *Documentation*: Update any relevant documentation to reflect the
new exception and the conditions under which it is raised.
As part of my research, I'm trying to understand how useful these comments
are in real-world development. If you have a moment, I'd be super grateful
if you could quickly reply to these two yes/no questions:
1. Does this comment provide suggestions from a dimension you hadn’t
considered?
2.
2. Do you find this comment helpful?
Thanks a lot for your time and feedback! And sorry again if this message
is a bother.
—
Reply to this email directly, view it on GitHub
<#16814 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BLYPP3SUGJY2HZIBYVERV2D3FLAXHAVCNFSM6AAAAABV7ID4XWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDSNJYG42TSMRUGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|

This commit introduces a safeguard to ensure that schedulers and samplers strictly adhere to the requested step count during iterative processing. The change prevents the system from exceeding the total number of steps, avoiding potential errors, inconsistencies, or unexpected behavior caused by unintended step overflows.
A check is added to verify that the current step (self.step) does not exceed or equal the total allowed steps (self.total_steps). If the condition is met, an InterruptedException is raised, gracefully halting further processing.
Description
Screenshots/videos:
Checklist: