Show Heatmaps
Turning attention and weight matrices into something you can see
- matrices
- image
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
- 2-D
xlabel,ylabel- axis labels (empty by default).figsize_w/figsize_h- per-cell figure dimensions (default 2.5 each). The total figure isw * colsbyh * 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.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| matrices | TENSOR | — | |
| xlabel | STRING | — | |
| ylabel | STRING | — | |
| figsize_w | FLOAT | 2.50.5–20 | — |
| figsize_h | FLOAT | 2.50.5–20 | — |
| cmap | STRING | Reds | — |
| titlesopt | STRING | — | |
| max_samplesopt | INT | 2621440–1073741824 | — |
| dimsopt | STRING | auto | — |
| axis_reduceopt | COMBO | mean | 4 options: mean, max, first, mid |
| auto_selectopt | COMBO | last_n | 4 options: first_n, last_n, most_informative_n, least_informative_n |
| auto_nopt | INT | 00–3 | — |
| on_erroropt | COMBO | fallback_first_n | 2 options: error, fallback_first_n |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |