IW ModelHook
A sampler hook that tries to fix SDXL's latent weirdness
- model
- MODEL
IW ModelHook is the odd node in the iwanders pack - it's not a string utility, it's a sampler hack. It takes a MODEL in, registers a post-CFG hook on it, and hands the model back out. From then on, every sampling step runs your denoised latent through a fixed set of corrective transforms before it continues. No knobs, no options, no on/off switches in the UI: it does what it does.
What it's actually doing
The source implements ideas from a Hugging Face blog post ("explaining the SDXL latent space") about the SDXL latent space having out-of-bounds values that show up as color shifts and artifacts. The hook applies three transforms, gated by where you are in the denoise:
- Early in the run (estimated timestep above ~950):
soft_clamp- values outside a threshold get pulled toward the mean instead of letting extreme latent outliers run wild. - Mid-to-late (above ~700):
center_tensor- each channel's mean is subtracted, which is "balance the colors" in latent terms. This targets the washed-out or color-cast output people fight on SDXL. - Very late (timestep under 100): center again plus
maximize- normalize the latent so it fills the expected range before the VAE decodes it.
So it's a "clean up the latent as you go" node aimed at the classic SDXL failure modes: color casts, oversaturation, and latent-range garbage.
Be honest about the caveats
This is an experiment, not a polished tool. There are no parameters, so you can't tune how aggressive the clamping is. The timestep estimate is derived from a step counter assuming ~40 sampling steps - run 20 or 50 steps and the thresholds land at slightly different points, which changes the effect even though you changed nothing else. And it hooks the post-CFG pass, so it's tuned for the CFG-era SDXL workflow; on guidance-distilled models that run at CFG 1 there's no meaningful CFG correction to post-process in the first place. It also returns the model, so wiring it between a checkpoint loader and your sampler is how you enable it - unplug it and the workflow goes back to stock.
I found no community discussion of this node anywhere - it's a personal experiment the author shipped with the pack. Treat it as "save a copy of your workflow, drop it in, see if your color problem goes away." If it doesn't help, don't fight it; there are better-maintained color-fix nodes out there. If it does, you've found a free latent-space band-aid.
Inputs and install
One input: model (MODEL, wired by default). One output: the same MODEL. That's the whole surface - it's deliberately frictionless to add or remove.
cd ComfyUI/custom_nodes
git clone https://github.com/iwanders/ComfyUI_nodes
Restart ComfyUI, or install via ComfyUI Manager (search iwanders). Pure Python, no dependencies, no downloads. Worth one experiment on an SDXL workflow with color-shift problems; nothing more.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |