Nodes/ComfyUI-SD3-Powerlab/Render SD3 Attention
ComfyUI Node

Render SD3 Attention

Render a joint block's attention weights as an image

By G-370·Created 2 years ago·Updated 2 years ago· 20
Render SD3 Attention
  • sd3_model
  • IMAGE
joint_block0
backbone
view
colormap

Stable Diffusion 3 isn't a U-Net like everything before it. It's a stack of 24 transformer "joint blocks," and inside each one is a big matrix of numbers that decides how much one token attends to another. Render SD3 Attention is the node that turns that matrix into a picture you can actually look at.

It's a curiosity node first and a research tool second. You plug in a loaded SD3 model, pick a block, and out comes an image of its QKV attention weights - either as the query, key, or value slice alone, or the whole thing colormapped into a single frame. Nothing about the model changes. It's purely reading what's already in the weights, which is the polite half of this pack (the "Hack" nodes in the same repo write back).

How it works

Every joint block (numbered 0–23) has two sub-networks: a context_block that processes the text tokens and an x_block that processes the image/latent tokens. Each holds a fused QKV projection - one weight tensor with the query, key, and value matrices stacked vertically.

The node digs that tensor out of the model's state dict, then renders it based on your view choice:

  • query / key / value - splits the 4608×1536 QKV tensor into three 1536×1536 chunks and shows one, normalized to [0,1] and pushed through a matplotlib colormap so the structure is visible.
  • all-stacked - the entire QKV matrix colormapped as one tall image.
  • all-interposed - the QKV matrices reshaped into a 1536×1536 RGB image, one per channel. This is the "raw" format, no normalization, and it's the exact shape the pack's write-back nodes expect.

The colormap dropdown is the whole matplotlib palette - viridis, magma, turbo, all 181 of them - plus none for plain grayscale. Fun to scrub through, and genuinely useful for spotting whether a layer's weights are degenerate or intact. There's real history here: this pack was born out of the June 2024 "perturbed SD3" experiments, when people were trying to figure out which blocks Stability's safety training had mangled. Peeking at block weights was step one of that investigation.

The inputs that matter

  • sd3_model - any loaded SD3-family checkpoint.
  • joint_block - which block, 0 to 23.
  • backbone - text (the context_block) or latent (the x_block).
  • view and colormap - described above.

The single output is an IMAGE, so it wires straight into a Preview or SaveImage node.

Installing it

Via ComfyUI Manager: open the Manager, search for ComfyUI-SD3-Powerlab, install, restart. Or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/G-370/ComfyUI-SD3-Powerlab

then restart ComfyUI. There's no requirements.txt - the whole pack is one __init__.py - and it imports matplotlib.pyplot at load time. torch and torchvision ship with ComfyUI, but matplotlib does not, so if your environment lacks it the pack silently fails to load. Fix that with pip install matplotlib into whatever Python ComfyUI runs on.

Common issues

The attention math is hardcoded to SD3 Medium's layout: 24 blocks, 1536-dim QKV. That's the model this pack was built for in June 2024, and it shows. SD 3.5 Large and Medium use different hidden sizes and block counts, so the split/reshape here will throw a shape error rather than quietly produce garbage. If you're on SD 3.5, RenderAttention is a Medium-only toy. Also, if you pick a model or layer that doesn't expose that tensor, the code raises its error as a bare string - modern Python turns that into a confusing TypeError: exceptions must derive from BaseException, which is not the helpful message it looks like. If you see that, your block/backbone combo doesn't exist in the model you loaded.

CategorySD3 Power Lab/Visualize

Inputs (5)

NameTypeDefaultDescription
sd3_modelMODEL
joint_blockINT0
backboneCOMBO2 options: text, latent
viewCOMBO5 options: query, key, value, all-stacked, all-interposed
colormapCOMBO181 options: none, magma, inferno, plasma, viridis, cividis, +175

Outputs (1)

NameTypeDescription
IMAGEIMAGE