Linear Regression
Y = Xw + b as three wires — linear regression without a single line of code
- X
- w
- b
- y_hat
CdlLinReg is the mathematical heart of the pack's linear regression demo: it computes y_hat = X @ w + b - the prediction step of linear regression - with three tensor inputs and one tensor output. Nothing fancier than a matrix multiply and an add. It's the "hello world" of the whole ComfyDL philosophy: instead of writing torch.matmul(X, w) + b in a notebook, you wire three cdlTensor sockets and watch the numbers flow.
The pack's Linear Regression example workflow is the canonical use: a synthetic data node generates X (features) and true w/b, this node produces predictions, a loss node measures how wrong they are, and an optimizer node nudges w and b toward the answer. You get to see gradient descent happen in a graph instead of a terminal. For someone learning deep learning this is genuinely the cleanest possible first graph: three inputs, one operation, one obvious next step.
How it works
The implementation is a straight one-liner: torch.matmul(X, w) + b, mapped to the d2l linreg function. The X tensor should be [batch, features], w should be [features, 1] (or [features]), and b a matching broadcastable scalar or vector. The node does no reshaping for you - like the rest of ComfyDL, it assumes you built the tensors to fit. This is a prediction node, not a training node; the learning lives in the optimizer nodes you chain after the loss.
Inputs and output
Three required inputs, all cdlTensor:
X- the feature matrix, shape[batch, features].w- the weight vector. Its length must matchX's feature count, or the matmul fails with a shape error.b- the bias. A scalar broadcasts fine.
The single output is y_hat, a cdlTensor of predictions, one per row of X. Wire it into the pack's squared-loss or optimizer nodes for the classic regression loop, or into a visualization node if you want the fitted line drawn.
Installing ComfyDL
It's part of the ComfyDL pack:
cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ComfyDL/requirements.txt
Restart ComfyUI. The only extra dependency is matplotlib; torch comes with ComfyUI. ComfyUI Manager users: search "ComfyDL", and if it's not in the built-in list (the pack hasn't published to the official Comfy Registry yet), use Install via Git URL with https://github.com/Cynthia-lxx/ComfyDL.
Common issues
Shape mismatches are the whole failure mode here. w of the wrong length is the classic error, and since the pack's tensors are often built by dataset or random-tensor nodes, the fix is usually to check the tensor's shape upstream. There's also the conceptual trap: this node predicts, it doesn't learn - if you wire in random w and b and see garbage predictions, that's expected; the learning happens when you close the loop with an optimizer. If you just wanted a single number multiplied and added and the node feels like overkill, you're not wrong - but in the demo graph it's the piece that makes the rest click.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| X | TENSOR | — | |
| w | TENSOR | — | |
| b | TENSOR | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| y_hat | TENSOR | — |