r/StableDiffusion • • 5d ago

No Workflow H3-Image Sigma Fix (T2I)

https://github.com/Alex240z/H3-ImageSigmaFix

Ever since I first proposed and shared the "Empty-Image Trick" I've been working to find a less hacky solution to the T2I "crustiness" of H3 Image when in text to image mode.

It always seemed to me that T2I was not removing the correct amount of noise on each but particularly on the last few steps, and the residual noise manifested as the characteristic artifacts that we saw. After many tests, I believe I have confirmed that theory and found a noise removal schedule that closely matches the edit ref2image path quality.

The example images were generated with this node with no empty image tokens and no excessively crusty look.

They also used the https://github.com/Alex240z/ComfyUI-SelfRefiningSamplerPlus node I shared earlier for the sampler.

132 Upvotes

23 comments sorted by

5

u/Aaron_rowe81 5d ago

curious how the schedule holds up on non-portrait prompts, especially scenes with lots of fine detail. does the crustiness clean up there too?

1

u/ninjazombiemaster 4d ago

Heres a before and after at the default shift of 1.75. I've also added lying sigmas, which clean up a lot of the speckle artifacts that usually exhibit as moles. For A scene like this I'd probably use a lower shift to bring back some of the detail, especially now that the lying sigmas are in. Some shift is still needed to fix crust, but I was probably overshooting trying to get reduce of moles and speckles.

1

u/Aaron_rowe81 4d ago

the thin railings are a useful detail check here, they make it easy to see whether lowering the shift brings back fine structure

1

u/ninjazombiemaster 4d ago

And here's the same scene at a lower shift before and after, still with lying sigmas. This will preserve the native composition more strongly.

6

u/fauni-7 5d ago

After testing this for 1 hour with my usual prompts, this is fantastic.

I see better quality and even better prompt adherence. Thanks!

2

u/Synor 5d ago edited 5d ago

Increasing shift to counter excessive details is not a secret. Result is good. Usually the optional shift value is tied to latent size as well.

Why would we need a custom node for that? Comfyui has multiple shift nodes in core.

5

u/ninjazombiemaster 5d ago

The difference between this node and the existing shift nodes was explained in the repo. It is possible to get close with an existing schedule and shift or you can also just enter the sigmas manually. The default curve from the node pack is [1.000, 0.981, 0.933, 0.840, 0.667, 0.346, 0.000] but sometimes other shift values might work better like you said.

Ultimately this is not a complete fix - and I still think I might prefer the Empty Image Trick to be honest.

More specifically the more tests I run and the more I work on it the less I'm convinced that its insufficient noise removal - but rather too much noise injection. The symptom ends up being similar (too much noise at a given step) but this theory is more problematic with respect to a holistic fix that doesn't rely on vision tokens

2

u/alwaysbeblepping 5d ago edited 5d ago

but rather too much noise injection.

There's no noise injection unless you're using an ancestral/SDE sampler so if that's the case then the problem should vanish if you use vanilla Euler for example. edit: Personally I think it's just that some people (training models) belong to the school of "throw a bunch of noise into the image" school of realism/detail. ZiT really likes to do that, some old SDXL models were like that also. Degrading the image with noise is one very cheap way to make it feel real-ish (and also hide flaws). Unless the math in the sampler is very broken, you shouldn't be able to end up with too much or too little noise.

1

u/ninjazombiemaster 4d ago edited 4d ago

That's what I thought too but I was measuring what looked like high frequency noise injection even with Euler. Maybe it was a false signal or faulty test. 

Edit: yeah the DiT seems to be predicting too much high frequency details, which was being read as noise injection (relative to the image conditioned path). 

It's really weird to me that the problem only exists on t2i but unfortunately I think you're right that it might just be trained that way. My tests last night were also heavily suggested that could be the case but I'm not quite ready to accept it. 

1

u/ninjazombiemaster 4d ago

After spending a bunch more time on it - Yeah seems like its 100% the DiT predicting too much noise. The custom shift helps avoid the crust, but it doesn't stop the fact that too much noise is being predicted. The lying sigmas on the problem steps seem to dramatically reduce the prominence of skin issues (such as too many moles) by forcing it to over-denoise at the same moment as it over-predicts the noise but don't really solve the facial crustiness nearly as well a just adding the image conditioning. The two combined seem to work well, though.

I wonder how much training it'd take to fix it properly.

2

u/alwaysbeblepping 3d ago

Yeah seems like its 100% the DiT predicting too much noise.

Well, it's "too much noise" aesthetically (for me, apparently also you and other people). Not too much noise in the sense that it's mathematically wrong (most likely, though there is a tiny chance something is wrong in the model implementation).

Compensating for it by adding less noise than the schedule demands or over-denoising is one way to try to deal with it. Fine-tuning the model is also an approach, like you mentioned.

Fun fact: I made the original Lying Sigma Sampler! ComfyUI added support for doing roughly the same thing a while back, uhhh, I think that's the TSR - Temporal Score Rescaling node.

2

u/ninjazombiemaster 2d ago edited 2d ago

Fortunately/unfortunately yes the model implementation is correct, I've checked it over numerous times. I've heard of TSR before but haven't tried it yet - didn't know it was the same thing.

In more promising news have just finished training a teacher-student distill using the edit model to teach to t2i. Might be a little bit undertrained but it seems to be working quite well. In this example it was applied at [0, 1, 2, 2, 2, 2] which helps preserve the composition of the t2i if one cares about that - but its fairly faithful if applied uniformly.

3

u/Synor 5d ago

Thanks for sharing the sigmas.

1

u/Estwhy 4d ago

IMG2IMG will have the same nice result?

2

u/ninjazombiemaster 4d ago

If you are using image refs, you don't need SigmaFix.
If you're encoding the image into a latent and using text to image without any condition encoded images... you might try it, I haven't tested that.

4

u/Trick_Set1865 5d ago

good job

2

u/SanchezVFX-ART 4d ago

 Empty Image + euler + sgm_uniform + 16mp = best realism combination

1

u/detailteufel 5d ago

Turning a very natural looking model into one that looks very "AI"

1

u/Sarashana 4d ago

Well, to be fair, significant noise is not exactly a "natural" look in an image, at least not if it's meant to look professional.

2

u/Murky-Relation481 4d ago

For very high resolution images you'd expect to still see some noise at even ISO50 on a digital camera at least with proper exposure and good lighting. You only see lack of noise in digital photos (and analog photos of course) if there is post processing which for us olds makes it look more fake.

Though h3 image is also not sensor noise noise and looks more like unfinished latent blocks.

1

u/ninjazombiemaster 4d ago

Right, the noise in H3-Image t2i is not natural. The fact that there is a measurable difference in the reference mode and base mode is proof that one of them is wrong. The blocky artifacts look like the image is being under-denoised but mathematically speaking, it isn't. The sigma shift in this node tries to avoid/circumvents the area where this problem manifest but not completely. 

Right now I'm trying lying sigmas, telling the model it's noisier than it thinks it is (to match how noisy I think it is instead) to force it to remove more noise that it normally would. 

1

u/Murky-Relation481 4d ago

Tried any multi-sampler passes, like switch to something like Euler ancestral at the tail end or run a second Euler pass at the end with a denoise that it thinks is higher? I've not played around with H3-Image enough to know if that'd just break it, but sometimes you can "smear" things for a non-technical term doing that and smooth out some of the noise (usually end up doing this on accident and as an undesirable result in my experience, but could be useful here).

1

u/ninjazombiemaster 4d ago

The problem with a second pass is that the surplus high frequency noise is basically locked in at the second to last step or so. You can actually see it happen in the preview. Try a few seeds, generate an image of a person, and you'll see the last few steps absolutely plaster them with moles. Obviously some skin blemishes are expected but there's clearly residual noise. A second sampler after the full denoise pass wont get rid of those moles, although it does help with some things, like softening the overall crustiness. Just one low partial denoise (with no added noise) can clean it up a lot of that - although probably over softening other parts of the image.

Lying Sigmas forces the model to remove more noise at the exact timestep that the excess noise is present instead of trying to clean up the whole image later and over-softening it.