Nodes/ComfyDL/Show Heatmaps
ComfyUI Node

Show Heatmaps

Turning attention and weight matrices into something you can see

By Cynthia-lxx·Created 2 months ago·Updated 2 days ago· 6
Show Heatmaps
  • matrices
  • image
xlabel
ylabel
figsize_w2.5
figsize_h2.5
cmapReds
titles
max_samples262144
dimsauto
axis_reducemean
auto_selectlast_n
auto_n0
on_errorfallback_first_n

The best thing about attention is also the worst: the model hands you a matrix of "how much token i attends to token j," and you have no idea what it means until you can look at it. CdlShowHeatmaps is ComfyDL's answer - it renders matrix tensors as a grid of heatmaps, with a colorbar, ready to preview or pass downstream. It's the node you'll use the first time an attention visualization actually clicks.

This is the IMAGE-output variant of the pack's heatmap visualizer. ComfyDL follows a "dual variant" pattern for visualization: an (Output) version that displays inline in the UI, and a plain version like this one that renders the figure into a standard IMAGE tensor you can keep building on.

The inputs

  • matrices - the data, a cdlTensor, auto-promoted to 4-D. Here's the shape language:
    • 2-D [H, W] → a single 1×1 heatmap
    • 3-D [N, H, W] → N heatmaps in a 1×N row
    • 4-D [N, M, H, W] → an N×M grid
  • xlabel, ylabel - axis labels (empty by default).
  • figsize_w / figsize_h - per-cell figure dimensions (default 2.5 each). The total figure is w * cols by h * rows.
  • cmap - matplotlib colormap name (default "Reds").
  • titles - comma-separated subplot titles (optional).

Output: image - a [1, H, W, C] IMAGE of the heatmap grid, wired to a Preview node and you're done.

Installing ComfyDL

The standard light install:

cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
cd ComfyDL && pip install -r requirements.txt

Restart ComfyUI; it's under ComfyDL → Visualization, or search "ComfyDL" in ComfyUI Manager. matplotlib is the only extra dependency.

What to actually look at

The canonical use: a transformer attention matrix. In the ComfyDL NLP nodes, attention weights come out shaped to feed exactly this node - feed them in and the diagonal lines and focused patches tell you whether the model learned to attend sensibly. Correlation matrices from your data exploration work just as well.

Gotchas are mostly shape-related. A 4-D input is read as [N, M, H, W] - rows then columns - so if you hand it a tensor with a different leading order, your "grid" will be transposed or scrambled, not wrong. And the promotion is additive, not reshaping: a [H, W] becomes [1, 1, H, W], so don't pre-add batch dims and expect it to be ignored. If your figure comes out with a giant empty grid, that's usually a dims-order misunderstanding. Default colormap is Reds, which reads well; if you want more contrast for attention values, "viridis" or "plasma" are the usual upgrades.

Categoryd2l/Visualization

Inputs (13)

NameTypeDefaultDescription
matricesTENSOR
xlabelSTRING
ylabelSTRING
figsize_wFLOAT2.50.5–20
figsize_hFLOAT2.50.5–20
cmapSTRINGReds
titlesoptSTRING
max_samplesoptINT2621440–1073741824
dimsoptSTRINGauto
axis_reduceoptCOMBOmean4 options: mean, max, first, mid
auto_selectoptCOMBOlast_n4 options: first_n, last_n, most_informative_n, least_informative_n
auto_noptINT00–3
on_erroroptCOMBOfallback_first_n2 options: error, fallback_first_n

Outputs (1)

NameTypeDescription
imageIMAGE