PyTorchInferenceNode
Run a trained network on real data (one sample at a time)
- model
- input_data
- dataset
- TORCH_TENSOR
Everything else in this pack is setup: downloading data, building a network, training it. PyTorchInferenceNode is the payoff - it pushes a TORCH_TENSOR or a sample from a TORCH_DATASET through a trained TORCH_MODEL and returns whatever your network's last layer produces. Wire its output to TensorToList or PlotSeriesString and you can actually see what the model decided.
It's part of EternalKernel PyTorch Nodes (TashaSkyUp), the pack that runs raw PyTorch inside the ComfyUI graph rather than the usual diffusion-UNet machinery. This node is the closest thing the pack has to a normal "model inference" step, and it's about as simple as inference gets.
How it works
The node takes a model plus exactly one of two data sources:
- input_data - a
TORCH_TENSOR, e.g. a single MNIST sample or a reshaped batch. - dataset - a
TORCH_DATASET.
Pass both and it raises an error; pass neither and it raises an error. Read that as a deliberate design choice: the node wants to know which path you meant.
Two behaviors worth knowing before you wire it up. First, when given a dataset it only grabs the first sample - next(iter(x))[0] - so don't expect a dataset to run your whole validation set in one go. Second, it compares the tensor's device to the model's and moves the input over if they differ, so a model parked on CUDA happily takes CPU tensors. The output is simply model(x): raw logits in, raw logits out, no softmax, no eval() call, no thresholding. If your last layer is a Softmax or an argmax, that's on the model you built, not this node.
Inputs and outputs
- model (required
TORCH_MODEL) - anything fromSequentialModelProviderplus its layer nodes, or a loaded model. - input_data / dataset (optional) - provide one.
- Output: TORCH_TENSOR - the network's output, shaped by your final layer. For a 10-class MNIST classifier with a 10-unit Linear head, that's
(1, 10)of logits.
Installing it
It ships with the whole ETK pack:
cd ComfyUI/custom_nodes
git clone https://github.com/TashaSkyUp/EternalKernelPytorchNodes.git
cd EternalKernelPytorchNodes
pip install -r requirements.txt
Restart ComfyUI and it's under ETK/pytorch - or install via ComfyUI Manager by searching "EternalKernel PyTorch Nodes".
Troubleshooting
The classic failure is a shape mismatch: feed a 2D tensor to a model that expects a flattened input and you get a matrix-multiplication error that mentions nothing helpful. Check your ReshapeTensor step. Also remember the pack patches ComfyUI's input validation to ignore return-type mismatches, so a wrong input type often fails at the torch layer instead of at the port - if the error text is cryptic, trace which output actually fed the model input. And if you meant to classify and you're getting floats in the hundreds, that's logits, not probabilities - add a Softmax layer or threshold on your side.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| model | TORCH_MODEL | — | |
| input_dataopt | TORCH_TENSOR | — | |
| datasetopt | TORCH_DATASET | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TORCH_TENSOR | TORCH_TENSOR | — |