Nodes/NKD Klein Tools/😺NKD Klein Presampling
ComfyUI Node

😺NKD Klein Presampling

This node is the front door

By Nekodificador·Created 4 months ago·Updated 10 days ago· 80
😺NKD Klein Presampling
  • model
  • clip
  • vae
  • ref_images
  • mask
  • model
  • positive
  • negative
  • latent
  • bundle
  • mask
  • ref_0
â—„positiveâ–º
â—„negativeâ–º
â—„pin_modelfalseâ–º
â—„resizetrueâ–º
â—„aspect_ratioAs Referenceâ–º
â—„megapixels1.0â–º
â—„custom_width1024â–º
â—„custom_height1024â–º
â—„image_fitNativeâ–º
â—„outpaint_fillGrayâ–º
â—„slide0.50â–º
â—„bypass_referencefalseâ–º
â—„reference_strength0â–º
â—„mask_expand20â–º
â—„mask_blur10â–º
â—„inpaint_blend1.00â–º
â—„use_detailingfalseâ–º
â—„detail_padding50â–º

If you've run Flux Klein in ComfyUI, you know the stock multi-reference workflow is a wiring project. ReferenceLatent nodes, conditioning merges, a canvas resizer, a mask-grow chain, a detailer rig - enough spaghetti to feed a family. NKD Klein Presampling collapses all of it into one box. Plug in your model, write a prompt, drop an image, and it hands your sampler everything it needs. That's the whole pitch, and it's why the pack author describes it as "no manual wiring of internal pieces."

It's the first node of the NKD Klein Tools pack, by Nekodificador (who also makes NKD Preview Tools and the NKD Sigmas Curve). The pack landed on r/comfyui in June 2026 to a warm reception, and the design philosophy is visible on the front of the node: one box that figures out what you're doing from what you connect.

How it works

Presampling does the prep work that a hand-built Klein graph would spread across a dozen nodes:

  • Mode auto-detection. No reference = text-to-image. Image only = img2img. Image + mask = inpainting. Add Use Detailing on top and it crops the masked zone, regenerates it at high resolution, and hands the crop to your sampler.
  • Canvas sizing. From Aspect Ratio + Megapixels it picks the output size, then preprocesses your reference to fit via Image Fit - Native (model rebuilds the canvas, no distortion), Center Crop, or Outpaint (with Gray/Black/White/Smart fill for the empty space).
  • The Klein-specific part. It builds the reference conditioning the way Klein actually consumes it - your images get appended to the attention sequence as extra tokens ([txt | canvas | ref_0 | ref_1 …], up to 8 slots) so the model attends to them every step. A bundle output carries the crop boxes, masks, and original image so the matching Postsampling node can put everything back afterward.

Inputs and outputs that matter

You'll set maybe a handful of these:

  • ref_0 - your input image. The most important slot; more appear automatically as you connect.
  • positive - describe what you want, in sentences (Klein's Qwen3 encoder reads a prompt like an instruction, not a tag list; see the Prompt Builder node).
  • reference_strength - the creative dial. 0 is Klein's balanced default; crank it up (to 10) to anchor the layout tightly to your reference, go negative for looser reinterpretation.
  • mask (optional) - paint white over the area to regenerate; connecting it flips the node into inpainting mode, with Mask Expand, Mask Blur and Inpaint Blend to soften the seam.

Outputs: model, positive, negative and latent feed your sampler; bundle goes to Postsampling. The preprocessed ref_0 output is handy if another part of the graph needs the exact canvas-sized image, and the processed mask tells downstream nodes what actually got regenerated.

The chain is short and linear:

NKD Klein Presampling → [your sampler] → VAE Decode → NKD Klein Postsampling

Installing it

Via ComfyUI Manager, search NKD Klein Tools. Or clone it in:

cd ComfyUI/custom_nodes
git clone https://github.com/Nekodificador/ComfyUI-NKD-Klein-Tools

Then restart ComfyUI. Good news on dependencies: requirements.txt is essentially empty - torch and the ComfyUI API come from ComfyUI itself, so there's no dependency-hell to fight. You need PyTorch ≥ 2.0 and a ComfyUI build with Flux Klein model support. You still have to supply the model yourself - a FLUX.2-klein-4B or -9B checkpoint plus its Qwen3 text encoder and VAE, from HuggingFace. The pack downloads nothing.

Common issues

  • Confusing the two "strength" dials. reference_strength here controls positional anchoring - how tightly the layout sticks to your reference. The separate Reference Weight node controls how much a reference shows up. Two different things; the README is explicit about it.
  • Upgrading from an older version. Megapixels used to be a dropdown; workflows saved then still load, with the value migrated automatically, but it's worth opening the node and confirming the number is what you wanted.
  • Resize off. If you turn Resize off, the node leaves every image at its own size and works at your input's native resolution - the sizing is now your job, elsewhere in the graph.
  • Detailing needs both an image and a mask. Without a mask there's nothing to zoom into, so the toggle is silently ignored. If you enabled it and nothing changes, that's why.
Category😺NKD Nodes/Klein

Inputs (23)

NameTypeDefaultDescription
modelMODELYour Flux Klein model.
clipCLIPThe text encoder that goes with the model.
vaeVAEThe VAE that goes with the model.
positiveSTRINGDescribe what you want in the image.
negativeSTRINGDescribe what you don't want.
pin_modelBOOLEANfalseKeeps the model in your graphics card so it doesn't reload between runs. Faster, but only turn it on if you have plenty of VRAM.
resizeBOOLEANtrueOn (default): the node sizes the image for you from Aspect Ratio and Megapixels. Off: the node leaves every image at its own size and works at your input image's native size — use this when you want to handle sizing yourself elsewhere. Turning it off hides Aspect Ratio and Megapixels.
aspect_ratioCOMBOAs ReferenceThe shape of the final image. 'As Reference' copies the shape of your input image. 'Custom' lets you type any size you want.
megapixelsFLOAT1.00.1–4How big the final image should be, in megapixels. Bigger values mean more detail and sharper results, but also slower generation and more VRAM needed.
custom_widthINT102464–8192Width in pixels. Only used when Aspect Ratio is set to Custom.
custom_heightINT102464–8192Height in pixels. Only used when Aspect Ratio is set to Custom.
image_fitCOMBONativeHow to handle your input image when the chosen canvas has a different shape. Only matters when the canvas shape doesn't match the image. Native: the model rebuilds the canvas around your subject without distorting it (best for changing aspect ratio or upscaling). Center Crop: cuts the image to fit the canvas (no distortion, loses the edges). Outpaint: fits the whole image inside the canvas and lets the model fill in the surrounding space.
outpaint_fillCOMBOGrayWhat to put in the empty space around your image when using Outpaint. Gray is neutral and lets the model decide freely. Black or White nudge it toward dark or bright surroundings. Smart fills the space with a soft continuation of the image so the model has a natural starting point. Only used with Outpaint.
slideFLOAT0.500–1Shifts the image off-centre. With Outpaint it moves the image within the empty space; with Center Crop it chooses which part of the image is kept. 0.5 stays centred. The direction follows the canvas shape: a taller canvas moves it up (toward 1) or down (toward 0); a wider canvas moves it right (toward 1) or left (toward 0). Used with Outpaint and Center Crop.
bypass_referenceBOOLEANfalseTurn off the model's ability to look at your reference image while it works. Leave it off in most cases — turn it on only if you want the model to ignore the reference completely.
reference_strengthINT0-2–10How tightly the result follows the layout of your reference image. 0 is the default (balanced — good for most edits). Higher values lock the result more strictly to the original layout (useful when things need to line up perfectly with the input). Negative values give the model more creative freedom to reinterpret what it sees.
ref_imagesCOMFY_AUTOGROW_V3Connect your input image to ref_0. More slots will appear automatically if you want to add extra reference images.
mask_expandINT200–512Makes the masked area a bit bigger so the regenerated region blends naturally with its surroundings.
mask_blurINT100–512Softens the edges of the mask so the transition between the new and old parts of the image looks smoother.
inpaint_blendFLOAT1.000–1Controls how sharp the transition is between the regenerated area and the original image. 0.0 gives a clean cut along the mask edge; higher values fade the two together more gently.
use_detailingBOOLEANfalseZooms into the masked area before regenerating it, so you get more detail in small zones (faces, hands, eyes…) without having to upscale the whole image. Needs both an input image and a mask.
detail_paddingINT500–512How much extra space around the mask the zoom should include. More padding gives the model more context, less padding focuses tighter on the masked area.
maskoptMASKPaint a mask to tell the model which part of the image to regenerate. White areas get redone, black areas stay the same. Connecting a mask switches the node into inpainting mode.

Outputs (7)

NameTypeDescription
modelMODEL—
positiveCONDITIONING—
negativeCONDITIONING—
latentLATENT—
bundleNKD_KLEIN_BUNDLE—
maskMASKThe mask after expanding and softening — useful if a downstream node needs to know which area was regenerated.
ref_0IMAGEYour input image after the Image Fit / Outpaint preprocessing, at the final canvas size. Handy to feed into other parts of the workflow that need the same prepared image.