r/StableDiffusion • • 4d ago

No Workflow Self-Refining Sampler+

https://github.com/Alex240z/ComfyUI-SelfRefiningSamplerPlus
Before/After
Before/After
Before/After
After

Based on: https://arxiv.org/html/2601.18577v1 and builds on pre-existing work by Kijai (The SamplerSelfRefineVideo Node).

I have found that Minimax H3-Image loves the Self-Refining Sampler. Seeing this, I spun up an improved version (SRS+) that is compatible with sampling methods besides Euler, has more easily adjustable sub-step and perturb amounts per step.
It seems to significantly improve the model's ability to resolve fine details, especially when combined with the "Empty-Image Trick" I shared previously (if using T2V). One place this is evident are patterns like fishnet, lace, sequins and other challenging fabrics/textiles. It seems to improve line-art for anime/illustration styles, and can often fix self-correct body-horror deformities.

As a starting point, try running it from steps 2-4 with 3 sub-steps and an uncertainty threshold of 0.03. But I'm much more curious what settings you try and results you get with them. Since it does sub-step, it increases gen time but I think it is well worth it.

I've tested it less with video, but it has shown promise there, too.

Just socket this chungus into a SamplerCustomAdvanced like any other sampler. Let me know if you have any issues, or what kind of results you get.

152 Upvotes

70 comments sorted by

18

u/ninjazombiemaster 4d ago

Video example of it fixing a Pika H3 gen using the paper's preset:
https://imglink.cc/cdn/8oCs6N3f93.mp4

0

u/[deleted] 4d ago

[deleted] — view deleted comment

7

u/a-ijoe 4d ago

it's got 3 legs in the first one.

1

u/Diabolicor 4d ago

If you take a look at the original paper it's a technique for self-correcting physics dynamics, motion and physical realism without additional model training.

7

u/VasaFromParadise 4d ago edited 4d ago

threshold of 0.03
My image changes dramatically after this method. Has anyone figured out why yet? Or is it just me?
PS. perturb_strength_scale - must be less than 1, otherwise the image changes significantly.

4

u/ninjazombiemaster 4d ago

It's like SDE samplers, it injects nose at each substep. You can reduce this by doing fewer substeps, waiting til later to engage them so the image is more locked in, or decreasing the perturbation strength. 

3

u/VasaFromParadise 4d ago

Something like this?)

3

u/ninjazombiemaster 3d ago

Yes, but definitely keep experimenting too. 

12

u/Dante_77A 4d ago edited 4d ago

Interestingly, these fishnet outfits usually glitch on most models if the character isn’t close to the camera.

But note that the girl’s face has been drastically altered 

8

u/ninjazombiemaster 4d ago edited 4d ago

This is to be expected, due to the spatial compression of the VAE. But In the case of H3 it also just doesn't seem to get enough time with the 6 steps to resolve these details, and simply increasing step count or using higher order samplers normally seems to destroy the image. But for some reason, the SRS substeps do not degrade it.

As for the face alteration, it is injecting noise so this also expected depending on the settings. You can tune the strength and time steps. This was t2i so no ref - neither face can be judged for accuracy. 

3

u/Dunc4n1d4h0 3d ago

You noticed face change, but what about hand repair?

9

u/YeahlDid 4d ago

Pretty neat stuff, thank you. About how much does this add to generate time?

2

u/ninjazombiemaster 4d ago

Depends on how you configure the sub-stepping. You control when and how many. It could barely add any time or double it. 

6

u/JorG941 4d ago

Is this aplicable on other models?

5

u/ninjazombiemaster 4d ago

Yes, it can be used with other video and image models. 

1

u/JorG941 3d ago

What about image only models?

1

u/ninjazombiemaster 3d ago

It is compatible with practically any model, but some might not work as well as H3 does.

3

u/alwaysbeblepping 4d ago edited 3d ago

This sounds like a very similar concept to restart sampling, although generally restart run multiple steps before jumping back to a previous sigma and wasn't used near max sigma. I actually have a node in my Overly Complicated Sampling node pack (SimpleRestartSchedule) that lets you define a schedule like run a step, jump back a step, run a step, jump back a step however many times you want. (It does require a restart-aware sampler to actually consume the schedule.)

(1.0 - sigma) * denoised + sigma * eps_mix - Idea for a drinking game. Take a shot whenever you find a manual implementation of torch.lerp in a custom node or ComfyUI source. Make sure your will is in order because you are definitely dying of alcohol poisoning before you get past a few modules.

1

u/ninjazombiemaster 3d ago

Indeed. For some reason though H3-image seems much more tolerant of the substeps from this approach than it is of regular res, or various multi-step or higher order sampling I've tried. 

Also lol. 

1

u/alwaysbeblepping 3d ago

For some reason though H3-image seems much more tolerant of the substeps from this approach than it is of regular res[tarts, I assume]

Actually, looking at the code there is a significant difference in the normal branch. Restart noises the latent back up to a specific sigma but preserves all the existing noise as well as the partially denoised image part. Your normal branch seems to be doing a LCM/pingping step (just to the same sigma) so all the noise gets replaced.

I've heard people talk about LCM being good for low step models. I actually don't doubt it but I also understand why that would be the case. The whole idea of low-step is a straight path to the clean image, it seems like replacing 100% of the noise is the most disruptive thing you could do.

Also lol.

There really is a reason to prefer using torch.lerp to manually reinventing it, though. :) Especially that version which requires two multiplications on your large video tensors and an addition. It also can be written as (eps_mix - denoised) * sigma + denoised with only one multiplication and less intermediate values (or (eps_mix - denoised).mul_(sigma).add_(denoised) for the in-place version). torch.lerp(denoised, eps_mix, sigma) can use an optimized kernel, possibly use in-place operations internally (lowering how much peak VRAM you need and maybe decreasing memory fragmentation).

Optimizing latent twiddling doesn't matter a lot of the time but video latents actually can be big enough to notice a difference. Doing the math differently can (sometimes) change seeds slightly so there's an argument for not doing something like going into ComfyUI and replacing all the existing manual LERP implementations but if you're making a new node...

That's my opinion, anyway, which you didn't ask for but got all the same!

2

u/ninjazombiemaster 3d ago

Fair enough. It's a trivial enough change to make anyway, whether it ends up being impactful or not.

2

u/ninjazombiemaster 3d ago

The node is now live on the Comfy Registry for easier access.

2

u/Entrypointjip 2d ago

I been using it with MOSS SFT with turbo LoRA 8 steps, when you use this you can lower the steps to 6 to recover some of the lost speed.

1

u/ninjazombiemaster 2d ago

What settings in the sampler have you been using? I haven't had much luck in moss with it yet.

1

u/Entrypointjip 2d ago

I Just stole the one someone posted here since at first I didn't understand exactly what was what.

4

u/ninjazombiemaster 2d ago

Substeps per step is how many times to run the refinement. Perturb is how much to alter the image on each refinement pass. By avoiding early steps and keeping noise values low on early stages, the overall composition is mostly preserved.

2

u/Rude-Advantage-22 2d ago

Man, am I just stupid, or how the heck do you wire this thing up? Does it go in front of the KSamper? None of the sockets seem to line up unless I add another SamplerCustomAdvanced, but then I've no clue what to do with that node's required Guide/Sigma/Noise/etc. Any more documentation I'm missing, u/ninjazombiemaster ?

3

u/ninjazombiemaster 2d ago

Sampler Custom Advanced Takes the Inputs
RandomNoise > noise
CFG Guider/ Basic Guider > guider (Guider needs model & conditioning)
SRS+ > sampler
BasicScheduler > sigmas (Basic Scheduler needs a connection to the model & step count set)
Whatever Conditioning Node > latent

3

u/nixudos 4d ago

I tried it on a 9 step Ref2video Minimax H3 workflow.
Just the default settings, as I have no idea what to tweak.
It seemed to improve the audio noticeably, but there was one artifact in it. I'm trying to make another test and see if it was just a fluke.

Are there any recommended settings for Minimax video generations?

2

u/ninjazombiemaster 4d ago

I haven't done enough tests with video to really recommend settings.But I would start with the "paper" preset since the original paper was meant for video correction.

2

u/mac404 4d ago edited 4d ago

Interesting, definitely going to try it out!

Loading it up, seems like the defaults baked into the node are different from what you're suggesting to start with in the post here? Any reason why you're setting uncertainty threshold so much lower than the 0.25 node default and running it on one fewer step? And which metric is being used (mean or norm) related to your 0.03 suggestion?

Edit: Okay, a few dumb questions as I try to make sense of the settings:

  • Given the 0 indexing in the node, are you saying you ran with the steps labeled 2-4, or actually the ones labeled 1-3?
  • Are you suggesting to run 1 substep per step for the remaining steps? Or is the correct setting actually 0?
  • Looks like a value of 1.0 for perturb per step follows the paper, so keeping that. But does it matter what those values are set to for steps that don't run any substeps?

2

u/ninjazombiemaster 4d ago

Node defaults were based on the paper and/or Kijais beta node. Honestly I'm hoping people try lots of settings and share their results. The settings I mentioned were the ones used for the example images though. 

Low uw% keeps the refine engaged longer by preventing it from masking as early.   

Yes, the samples were generated with the steps labeled 2,3,4 at 3 and the others at 0. But definitely try other configs too. 

It doesn't matter what is set at if substeps are 0. 

0

u/mac404 4d ago

Thanks for the reply!

Some very initial results are encouraging, but definitely need to try out more combinations of settings to get a feel for things. One thing that seems nice is that ramping up substeps across all steps doesn't seem to meaningfully destroy the image.

2

u/ninjazombiemaster 3d ago

Indeed, that was quite surprising to me and was a major reason I pushed this. Other higher order / multi step samplers seem to destroy the output unless you decrease the step count but with this you can basically un-turbo the model. 

1

u/Fantastic-Client-257 3d ago

This is absolutely brilliant (still testing/tweaking). Huge props.

1

u/Apprehensive_Sky892 3d ago

In the second comparison with the woman wearing the fishnet stocking, her right-hand fingers are complete fixed 😅

1

u/ninjazombiemaster 3d ago

Yes it does a good job of correcting anatomical issues.

1

u/PantInTheCountry 3d ago

Ran into an issue installing this from the ComfyUI Manager.

The node will not install unless explicitly set allow_git_url_install = true in config.ini and ComfyUI launched with a loopback --listen (any 127.x.x.x address, or ::1), or network_mode = personal_cloud in config.ini. (my settings have the more restrictive allow_git_url_install = true and network_mode = public options selected)

Not sure if this is a configuration issue when the node was published or a configuration issue with Comfy/Stability Matrix. No other node has this problem (tested by installing another new node from the manager).

2

u/ninjazombiemaster 3d ago

Are you selecting the versioned release (1.0.0) or the nightly release? Make sure you're on versioned as Comfy should not see it as a risk.

2

u/PantInTheCountry 3d ago

Thanks. I was using the default selection of nightly release. Selecting the versioned 1.0.0 telease did the trick

1

u/jjjnnnxxx 3d ago

Very cool node — I'd love to see it implemented in native Comfy. Maybe you should submit a PR? Also, the widgets are a bit glitchy: they sometimes break node values, and it happens every time I use comfy agent to work with the canvas.

1

u/ninjazombiemaster 3d ago

Kijai has a more basic implementation available in KJnodes. I've also noticed some instability with the widgets, I'll work on it. 

1

u/ninjazombiemaster 1d ago

I've made some changes to the widgets to hopefully improve the stability, let me know if you're still having issues and some more specific details to reproduce.

1

u/Flat_Technology_5325 3d ago

Hmm, I was using this in comfyui yesterday after t installing it with no issues but when I updated comfy today, it kills my UI and it won't load 🤔

1

u/ninjazombiemaster 3d ago

What version of comfyui? 

1

u/Straight-Election963 3d ago

is it normal to take all of that time in generating ?? i mean im using moss like 25 step, and it takes like 2 min, but with connecting this node on 4 steps only it takes like 6 ~ min !! anyway to deduct that time ?

1

u/ninjazombiemaster 3d ago

Can you monitor your vram/ram usage with and without the node? It only slightly increases time for me relative to the number of steps. 

1

u/Calm_Mix_3776 2d ago

Can you kindly post your workflow? For some reason I'm getting worse results with this sampler compared to Euler. :(

1

u/ninjazombiemaster 2d ago

It's just the default workflow with the ksampler replaced with Sampler Custom Advanced and this node. 

If substeps per step are set to 0 this should exactly match Euler. If you're still seeing a different quality with that setting then the issue is elsewhere in your workflow. 

Once you have confirmed the quality matches Euler with the substeps bypassed then try the example settings I posted. 

1

u/Diabolicor 4d ago edited 4d ago

Really interesting paper. Can you describe the config you used for your video tests and did you run it with your Re-Time pass or was it just 1 Pass ?

1

u/ninjazombiemaster 4d ago

That was with the "paper" preset, no re-time. 

1

u/Ill_Resolve8424 4d ago

How to use this in comfy? Looks promising

3

u/ninjazombiemaster 4d ago

You plug it into the "sampler" input of a sampler custom advanced node. 

1

u/Cubey42 3d ago

where can I get the node?

2

u/ninjazombiemaster 3d ago edited 3d ago

Github link at the top of the page, I'll add it to the comfy UI manager soon too. Edit: It is now live on the comfy registry and can be accessed in the custom node manager, too.

5

u/Estwhy 4d ago

Im so dumb, could you provide us a workflow please?

2

u/chimaeraUndying 3d ago

Would you care to share the (Comfy, I'm assuming) workflows for these?

0

u/fallengt 4d ago

Neat, but sampling speed decreases quite a bit. It's not free lunch

4

u/ninjazombiemaster 4d ago

Naturally. But it's worth the wait imo. 

1

u/Cubey42 3d ago

Have to check this out thanks

1

u/physalisx 3d ago

Looks interesting! I will check this out later

0

u/Enshitification 4d ago

I wonder if this would combine well with the Lakonik team's pi-H3 to get better results from their low-step adapters? I'm not near a machine to test it right now, so this is my reminder note.

1

u/ninjazombiemaster 4d ago

I think it would. Of course it also makes them slower so the question becomes how does it compare to higher step options given the same length of time. 

0

u/Silonom3724 4d ago

I tried it. It improves frame to frame variance but mostly because you throw more steps (substeps) at it. It's a trade off quality for more compute. Not a win in my book.

0

u/celialoriaart 4d ago

The difference on the fishnet texture and the hand structure in the "after" shot is wild. Definitely plugging this into my SamplerCustomAdvanced node to test those 2-to-4 step settings!

1

u/ninjazombiemaster 4d ago

Yeah it blew my mind with how much/consistently it was improving things.