Nodes/NKD Klein Tools/😺NKD Klein Reference Region
ComfyUI Node

😺NKD Klein Reference Region

Pin one reference to one zone of the canvas

By Nekodificador·Created 4 months ago·Updated 11 days ago· 80
😺NKD Klein Reference Region
  • model
  • latent
  • mask
  • model
  • latent
â—„reference_index1â–º
â—„region_weight1.00â–º
â—„outside_suppression1.00â–º
â—„region_hardness0.00â–º

Here's a Klein workflow problem that has no stock solution: you've got a reference image that should only influence part of the canvas. Maybe a product shot that should control just the item on the table, while the rest of the scene takes its cues from the prompt and other references. Without help, Klein spreads every reference across the whole image. NKD Klein Reference Region is the experimental node that confines one reference to one masked zone - the reference's influence is held inside the area you paint, and can be reinforced inside it.

It's part of the pack's newer regional-reference family (with Reference Fit and Reference Control), all marked experimental. On reasonable settings it works cleanly; on strong settings expect a little bleed into neighbors. The author is upfront about it and says so in the README.

How it works

Klein's attention is joint over [txt | canvas | ref_0 | ref_1 …] - every canvas token "sees" a reference through the attention weight from that canvas query to the reference's keys. This node exploits that: it installs an attention patch (set_model_attn1_patch) that adds a per-position bias to the canvas-query × this-reference-key block. Canvas tokens inside your mask keep neutral or boosted attention toward the reference; tokens outside get a strong negative bias so the reference stops influencing them.

Because the mask is area-pooled down onto the model's token grid (from your latent), the whole thing is resolution-independent - repaint your mask at any size and the containment scales with it.

Inputs that matter

  • model - from Presampling. The node returns a patched clone of it.
  • latent - Presampling's latent output. Used to map your mask onto the token grid; without it the node can't localize and bails out safely.
  • mask - the zone this reference should fill. White = the reference applies here; black = it's kept out.
  • reference_index - which reference to confine. 0 = the main reference (ref_0), 1 = ref_1, in connection order. Usually a secondary reference (1+).
  • region_weight - how strongly the reference shows up inside the zone. 1 = normal, above 1 reinforces (up to 4), below 1 dilutes even inside. Note the tooltip's warning: pushing this high can make the reference bleed - tighten the zone with region_hardness instead.
  • outside_suppression - how much the reference is held back outside the zone. 1.0 = it appears only inside; 0.0 = no regional restriction (acts everywhere, like a normal reference).
  • region_hardness - crispness of the zone edge. 0 = soft falloff that follows your mask's blur (natural blend, but the reference can halo just outside). 1 = hard binary edge - tightest containment, though the boundary snaps to the token grid and can look slightly stepped.

Outputs are model and latent; the latent passes through so you can chain one node per region/reference, each with its own mask.

The crucial pairing: Reference Fit

A masked region only sees the slice of the reference that overlaps it positionally, because Klein lays every reference over the whole canvas. That's where NKD Klein Reference Fit comes in - it scales the reference to fit your mask's bounding box so the whole reference lands inside the zone. The intended wiring is:

reference image → NKD Klein Reference Fit (with your mask) → Presampling's ref slot
your mask        → NKD Klein Reference Region → sampler

Use the same mask in both nodes. Without Fit, you'll get a partial or misaligned crop inside the zone.

Wiring and installing

On the model line between Presampling and your sampler:

NKD Klein Presampling → NKD Klein Reference Region → [your sampler] → NKD Klein Postsampling

Connect Presampling's model and latent in, attach the mask, set the index, run. Install via ComfyUI Manager (search NKD Klein Tools) or:

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

Restart ComfyUI. No pip dependencies - requirements.txt is empty, so no conflicts to fight. You need a Flux Klein model (4B or 9B plus Qwen3 encoder and VAE) yourself; the pack ships no weights.

Gotchas

  • Empty or all-black mask → no-op. The node logs a warning and passes the model through rather than accidentally blocking the reference everywhere.
  • Mask without a latent. It can't build the token-grid mapping, so the region is skipped (strength only) - check the console warning.
  • Bleed outside the zone. Dial region_hardness up toward 1.0 rather than fighting it with the other knobs.
Category😺NKD Nodes/Klein

Inputs (7)

NameTypeDefaultDescription
modelMODEL—
latentLATENTThe canvas latent from Presampling — used to map your mask onto the model's token grid. Connect Presampling's latent output here.
maskMASKThe zone this reference should fill. White = the reference applies here; black = it's kept out.
reference_indexINT10–7Which reference to confine to the zone. 0 = the main reference (ref_0), 1 = ref_1, … in the order added. Usually a secondary reference (1+).
region_weightFLOAT1.000–4How strongly the reference shows up INSIDE the zone. 1.0 = normal, above 1 reinforces (up to 4), below 1 dilutes it even inside the zone. Note: pushing this high can make the reference bleed into neighbouring areas — use region_hardness to tighten the zone instead.
outside_suppressionFLOAT1.000–1How much the reference is held back OUTSIDE the zone. 1.0 = it appears only inside the zone; 0.0 = no regional restriction (acts everywhere, like a normal reference). In between fades the restriction.
region_hardnessFLOAT0.000–1Crispness of the zone edge. 0.0 = soft falloff (follows your mask's blur — natural blend, but the reference can halo just outside the zone). 1.0 = hard binary edge (tightest containment; the boundary snaps to the token grid so it may look slightly stepped). Raise this if the reference bleeds into areas you didn't mask.

Outputs (2)

NameTypeDescription
modelMODEL—
latentLATENTThe same latent, passed through — chain it into the next Reference Region to drive several regions.