Nodes/StyleAligned for ComfyUI/StyleAligned Reference Sampler
ComfyUI Node

StyleAligned Reference Sampler

StyleAligned Reference Sampler

By brianfitzgerald·Created 3 years ago·Updated about a year ago· 308
StyleAligned Reference Sampler
  • model
  • positive
  • negative
  • ref_positive
  • sampler
  • sigmas
  • ref_latents
  • output
  • denoised_output
share_norm
share_attn
scale1.00
batch_size2
noise_seed0
cfg8.0

The README calls this a replacement for KSampler, which is true but a little misleading on its own - unlike a normal KSampler, this one doesn't work standing alone. It needs a second node's output wired into it first. If you landed here directly: StyleAligned Reference Sampler is the second half of a two-node pipeline. The first half, Sample Reference Latents, DDIM-inverts a reference image into a per-step latent trail; this node consumes that trail while generating a brand-new image, sharing self-attention and normalization step-for-step so the new image comes out in the reference's style.

The idea underneath both nodes is the 2023 StyleAligned technique from Google Research: a surprising chunk of what reads as "style" - texture, palette, brushwork - lives in the statistics of self-attention (the query/key values, and group/layer normalization) computed during denoising, not in the literal pixels. Normal sampling denoises your latent in isolation, step by step. This node does the same denoising, but at each step it also reaches into the matching step of ref_latents and shares the reference's attention keys/values (and, depending on your settings, normalization stats too) with your generation. Match those statistics step-for-step across the two trajectories and the new image inherits the reference's look while following your new prompt for content - no training, no LoRA, just borrowed attention.

The inputs specific to this node, beyond the standard sampler plumbing (model, sampler, sigmas, noise_seed, cfg, latent_image as your starting noise): positive and negative are the conditioning for the new image you're generating. ref_positive is separate - it's the conditioning that produced the reference during inversion, and it needs to actually match what was used over on the Sample Reference Latents side, since the attention sharing is keyed to that context. ref_latents is the STEP_LATENTS output from Sample Reference Latents - this is the one input that only exists because of the paired node. batch_size lets you generate more than one styled image in a single pass. And the three style knobs carry over from Batch Align: share_attn (q+k default, q+k+v for a stronger but riskier effect), share_norm (both default, or group/layer for a lighter touch), and scale - though note the range here goes up to 2, not 1, so you can push well past "full strength" if the effect isn't landing hard enough at default.

Outputs: output is the final generated latent - VAE-decode it like normal. denoised_output is a second latent, the model's fully-denoised prediction at the last step; most workflows never touch this one, it's there for previewing what the model currently thinks the final image will be. If you've used ComfyUI's own SamplerCustom node before, this socket shape will look familiar - this node is built on that same interface, with the reference plumbing and the three style knobs bolted on.

Install the usual way: search "StyleAligned for ComfyUI" in ComfyUI Manager, or cd ComfyUI/custom_nodes && git clone https://github.com/brianfitzgerald/style_aligned_comfy and restart. No extra models or dependencies.

Worth knowing going in: this is a 2023 technique, the repo says outright it's no longer actively maintained, and reddit chatter about it basically stopped in 2024 once IP-Adapter took over the zero-shot-style niche (and, more recently, instruction-editing models took over reference-based work generally). It's not broken, it's just not where anyone's actively improving things - so treat any rough edge you hit as yours to work around, not something to file an issue about and wait on.

Common trip-ups:

  • Mixing up positive and ref_positive. It's easy to plug the same conditioning into both and lose half the point - ref_positive describes the reference, not the image you're generating now.
  • Step-count mismatch between the invert pass and this pass. ref_latents is a fixed sequence recorded at inversion time; if sigmas here has a different step count than what produced it, the two trajectories won't line up step-for-step. Keep the schedule consistent across both nodes.
  • No dropdown sampler here. Unlike stock KSampler where you pick "euler" from a list, this node wants a SAMPLER from a sampler-selector node and a SIGMAS from a scheduler node - two extra nodes if you're used to the single-node KSampler workflow.
  • Modern base models won't patch. This targets SDXL/SD1.5-era UNet attention; it predates Flux, SD3, Wan and Qwen's DiT architectures entirely, and an unmaintained pack has no reason to have grown support for them since.
Categorystyle_aligned

Inputs (13)

NameTypeDefaultDescription
modelMODEL
share_normCOMBO4 options: both, group, layer, disabled
share_attnCOMBO3 options: q+k, q+k+v, disabled
scaleFLOAT1.000–2
batch_sizeINT21–8
noise_seedINT00–18446744073709550000
cfgFLOAT8.00–100
positiveCONDITIONING
negativeCONDITIONING
ref_positiveCONDITIONING
samplerSAMPLER
sigmasSIGMAS
ref_latentsSTEP_LATENTS

Outputs (2)

NameTypeDescription
outputLATENT
denoised_outputLATENT