PrepForUnsampling
Getting your images, masks, and latents ready for RES4LYF unsampling
- image_1
- image_2
- mask
- latent
- vae
- latent_1
- latent_2
- mask
- empty_latent
- width
- height
Unsampling is RES4LYF's headline img2img trick - instead of just adding noise to a latent and denoising it back down (the normal, blurry, low-fidelity way to do img2img), you run the sampler in reverse to invert an image into noise, then resample it with a new prompt. Done right, it keeps composition and style far better than a plain low-denoise pass, because you're not guessing at the noise, you're recovering the actual noise trajectory that produced the image. Done wrong, you get a black screen or something incoherent - and a lot of "wrong" comes down to feeding the sampler mismatched image, mask, and latent shapes. PrepForUnsampling is the node that gets all of that lined up before it hits the sampler.
What it actually does
It's a batching and resizing utility built specifically for the dual-guide unsampling workflows in the README (composition guide, style guide, and a mask to blend between them). You feed it up to two images, an optional mask, and optionally a latent, tell it the target size and how to fit everything into that size, and it VAE-encodes the images into latents with matching shape - plus it hands you back an empty_latent sized to match, ready for the actual generation pass. That "empty_latent" output is the detail people miss: unsampling workflows need a correctly-shaped blank latent for the resample stage as much as they need the encoded guide latents, and getting that dimension wrong silently is a classic way to end up with garbage output.
The inputs and outputs that matter
image_1/image_2(IMAGE, optional) - your guide images. Single-guide unsampling only needsimage_1; dual-guide (composition + style, masked between them) uses both.mask(optional) - blends between the two guides when you're running dual guides.mask_channel(red/green/blue/alpha) picks which channel of that mask image carries the actual mask data, andinvert_maskflips it.latent(optional) - feed an existing latent through if you're chaining from an earlier stage rather than starting from images.vae(optional) - needed if you're encoding from images; skip it if you're only passing a latent through.width/height(default 1024×1024) plusresize_to_input- set a target size, or lock it to whichever input (image_1,image_2,mask, orlatent) should dictate the size instead.method(default "fill / crop") andinterpolation(default "lanczos") - the usual resize behavior knobs: stretch, keep proportion, fill/crop, or pad, with your choice of resampling filter.latent_type(default "16_channels") - match this to your model family. Flux, Chroma, HiDream, SD3.5 and other modern transformer models use 16-channel latents; SD1.5/SDXL use 4. Get this wrong and the VAE encode will be garbage or error outright.
Outputs: latent_1 and latent_2 (your encoded guides), mask (resized to match), empty_latent (the blank canvas for resampling), and width/height (so downstream nodes can stay in sync without you retyping numbers).
How to install it
Same install as the rest of RES4LYF - there's no separate step for this node. Through ComfyUI Manager: search "RES4LYF", install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ClownsharkBatwing/RES4LYF/
cd RES4LYF
pip install -r requirements.txt
(swap pip for your portable install's embedded pip.exe on Windows). Restart ComfyUI after.
Common issues & troubleshooting
Latent channel mismatch. This is the single most common way unsampling breaks - pick latent_type for the model you're actually running, not the model you usually run. A 4-channel latent fed to a Flux-family sampler (or vice versa) will not produce a sensible image.
Composition looks right but resampling produces noise or a black image. This is a known unsampling failure mode independent of this node - the community's fix is almost always to switch to a genuine unsampling-capable sampler (RES4LYF's own ClownsharKSampler set to sampler_mode: unsample, then resample) rather than a generic reverse-noise hack, and to add more steps if the result is close but rough.
Dual guides bleed into each other oddly. Check mask_channel first - it's an easy one to leave on the wrong channel if your mask image came from a tool that writes to alpha instead of a plain grayscale red channel, and invert_mask is the other usual suspect when the guide that should dominate isn't.
Output size doesn't match what you expected. resize_to_input overrides your explicit width/height - if you set both, whichever input you named there wins, which surprises people who expect the numeric fields to always apply.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| resize_to_input | COMBO | false | 5 options: false, image_1, image_2, mask, latent |
| width | INT | 10240–16384 | — |
| height | INT | 10240–16384 | — |
| mask_channel | COMBO | 4 options: red, green, blue, alpha | |
| invert_mask | BOOLEAN | false | — |
| latent_type | COMBO | 16_channels | 2 options: 4_channels, 16_channels |
| interpolation | COMBO | lanczos | 6 options: nearest, bilinear, bicubic, area, nearest-exact, lanczos |
| method | COMBO | fill / crop | 4 options: stretch, keep proportion, fill / crop, pad |
| image_1opt | IMAGE | — | |
| image_2opt | IMAGE | — | |
| maskopt | IMAGE | — | |
| latentopt | LATENT | — | |
| vaeopt | VAE | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| latent_1 | LATENT | — |
| latent_2 | LATENT | — |
| mask | MASK | — |
| empty_latent | LATENT | — |
| width | INT | — |
| height | INT | — |