Nodes/ComfyDL/Show Trace 2D
ComfyUI Node

Show Trace 2D

Watching an optimizer wander its way to the minimum

By Cynthia-lxx·Created 2 months ago·Updated 2 days ago· 6
Show Trace 2D
  • results
  • image

Optimizers are usually a black box: you set a learning rate, run training, and only ever see the loss number. CdlShowTrace2D opens the box. Feed it a sequence of (x1, x2) parameter positions and it plots the optimizer's actual path through 2-D parameter space - the zigzagging descent, the overshoot, the slow crawl into the basin. It's the d2l textbook's show_trace_2d, ported as a node, and it's one of the best "aha" nodes in the pack.

The d2l book uses this to teach optimization geometry: why high learning rates bounce, why momentum smooths, why gradient descent on an ill-conditioned function slaloms. In ComfyDL, you record your optimizer's parameter positions into a [N, 2] tensor, and this node turns the run into a picture. The plot is simple by design - orange line with dots, labeled axes, grid - because the path is the whole point.

The inputs

Just one: results - a cdlTensor of shape [N, 2], where each row is a (x1, x2) coordinate on the trajectory. N is the number of recorded steps. That's it; the axes are hardcoded to x1/x2 and the figure size is fixed.

Output: image, a standard [1, H, W, C] IMAGE you can preview or save.

Installing ComfyDL

The usual 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. Only dependency is matplotlib; nothing to download.

How to actually use it

The d2l workflow it's built for: pick a 2-D objective, record the parameter value at each optimization step into a growing [N, 2] tensor, and at the end render the trace. Since ComfyUI isn't a Python loop, the practical pattern in this pack is a fixed number of unrolled SGD Step iterations with a node that appends each step's (x1, x2) to the trace. Re-run with different lr values and compare traces side by side - that's the experiment this node exists to enable.

Two honest caveats. First, it only plots what you record: if nothing in your graph is actually logging positions to results, the node has nothing to show, and it's easy to forget that logging step because it's the one piece of plumbing that isn't obviously a "real" node. Second, the textbook version also draws the objective's contours so you can see the function you're descending; this node drops the contour surface and just shows the path. You lose a little context, but the trajectory itself - the thing everyone actually looks at - is intact.

Gotchas are minimal: results must be [N, 2] (not [2, N]), and it's a cdlTensor, so it lives inside the ComfyDL sandbox. Both are the usual pack conventions. If the trace looks like a scribble, that's not a bug - that's your optimizer telling you the truth about your learning rate.

Categoryd2l/Visualization

Inputs (1)

NameTypeDefaultDescription
resultsTENSOR

Outputs (1)

NameTypeDescription
imageIMAGE