Nodes/ComfyUI-RefSampling/Apply Ref UNet
ComfyUI Node

Apply Ref UNet

The unglamorous node that makes the pack work

By logtd·Created 2 years ago·Updated 2 years ago· 5
Apply Ref UNet
  • model
  • MODEL
attn

This is the node you'll add and immediately forget about - which is exactly the point. Apply Ref UNet does nothing visible on its own. But if you chain up Apply Ref Content or Apply Ref Style without it, those nodes quietly do nothing at all. It's the plumbing: it rebuilds your UNet so the reference-injection machinery has somewhere to live.

Why it exists

ComfyUI-RefSampling is a proof-of-concept pack from logtd (also behind ComfyUI-Fluxtapoz and the ComfyUI port of InstanceDiffusion) that implements two reference-image tricks - the "Reference CNet" mode from sd-webui-controlnet and NAVER's Visual Style Prompting - via attention injection. Neither trick can work unless the model's attention layers are modified to record and replay states. That modification is this node's entire job. It's the first step in the chain, and the pack's example workflow wires it exactly like this:

CheckpointLoaderSimple → ApplyRefUNetNode → ApplyRefContentNode → ApplyRefStyleNode → KSampler

How it works

Under the hood, apply walks your diffusion model, finds every BasicTransformerBlock (the self-attention blocks that SD 1.5 and SDXL use), swaps each attention module's class for a wrapped version that can stash and replay its attention states, then wraps the whole UNet in a controller that orchestrates the write/reference/read passes the content and style nodes depend on. It flags the model as reference-capable, and that flag is what tells the rest of the pack the machinery is in place.

Two inputs, one output. The model goes in, a patched MODEL comes out. The attn input is an enum with exactly one option - ["FULL"] - which is proof-of-concept in the clearest possible form: there's nothing to choose, it's there because the original design imagined more attention modes later. The name is honest, too: this is a UNet technique, and it only makes sense on UNet-based models.

Install

# Easiest - ComfyUI Manager:
#   Manager → Install Custom Nodes → search "ComfyUI-RefSampling" → Install → restart ComfyUI

# Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/logtd/ComfyUI-RefSampling
# restart ComfyUI

No requirements.txt, no pip install, no model files. The pack's own pyproject.toml description still mentions "Ref Sampler" nodes that don't exist in the shipped __init__ - trust the actual three nodes, not the metadata.

Where people get burned

  • Order matters. Apply Ref UNet has to be applied to the model before the content/style nodes' config gets read. The example chain puts it first for a reason; deviate from that order only once you know what you're doing.
  • It's SD 1.5/SDXL territory. The node hunts for BasicTransformerBlock, and on a DiT model like Flux, Qwen-Image, or Z-Image there are none. Instead of erroring, it just… doesn't find anything, and the whole pack silently does nothing. If you're on Flux wondering why RefSampling seems dead, that's why - it was never built for your model.
  • It's not where you tune anything. All the strength dials live on Apply Ref Content (fidelity, attention_bound) and Apply Ref Style (attention_count). This node is a switch that turns the mechanism on, not a control for how hard it pulls.

So: add it first, forget about it, and blame it only when you're on a model family it was never designed for. That's the one case where "the node did nothing" is the whole truth.

Categoryflow

Inputs (2)

NameTypeDefaultDescription
modelMODEL
attnCOMBO1 options: FULL

Outputs (1)

NameTypeDescription
MODELMODEL