Skip to content

Add ancestral sampling and advanced node - #7

Merged
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral
Jun 19, 2025
Merged

Add ancestral sampling and advanced node#7
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral

Conversation

@blepping

Copy link
Copy Markdown
Contributor

This pull adds ancestral sampling support as well as an advanced node that exposes the various settings (and allows setting ETA to enable ancestral sampling). The ancestral sampling side works for both flow and non-flow models and was tested on SD 1.5, Wan, Flux, and Cosmos Predict2. These changes should not affect results when ancestral sampling isn't enabled.

I tried to keep these changes minimal and use your code style when possible but a little refactoring was necessary. I also expanded your first_only option to allow setting the start/end step ranges for distance sampling.

There's an experimental option to use ancestralness in the internal distance steps as well. Interesting, it works pretty well with flow models (doesn't seem as good with non-flow). Example with Flux, no ancestral sampling:

image

vs with these parameters (previous generation was the same, just with both ETA parameters set to 0):

image

image

Hopefully this pull is along the lines of something you'd be interested in merging. If you need anything changed, please let me know!

@Extraltodeus

Extraltodeus commented Jun 19, 2025

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

I had given up after messing up the scaling but I feel that it could help with selecting better values.

@Extraltodeus
Extraltodeus merged commit 49c35d0 into Extraltodeus:mainJun 19, 2025
@blepping

Copy link
Copy Markdown
ContributorAuthor

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

@Extraltodeus

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

Oh :D

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

@Extraltodeus

Copy link
Copy Markdown
Owner

If I wanted to add it as ancestral in the preset list which setting would you recommand?

@blepping

Copy link
Copy Markdown
ContributorAuthor

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

Ah, I see. It can be sort of complicated for flow models, so maybe that was the issue. In any case, it works now (I hope!) so not really something you need to worry about anymore.

If I wanted to add it as ancestral in the preset list which setting would you recommand?

Most ancestral samplers just use eta=1.0, so you could do that. Or eta=0.5 for a milder ancestral effect. Ancestralness on the distance steps (distance_step_eta) is an experimental option and have weird results, if it was me I'd probably just let people enable that manually via the advanced node if they wanted to use it. It might not be worth making a preset for. If you do, probably try some relatively low value like 0.2 which may be enough to notice but not break stuff.

@Extraltodeus

Copy link
Copy Markdown
Owner

(forgot to say thanks ^^)

@Extraltodeus

Extraltodeus commented Jul 2, 2025

Copy link
Copy Markdown
Owner

I was trying around and I wonder about something. Since you mentionned not having good results with non-flow models for the internal steps I got to wonder if maybe this line (at line 163):

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=distance_step_eta if use_distance_eta else 0.0, is_rf=is_rf)

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

Because if I change it to:

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=(distance_step_eta * (resample_steps - 1) / resample_steps) if use_distance_eta else 0.0, is_rf=is_rf)

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

What is your opinion?

@blepping

Copy link
Copy Markdown
ContributorAuthor

Sorry about the slow reply!

Since you mentionned not having good results with non-flow models for the internal steps

Ahh, I see I phrased that part poorly and even left out a word. What I meant was that it can have weird results and requires some tweaking. I don't think it's necessarily bad, though 1.0 ETA on those steps may generally be too much.

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do, I'm just decent at implementing this sort of stuff from an existing reference.

It makes sense that noise addition on internal distance steps would have a strong effect since intuitively it seems like this would be compounding the effect of ETA. One way to deal with that would be just to set a low ETA manually (the approach I used). Scaling it based on the internal steps seems like something that should work also.

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

Using that approach, do you still see a noticeable difference between using ETA for the internal steps vs just leaving it at 0? If so, then sounds like a good idea! Like I said though, your judgement for this stuff is probably better than mine so I'd be inclined to just defer to whatever approach you think works best.

@Extraltodeus

Extraltodeus commented Jul 9, 2025

Copy link
Copy Markdown
Owner

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do

But actually no 😅🤣

The idea which made me tempted to try an ancestral version initially was to change seed in the internal steps to get some wiggling in the prediction and make more use of the distance weights. Currently I'm trying this but I'm never sure about the dosage of noise. So rather than shortening it (ETA at 1 currently gives blurry results with my modification) wrongly I figured it would be better to ask you :)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@blepping@Extraltodeus
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Add ancestral sampling and advanced node by blepping · Pull Request #7 · Extraltodeus/DistanceSampler · GitHub
Skip to content

Add ancestral sampling and advanced node - #7

Merged
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral
Jun 19, 2025
Merged

Add ancestral sampling and advanced node#7
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral

Conversation

@blepping

Copy link
Copy Markdown
Contributor

This pull adds ancestral sampling support as well as an advanced node that exposes the various settings (and allows setting ETA to enable ancestral sampling). The ancestral sampling side works for both flow and non-flow models and was tested on SD 1.5, Wan, Flux, and Cosmos Predict2. These changes should not affect results when ancestral sampling isn't enabled.

I tried to keep these changes minimal and use your code style when possible but a little refactoring was necessary. I also expanded your first_only option to allow setting the start/end step ranges for distance sampling.

There's an experimental option to use ancestralness in the internal distance steps as well. Interesting, it works pretty well with flow models (doesn't seem as good with non-flow). Example with Flux, no ancestral sampling:

image

vs with these parameters (previous generation was the same, just with both ETA parameters set to 0):

image

image

Hopefully this pull is along the lines of something you'd be interested in merging. If you need anything changed, please let me know!

@Extraltodeus

Extraltodeus commented Jun 19, 2025

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

I had given up after messing up the scaling but I feel that it could help with selecting better values.

@Extraltodeus
Extraltodeus merged commit 49c35d0 into Extraltodeus:mainJun 19, 2025
@blepping

Copy link
Copy Markdown
ContributorAuthor

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

@Extraltodeus

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

Oh :D

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

@Extraltodeus

Copy link
Copy Markdown
Owner

If I wanted to add it as ancestral in the preset list which setting would you recommand?

@blepping

Copy link
Copy Markdown
ContributorAuthor

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

Ah, I see. It can be sort of complicated for flow models, so maybe that was the issue. In any case, it works now (I hope!) so not really something you need to worry about anymore.

If I wanted to add it as ancestral in the preset list which setting would you recommand?

Most ancestral samplers just use eta=1.0, so you could do that. Or eta=0.5 for a milder ancestral effect. Ancestralness on the distance steps (distance_step_eta) is an experimental option and have weird results, if it was me I'd probably just let people enable that manually via the advanced node if they wanted to use it. It might not be worth making a preset for. If you do, probably try some relatively low value like 0.2 which may be enough to notice but not break stuff.

@Extraltodeus

Copy link
Copy Markdown
Owner

(forgot to say thanks ^^)

@Extraltodeus

Extraltodeus commented Jul 2, 2025

Copy link
Copy Markdown
Owner

I was trying around and I wonder about something. Since you mentionned not having good results with non-flow models for the internal steps I got to wonder if maybe this line (at line 163):

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=distance_step_eta if use_distance_eta else 0.0, is_rf=is_rf)

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

Because if I change it to:

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=(distance_step_eta * (resample_steps - 1) / resample_steps) if use_distance_eta else 0.0, is_rf=is_rf)

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

What is your opinion?

@blepping

Copy link
Copy Markdown
ContributorAuthor

Sorry about the slow reply!

Since you mentionned not having good results with non-flow models for the internal steps

Ahh, I see I phrased that part poorly and even left out a word. What I meant was that it can have weird results and requires some tweaking. I don't think it's necessarily bad, though 1.0 ETA on those steps may generally be too much.

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do, I'm just decent at implementing this sort of stuff from an existing reference.

It makes sense that noise addition on internal distance steps would have a strong effect since intuitively it seems like this would be compounding the effect of ETA. One way to deal with that would be just to set a low ETA manually (the approach I used). Scaling it based on the internal steps seems like something that should work also.

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

Using that approach, do you still see a noticeable difference between using ETA for the internal steps vs just leaving it at 0? If so, then sounds like a good idea! Like I said though, your judgement for this stuff is probably better than mine so I'd be inclined to just defer to whatever approach you think works best.

@Extraltodeus

Extraltodeus commented Jul 9, 2025

Copy link
Copy Markdown
Owner

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do

But actually no 😅🤣

The idea which made me tempted to try an ancestral version initially was to change seed in the internal steps to get some wiggling in the prediction and make more use of the distance weights. Currently I'm trying this but I'm never sure about the dosage of noise. So rather than shortening it (ETA at 1 currently gives blurry results with my modification) wrongly I figured it would be better to ask you :)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@blepping@Extraltodeus
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add ancestral sampling and advanced node by blepping · Pull Request #7 · Extraltodeus/DistanceSampler · GitHub
Skip to content

Add ancestral sampling and advanced node - #7

Merged
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral
Jun 19, 2025
Merged

Add ancestral sampling and advanced node#7
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral

Conversation

@blepping

Copy link
Copy Markdown
Contributor

This pull adds ancestral sampling support as well as an advanced node that exposes the various settings (and allows setting ETA to enable ancestral sampling). The ancestral sampling side works for both flow and non-flow models and was tested on SD 1.5, Wan, Flux, and Cosmos Predict2. These changes should not affect results when ancestral sampling isn't enabled.

I tried to keep these changes minimal and use your code style when possible but a little refactoring was necessary. I also expanded your first_only option to allow setting the start/end step ranges for distance sampling.

There's an experimental option to use ancestralness in the internal distance steps as well. Interesting, it works pretty well with flow models (doesn't seem as good with non-flow). Example with Flux, no ancestral sampling:

image

vs with these parameters (previous generation was the same, just with both ETA parameters set to 0):

image

image

Hopefully this pull is along the lines of something you'd be interested in merging. If you need anything changed, please let me know!

@Extraltodeus

Extraltodeus commented Jun 19, 2025

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

I had given up after messing up the scaling but I feel that it could help with selecting better values.

@Extraltodeus
Extraltodeus merged commit 49c35d0 into Extraltodeus:mainJun 19, 2025
@blepping

Copy link
Copy Markdown
ContributorAuthor

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

@Extraltodeus

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

Oh :D

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

@Extraltodeus

Copy link
Copy Markdown
Owner

If I wanted to add it as ancestral in the preset list which setting would you recommand?

@blepping

Copy link
Copy Markdown
ContributorAuthor

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

Ah, I see. It can be sort of complicated for flow models, so maybe that was the issue. In any case, it works now (I hope!) so not really something you need to worry about anymore.

If I wanted to add it as ancestral in the preset list which setting would you recommand?

Most ancestral samplers just use eta=1.0, so you could do that. Or eta=0.5 for a milder ancestral effect. Ancestralness on the distance steps (distance_step_eta) is an experimental option and have weird results, if it was me I'd probably just let people enable that manually via the advanced node if they wanted to use it. It might not be worth making a preset for. If you do, probably try some relatively low value like 0.2 which may be enough to notice but not break stuff.

@Extraltodeus

Copy link
Copy Markdown
Owner

(forgot to say thanks ^^)

@Extraltodeus

Extraltodeus commented Jul 2, 2025

Copy link
Copy Markdown
Owner

I was trying around and I wonder about something. Since you mentionned not having good results with non-flow models for the internal steps I got to wonder if maybe this line (at line 163):

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=distance_step_eta if use_distance_eta else 0.0, is_rf=is_rf)

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

Because if I change it to:

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=(distance_step_eta * (resample_steps - 1) / resample_steps) if use_distance_eta else 0.0, is_rf=is_rf)

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

What is your opinion?

@blepping

Copy link
Copy Markdown
ContributorAuthor

Sorry about the slow reply!

Since you mentionned not having good results with non-flow models for the internal steps

Ahh, I see I phrased that part poorly and even left out a word. What I meant was that it can have weird results and requires some tweaking. I don't think it's necessarily bad, though 1.0 ETA on those steps may generally be too much.

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do, I'm just decent at implementing this sort of stuff from an existing reference.

It makes sense that noise addition on internal distance steps would have a strong effect since intuitively it seems like this would be compounding the effect of ETA. One way to deal with that would be just to set a low ETA manually (the approach I used). Scaling it based on the internal steps seems like something that should work also.

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

Using that approach, do you still see a noticeable difference between using ETA for the internal steps vs just leaving it at 0? If so, then sounds like a good idea! Like I said though, your judgement for this stuff is probably better than mine so I'd be inclined to just defer to whatever approach you think works best.

@Extraltodeus

Extraltodeus commented Jul 9, 2025

Copy link
Copy Markdown
Owner

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do

But actually no 😅🤣

The idea which made me tempted to try an ancestral version initially was to change seed in the internal steps to get some wiggling in the prediction and make more use of the distance weights. Currently I'm trying this but I'm never sure about the dosage of noise. So rather than shortening it (ETA at 1 currently gives blurry results with my modification) wrongly I figured it would be better to ask you :)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@blepping@Extraltodeus
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add ancestral sampling and advanced node by blepping · Pull Request #7 · Extraltodeus/DistanceSampler · GitHub
Skip to content

Add ancestral sampling and advanced node - #7

Merged
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral
Jun 19, 2025
Merged

Add ancestral sampling and advanced node#7
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral

Conversation

@blepping

Copy link
Copy Markdown
Contributor

This pull adds ancestral sampling support as well as an advanced node that exposes the various settings (and allows setting ETA to enable ancestral sampling). The ancestral sampling side works for both flow and non-flow models and was tested on SD 1.5, Wan, Flux, and Cosmos Predict2. These changes should not affect results when ancestral sampling isn't enabled.

I tried to keep these changes minimal and use your code style when possible but a little refactoring was necessary. I also expanded your first_only option to allow setting the start/end step ranges for distance sampling.

There's an experimental option to use ancestralness in the internal distance steps as well. Interesting, it works pretty well with flow models (doesn't seem as good with non-flow). Example with Flux, no ancestral sampling:

image

vs with these parameters (previous generation was the same, just with both ETA parameters set to 0):

image

image

Hopefully this pull is along the lines of something you'd be interested in merging. If you need anything changed, please let me know!

@Extraltodeus

Extraltodeus commented Jun 19, 2025

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

I had given up after messing up the scaling but I feel that it could help with selecting better values.

@Extraltodeus
Extraltodeus merged commit 49c35d0 into Extraltodeus:mainJun 19, 2025
@blepping

Copy link
Copy Markdown
ContributorAuthor

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

@Extraltodeus

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

Oh :D

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

@Extraltodeus

Copy link
Copy Markdown
Owner

If I wanted to add it as ancestral in the preset list which setting would you recommand?

@blepping

Copy link
Copy Markdown
ContributorAuthor

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

Ah, I see. It can be sort of complicated for flow models, so maybe that was the issue. In any case, it works now (I hope!) so not really something you need to worry about anymore.

If I wanted to add it as ancestral in the preset list which setting would you recommand?

Most ancestral samplers just use eta=1.0, so you could do that. Or eta=0.5 for a milder ancestral effect. Ancestralness on the distance steps (distance_step_eta) is an experimental option and have weird results, if it was me I'd probably just let people enable that manually via the advanced node if they wanted to use it. It might not be worth making a preset for. If you do, probably try some relatively low value like 0.2 which may be enough to notice but not break stuff.

@Extraltodeus

Copy link
Copy Markdown
Owner

(forgot to say thanks ^^)

@Extraltodeus

Extraltodeus commented Jul 2, 2025

Copy link
Copy Markdown
Owner

I was trying around and I wonder about something. Since you mentionned not having good results with non-flow models for the internal steps I got to wonder if maybe this line (at line 163):

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=distance_step_eta if use_distance_eta else 0.0, is_rf=is_rf)

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

Because if I change it to:

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=(distance_step_eta * (resample_steps - 1) / resample_steps) if use_distance_eta else 0.0, is_rf=is_rf)

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

What is your opinion?

@blepping

Copy link
Copy Markdown
ContributorAuthor

Sorry about the slow reply!

Since you mentionned not having good results with non-flow models for the internal steps

Ahh, I see I phrased that part poorly and even left out a word. What I meant was that it can have weird results and requires some tweaking. I don't think it's necessarily bad, though 1.0 ETA on those steps may generally be too much.

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do, I'm just decent at implementing this sort of stuff from an existing reference.

It makes sense that noise addition on internal distance steps would have a strong effect since intuitively it seems like this would be compounding the effect of ETA. One way to deal with that would be just to set a low ETA manually (the approach I used). Scaling it based on the internal steps seems like something that should work also.

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

Using that approach, do you still see a noticeable difference between using ETA for the internal steps vs just leaving it at 0? If so, then sounds like a good idea! Like I said though, your judgement for this stuff is probably better than mine so I'd be inclined to just defer to whatever approach you think works best.

@Extraltodeus

Extraltodeus commented Jul 9, 2025

Copy link
Copy Markdown
Owner

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do

But actually no 😅🤣

The idea which made me tempted to try an ancestral version initially was to change seed in the internal steps to get some wiggling in the prediction and make more use of the distance weights. Currently I'm trying this but I'm never sure about the dosage of noise. So rather than shortening it (ETA at 1 currently gives blurry results with my modification) wrongly I figured it would be better to ask you :)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@blepping@Extraltodeus
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Add ancestral sampling and advanced node by blepping · Pull Request #7 · Extraltodeus/DistanceSampler · GitHub
Skip to content

Add ancestral sampling and advanced node - #7

Merged
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral
Jun 19, 2025
Merged

Add ancestral sampling and advanced node#7
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral

Conversation

@blepping

Copy link
Copy Markdown
Contributor

This pull adds ancestral sampling support as well as an advanced node that exposes the various settings (and allows setting ETA to enable ancestral sampling). The ancestral sampling side works for both flow and non-flow models and was tested on SD 1.5, Wan, Flux, and Cosmos Predict2. These changes should not affect results when ancestral sampling isn't enabled.

I tried to keep these changes minimal and use your code style when possible but a little refactoring was necessary. I also expanded your first_only option to allow setting the start/end step ranges for distance sampling.

There's an experimental option to use ancestralness in the internal distance steps as well. Interesting, it works pretty well with flow models (doesn't seem as good with non-flow). Example with Flux, no ancestral sampling:

image

vs with these parameters (previous generation was the same, just with both ETA parameters set to 0):

image

image

Hopefully this pull is along the lines of something you'd be interested in merging. If you need anything changed, please let me know!

@Extraltodeus

Extraltodeus commented Jun 19, 2025

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

I had given up after messing up the scaling but I feel that it could help with selecting better values.

@Extraltodeus
Extraltodeus merged commit 49c35d0 into Extraltodeus:mainJun 19, 2025
@blepping

Copy link
Copy Markdown
ContributorAuthor

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

@Extraltodeus

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

Oh :D

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

@Extraltodeus

Copy link
Copy Markdown
Owner

If I wanted to add it as ancestral in the preset list which setting would you recommand?

@blepping

Copy link
Copy Markdown
ContributorAuthor

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

Ah, I see. It can be sort of complicated for flow models, so maybe that was the issue. In any case, it works now (I hope!) so not really something you need to worry about anymore.

If I wanted to add it as ancestral in the preset list which setting would you recommand?

Most ancestral samplers just use eta=1.0, so you could do that. Or eta=0.5 for a milder ancestral effect. Ancestralness on the distance steps (distance_step_eta) is an experimental option and have weird results, if it was me I'd probably just let people enable that manually via the advanced node if they wanted to use it. It might not be worth making a preset for. If you do, probably try some relatively low value like 0.2 which may be enough to notice but not break stuff.

@Extraltodeus

Copy link
Copy Markdown
Owner

(forgot to say thanks ^^)

@Extraltodeus

Extraltodeus commented Jul 2, 2025

Copy link
Copy Markdown
Owner

I was trying around and I wonder about something. Since you mentionned not having good results with non-flow models for the internal steps I got to wonder if maybe this line (at line 163):

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=distance_step_eta if use_distance_eta else 0.0, is_rf=is_rf)

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

Because if I change it to:

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=(distance_step_eta * (resample_steps - 1) / resample_steps) if use_distance_eta else 0.0, is_rf=is_rf)

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

What is your opinion?

@blepping

Copy link
Copy Markdown
ContributorAuthor

Sorry about the slow reply!

Since you mentionned not having good results with non-flow models for the internal steps

Ahh, I see I phrased that part poorly and even left out a word. What I meant was that it can have weird results and requires some tweaking. I don't think it's necessarily bad, though 1.0 ETA on those steps may generally be too much.

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do, I'm just decent at implementing this sort of stuff from an existing reference.

It makes sense that noise addition on internal distance steps would have a strong effect since intuitively it seems like this would be compounding the effect of ETA. One way to deal with that would be just to set a low ETA manually (the approach I used). Scaling it based on the internal steps seems like something that should work also.

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

Using that approach, do you still see a noticeable difference between using ETA for the internal steps vs just leaving it at 0? If so, then sounds like a good idea! Like I said though, your judgement for this stuff is probably better than mine so I'd be inclined to just defer to whatever approach you think works best.

@Extraltodeus

Extraltodeus commented Jul 9, 2025

Copy link
Copy Markdown
Owner

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do

But actually no 😅🤣

The idea which made me tempted to try an ancestral version initially was to change seed in the internal steps to get some wiggling in the prediction and make more use of the distance weights. Currently I'm trying this but I'm never sure about the dosage of noise. So rather than shortening it (ETA at 1 currently gives blurry results with my modification) wrongly I figured it would be better to ask you :)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@blepping@Extraltodeus
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add ancestral sampling and advanced node by blepping · Pull Request #7 · Extraltodeus/DistanceSampler · GitHub
Skip to content

Add ancestral sampling and advanced node - #7

Merged
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral
Jun 19, 2025
Merged

Add ancestral sampling and advanced node#7
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral

Conversation

@blepping

Copy link
Copy Markdown
Contributor

This pull adds ancestral sampling support as well as an advanced node that exposes the various settings (and allows setting ETA to enable ancestral sampling). The ancestral sampling side works for both flow and non-flow models and was tested on SD 1.5, Wan, Flux, and Cosmos Predict2. These changes should not affect results when ancestral sampling isn't enabled.

I tried to keep these changes minimal and use your code style when possible but a little refactoring was necessary. I also expanded your first_only option to allow setting the start/end step ranges for distance sampling.

There's an experimental option to use ancestralness in the internal distance steps as well. Interesting, it works pretty well with flow models (doesn't seem as good with non-flow). Example with Flux, no ancestral sampling:

image

vs with these parameters (previous generation was the same, just with both ETA parameters set to 0):

image

image

Hopefully this pull is along the lines of something you'd be interested in merging. If you need anything changed, please let me know!

@Extraltodeus

Extraltodeus commented Jun 19, 2025

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

I had given up after messing up the scaling but I feel that it could help with selecting better values.

@Extraltodeus
Extraltodeus merged commit 49c35d0 into Extraltodeus:mainJun 19, 2025
@blepping

Copy link
Copy Markdown
ContributorAuthor

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

@Extraltodeus

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

Oh :D

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

@Extraltodeus

Copy link
Copy Markdown
Owner

If I wanted to add it as ancestral in the preset list which setting would you recommand?

@blepping

Copy link
Copy Markdown
ContributorAuthor

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

Ah, I see. It can be sort of complicated for flow models, so maybe that was the issue. In any case, it works now (I hope!) so not really something you need to worry about anymore.

If I wanted to add it as ancestral in the preset list which setting would you recommand?

Most ancestral samplers just use eta=1.0, so you could do that. Or eta=0.5 for a milder ancestral effect. Ancestralness on the distance steps (distance_step_eta) is an experimental option and have weird results, if it was me I'd probably just let people enable that manually via the advanced node if they wanted to use it. It might not be worth making a preset for. If you do, probably try some relatively low value like 0.2 which may be enough to notice but not break stuff.

@Extraltodeus

Copy link
Copy Markdown
Owner

(forgot to say thanks ^^)

@Extraltodeus

Extraltodeus commented Jul 2, 2025

Copy link
Copy Markdown
Owner

I was trying around and I wonder about something. Since you mentionned not having good results with non-flow models for the internal steps I got to wonder if maybe this line (at line 163):

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=distance_step_eta if use_distance_eta else 0.0, is_rf=is_rf)

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

Because if I change it to:

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=(distance_step_eta * (resample_steps - 1) / resample_steps) if use_distance_eta else 0.0, is_rf=is_rf)

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

What is your opinion?

@blepping

Copy link
Copy Markdown
ContributorAuthor

Sorry about the slow reply!

Since you mentionned not having good results with non-flow models for the internal steps

Ahh, I see I phrased that part poorly and even left out a word. What I meant was that it can have weird results and requires some tweaking. I don't think it's necessarily bad, though 1.0 ETA on those steps may generally be too much.

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do, I'm just decent at implementing this sort of stuff from an existing reference.

It makes sense that noise addition on internal distance steps would have a strong effect since intuitively it seems like this would be compounding the effect of ETA. One way to deal with that would be just to set a low ETA manually (the approach I used). Scaling it based on the internal steps seems like something that should work also.

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

Using that approach, do you still see a noticeable difference between using ETA for the internal steps vs just leaving it at 0? If so, then sounds like a good idea! Like I said though, your judgement for this stuff is probably better than mine so I'd be inclined to just defer to whatever approach you think works best.

@Extraltodeus

Extraltodeus commented Jul 9, 2025

Copy link
Copy Markdown
Owner

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do

But actually no 😅🤣

The idea which made me tempted to try an ancestral version initially was to change seed in the internal steps to get some wiggling in the prediction and make more use of the distance weights. Currently I'm trying this but I'm never sure about the dosage of noise. So rather than shortening it (ETA at 1 currently gives blurry results with my modification) wrongly I figured it would be better to ask you :)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@blepping@Extraltodeus
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add ancestral sampling and advanced node by blepping · Pull Request #7 · Extraltodeus/DistanceSampler · GitHub
Skip to content

Add ancestral sampling and advanced node - #7

Merged
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral
Jun 19, 2025
Merged

Add ancestral sampling and advanced node#7
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral

Conversation

@blepping

Copy link
Copy Markdown
Contributor

This pull adds ancestral sampling support as well as an advanced node that exposes the various settings (and allows setting ETA to enable ancestral sampling). The ancestral sampling side works for both flow and non-flow models and was tested on SD 1.5, Wan, Flux, and Cosmos Predict2. These changes should not affect results when ancestral sampling isn't enabled.

I tried to keep these changes minimal and use your code style when possible but a little refactoring was necessary. I also expanded your first_only option to allow setting the start/end step ranges for distance sampling.

There's an experimental option to use ancestralness in the internal distance steps as well. Interesting, it works pretty well with flow models (doesn't seem as good with non-flow). Example with Flux, no ancestral sampling:

image

vs with these parameters (previous generation was the same, just with both ETA parameters set to 0):

image

image

Hopefully this pull is along the lines of something you'd be interested in merging. If you need anything changed, please let me know!

@Extraltodeus

Extraltodeus commented Jun 19, 2025

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

I had given up after messing up the scaling but I feel that it could help with selecting better values.

@Extraltodeus
Extraltodeus merged commit 49c35d0 into Extraltodeus:mainJun 19, 2025
@blepping

Copy link
Copy Markdown
ContributorAuthor

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

@Extraltodeus

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

Oh :D

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

@Extraltodeus

Copy link
Copy Markdown
Owner

If I wanted to add it as ancestral in the preset list which setting would you recommand?

@blepping

Copy link
Copy Markdown
ContributorAuthor

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

Ah, I see. It can be sort of complicated for flow models, so maybe that was the issue. In any case, it works now (I hope!) so not really something you need to worry about anymore.

If I wanted to add it as ancestral in the preset list which setting would you recommand?

Most ancestral samplers just use eta=1.0, so you could do that. Or eta=0.5 for a milder ancestral effect. Ancestralness on the distance steps (distance_step_eta) is an experimental option and have weird results, if it was me I'd probably just let people enable that manually via the advanced node if they wanted to use it. It might not be worth making a preset for. If you do, probably try some relatively low value like 0.2 which may be enough to notice but not break stuff.

@Extraltodeus

Copy link
Copy Markdown
Owner

(forgot to say thanks ^^)

@Extraltodeus

Extraltodeus commented Jul 2, 2025

Copy link
Copy Markdown
Owner

I was trying around and I wonder about something. Since you mentionned not having good results with non-flow models for the internal steps I got to wonder if maybe this line (at line 163):

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=distance_step_eta if use_distance_eta else 0.0, is_rf=is_rf)

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

Because if I change it to:

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=(distance_step_eta * (resample_steps - 1) / resample_steps) if use_distance_eta else 0.0, is_rf=is_rf)

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

What is your opinion?

@blepping

Copy link
Copy Markdown
ContributorAuthor

Sorry about the slow reply!

Since you mentionned not having good results with non-flow models for the internal steps

Ahh, I see I phrased that part poorly and even left out a word. What I meant was that it can have weird results and requires some tweaking. I don't think it's necessarily bad, though 1.0 ETA on those steps may generally be too much.

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do, I'm just decent at implementing this sort of stuff from an existing reference.

It makes sense that noise addition on internal distance steps would have a strong effect since intuitively it seems like this would be compounding the effect of ETA. One way to deal with that would be just to set a low ETA manually (the approach I used). Scaling it based on the internal steps seems like something that should work also.

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

Using that approach, do you still see a noticeable difference between using ETA for the internal steps vs just leaving it at 0? If so, then sounds like a good idea! Like I said though, your judgement for this stuff is probably better than mine so I'd be inclined to just defer to whatever approach you think works best.

@Extraltodeus

Extraltodeus commented Jul 9, 2025

Copy link
Copy Markdown
Owner

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do

But actually no 😅🤣

The idea which made me tempted to try an ancestral version initially was to change seed in the internal steps to get some wiggling in the prediction and make more use of the distance weights. Currently I'm trying this but I'm never sure about the dosage of noise. So rather than shortening it (ETA at 1 currently gives blurry results with my modification) wrongly I figured it would be better to ask you :)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@blepping@Extraltodeus
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Add ancestral sampling and advanced node by blepping · Pull Request #7 · Extraltodeus/DistanceSampler · GitHub
Skip to content

Add ancestral sampling and advanced node - #7

Merged
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral
Jun 19, 2025
Merged

Add ancestral sampling and advanced node#7
Extraltodeus merged 2 commits into
Extraltodeus:mainfrom
blepping:feat_ancestral

Conversation

@blepping

Copy link
Copy Markdown
Contributor

This pull adds ancestral sampling support as well as an advanced node that exposes the various settings (and allows setting ETA to enable ancestral sampling). The ancestral sampling side works for both flow and non-flow models and was tested on SD 1.5, Wan, Flux, and Cosmos Predict2. These changes should not affect results when ancestral sampling isn't enabled.

I tried to keep these changes minimal and use your code style when possible but a little refactoring was necessary. I also expanded your first_only option to allow setting the start/end step ranges for distance sampling.

There's an experimental option to use ancestralness in the internal distance steps as well. Interesting, it works pretty well with flow models (doesn't seem as good with non-flow). Example with Flux, no ancestral sampling:

image

vs with these parameters (previous generation was the same, just with both ETA parameters set to 0):

image

image

Hopefully this pull is along the lines of something you'd be interested in merging. If you need anything changed, please let me know!

@Extraltodeus

Extraltodeus commented Jun 19, 2025

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

I had given up after messing up the scaling but I feel that it could help with selecting better values.

@Extraltodeus
Extraltodeus merged commit 49c35d0 into Extraltodeus:mainJun 19, 2025
@blepping

Copy link
Copy Markdown
ContributorAuthor

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

@Extraltodeus

Copy link
Copy Markdown
Owner

Absolutey amazing!!!! Thank you!!!!

Not a problem! You're one of the few people doing fun experimental stuff and I've had fun playing with your toys. Glad to give something back.

Oh :D

I had given up after messing up the scaling but I feel that it could help with selecting better values.

Do you mean getting ancestral stuff to work at all or something else?

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

@Extraltodeus

Copy link
Copy Markdown
Owner

If I wanted to add it as ancestral in the preset list which setting would you recommand?

@blepping

Copy link
Copy Markdown
ContributorAuthor

I don't remember much really. It's was about the scaling and how it worked. I'll admit I barely gave it a try, saw I was getting noise as an output and went back into the sampler's logic itself.

Ah, I see. It can be sort of complicated for flow models, so maybe that was the issue. In any case, it works now (I hope!) so not really something you need to worry about anymore.

If I wanted to add it as ancestral in the preset list which setting would you recommand?

Most ancestral samplers just use eta=1.0, so you could do that. Or eta=0.5 for a milder ancestral effect. Ancestralness on the distance steps (distance_step_eta) is an experimental option and have weird results, if it was me I'd probably just let people enable that manually via the advanced node if they wanted to use it. It might not be worth making a preset for. If you do, probably try some relatively low value like 0.2 which may be enough to notice but not break stuff.

@Extraltodeus

Copy link
Copy Markdown
Owner

(forgot to say thanks ^^)

@Extraltodeus

Extraltodeus commented Jul 2, 2025

Copy link
Copy Markdown
Owner

I was trying around and I wonder about something. Since you mentionned not having good results with non-flow models for the internal steps I got to wonder if maybe this line (at line 163):

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=distance_step_eta if use_distance_eta else 0.0, is_rf=is_rf)

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

Because if I change it to:

dstep_sigma_down, dstep_sigma_up, dstep_x_coeff = get_ancestral_step_ext(sigma, sigma_next, eta=(distance_step_eta * (resample_steps - 1) / resample_steps) if use_distance_eta else 0.0, is_rf=is_rf)

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

What is your opinion?

@blepping

Copy link
Copy Markdown
ContributorAuthor

Sorry about the slow reply!

Since you mentionned not having good results with non-flow models for the internal steps

Ahh, I see I phrased that part poorly and even left out a word. What I meant was that it can have weird results and requires some tweaking. I don't think it's necessarily bad, though 1.0 ETA on those steps may generally be too much.

Did not take into account that the first internal step is euler and so should be readjusted regarding this? I could widely be wrong since I'm now getting only the half of it but I figured I would ask rather than trying without really understanding.

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do, I'm just decent at implementing this sort of stuff from an existing reference.

It makes sense that noise addition on internal distance steps would have a strong effect since intuitively it seems like this would be compounding the effect of ETA. One way to deal with that would be just to set a low ETA manually (the approach I used). Scaling it based on the internal steps seems like something that should work also.

I can set all ancestral-related settings to 1 and get an image while without the modification I get a confetti cannon.

Using that approach, do you still see a noticeable difference between using ETA for the internal steps vs just leaving it at 0? If so, then sounds like a good idea! Like I said though, your judgement for this stuff is probably better than mine so I'd be inclined to just defer to whatever approach you think works best.

@Extraltodeus

Extraltodeus commented Jul 9, 2025

Copy link
Copy Markdown
Owner

To be honest, I don't really understand it either. :) You almost certainly understand the math behind sampling/noise addition better than I do

But actually no 😅🤣

The idea which made me tempted to try an ancestral version initially was to change seed in the internal steps to get some wiggling in the prediction and make more use of the distance weights. Currently I'm trying this but I'm never sure about the dosage of noise. So rather than shortening it (ETA at 1 currently gives blurry results with my modification) wrongly I figured it would be better to ask you :)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@blepping@Extraltodeus