Model Forward
Run your model on a tensor — eval mode, no gradients, done
- model
- tensor
- output
CdlModelForward is how you actually run a ComfyDL model. Everything else in the Model Utils family inspects, clones, saves, or toggles - this is the node that feeds a cdlTensor into a cdlModel and returns whatever comes out the other end. Build a LeNet, wire in a prepped image tensor, and this node gives you the class scores. It's the inference workhorse of the whole pack, and it's deliberately boring: it switches the model to eval mode, disables gradient tracking, and runs the forward pass.
The boring is the point. Training a model in ComfyDL means you want gradients flowing through loss and optimizer nodes. Inference is the opposite - you want no gradient graph, no accidental training-mode behavior. This node bakes in the safe defaults (model.eval() and torch.no_grad()) so you can't forget them, which is the exact class of mistake that silently ruins results with BatchNorm or Dropout layers. The d2l LeNet happens to use Sigmoid only, so mode barely matters for it - but the pack's deeper nets and RNNs care a lot.
How it works
The source is a short sequence with three careful steps. First it finds the model's device from its first parameter and moves your input tensor there if they differ - so you don't have to chase CPU/GPU mismatches yourself. Then it calls model.eval(). Then it runs the forward pass inside torch.no_grad() and returns the output. If your model uses Lazy layers (like CdlLeNet does), this is also the pass that finally materializes their shapes.
Inputs and output
model- anycdlModel.tensor- acdlTensorin the shape the model expects. For a LeNet that's a[batch, 1, 28, 28]-style image tensor; you'll usually build or prep it with dataset, image, and tensor nodes upstream.
The single output is output, a cdlTensor - shape depends entirely on your model. For a classifier it's logits or class scores; wire it into a visualization or argmax node to make it meaningful.
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 missing from the built-in list (the pack isn't on the official registry yet), use Install via Git URL with the repo link.
Common issues
Shape mismatches dominate: feed a LeNet a [batch, 3, ...] image or the wrong resolution and you'll get a runtime error, and since Lazy layers infer shape from the first pass, a wrong first input can lock in a wrong shape for the session. Also remember this node does not learn - it runs under no_grad, so wiring it into a training loop in place of the forward path means your optimizer will have nothing to backprop through. For training, keep the forward pass in the loss/optimizer branch; use this node for inference and visualization.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model | cdlModel | — | |
| tensor | TENSOR | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| output | TENSOR | — |