Extensions/ComfyUI-Pt-Wrapper
ComfyUI Extension

ComfyUI-Pt-Wrapper

PyTorch extension for ComfyUI featuring extensive PyTorch wrapper nodes for seamless tensor operations and PyTorch model training.

By HowToSD·Created about a year ago·Updated about a year ago· 7
HowToSD/ComfyUI-Pt-Wrapper
Nodes212
On cloudLocal install
CategoryData Analysis, Training
Stars7
Updatedabout a year ago

Nodes (212)

Hf Tokenizer Encode

One string away from BERT-ready tokens

Data Analysis
Pt Abs

Absolute value, minus the drama

Data Analysis
Pt Acos

Arccos, for when your angles need reversing

Data Analysis
Pt Add

The node under everything

Data Analysis
Pt Apply Function

Where the pack's callables actually get called

Training
Pt Arange

Roll your own index and position tensors

Data Analysis
Pt Argmax

The node that turns logits into a prediction

Data Analysis
Pt Argmin

The other arg-extreme, for distances and minima

Data Analysis
Pt Asin

Arcsin, the half of the trig pair nobody shows off

Data Analysis
Pt Atan

Arctan, the angle from a ratio

Data Analysis
Pt Bitwise And

Doing flag math inside ComfyUI

Data Analysis
Pt Bitwise Left Shift

Multiply by powers of two, one bit at a time

Data Analysis
Pt Bitwise Not

The simplest node in the pack, and when it's useful

Data Analysis
Pt Bitwise Or

How you set flags instead of checking them

Data Analysis
Pt Bitwise Right Shift

Floor-division by powers of two, the fast way

Data Analysis
Pt Bitwise Xor

Toggling bits and checking parity without Python

Data Analysis
Pt Bmm

The batched matrix multiply behind attention, without the Python

Data Analysis
Pt Bool Create

Hand-type a boolean tensor and get on with it

Data Analysis
Pt Compute Loss

The node the author told you not to use (mostly)

Training
Pt Concat

Stitch tensors together without leaving the graph

Data Analysis
Pt Cos

Cosines for your tensor math, radians included

Data Analysis
Pt Cosh

Hyperbolic cosine, the trig cousin you'll use twice a year

Data Analysis
Pt Crop

The node that will teach you ComfyUI images aren't what this pack wants

Data Analysis
Pt Data Loader

The feeding tube for your no-code training loop

Training
Pt Data Loader From Tensors

Skip the dataset, feed raw tensors straight to training

Training
Ptd Bernoulli

Coin-flip probabilities as a real distribution object

Distribution
Ptd Beta

A flexible distribution for probabilities and priors

Distribution
Ptd Binomial

How many successes out of n tries

Distribution
Ptd Categorical

Pick one outcome out of many

Distribution
Ptd Chi2

The chi-squared distribution, for stats and variance modeling

Distribution
Ptd Exponential

Waiting times and decay, as a distribution object

Distribution
Ptd Gamma

Ptd Gamma — define a Gamma distribution in the node graph, no Python required

Distribution
Pt Div

Pt Div — element-wise division, the humble node that saves you a step

Data Analysis
Ptdm Cdf

Ptdm Cdf — ask a distribution 'how likely is anything up to here?'

Distribution
Ptdm Cdf Tensor

Ptdm Cdf Tensor — the same CDF, but vectorized across a whole tensor

Distribution
Ptdm Icdf

Ptdm Icdf — the inverse CDF, for going from probability back to value

Distribution
Ptdm Icdf Tensor

Ptdm Icdf Tensor — invert a distribution for a whole batch of probabilities

Distribution
Ptdm Log Prob

Ptdm Log Prob — the log-probability node that's secretly the useful one

Distribution
Ptdm Log Prob Tensor

Ptdm Log Prob Tensor — score a whole tensor against a distribution in one shot

Distribution
Ptdm Pdf

Ptdm Pdf — how likely is this exact value? The density node, demystified

Distribution
Ptdm Pdf Tensor

Ptdm Pdf Tensor — draw the whole distribution shape at once

Distribution
Ptdm Pmf

Ptdm Pmf — the discrete answer to 'how likely is exactly k?'

Distribution
Ptdm Pmf Tensor

Ptdm Pmf Tensor — the whole probability histogram, one tensor at a time

Distribution
Ptdm Sample

Ptdm Sample — actually draw from the distribution, as a tensor

Distribution
Ptd Normal

Ptd Normal — the bell curve as a node, ready to sample and score

Distribution
Ptd Poisson

Ptd Poisson — a count distribution with the cdf/icdf that PyTorch forgot

Distribution
Ptd Student T

Ptd Student T — the fat-tailed distribution the pack had to rescue with scipy

Distribution
Ptd Uniform

Ptd Uniform — the simplest distribution in the pack, and a handy noise source

Distribution
Pt Einsum

Pt Einsum — the one node that replaces half the tensor-math drawer

Data Analysis
Pt Eq

Pt Eq — element-wise equality, the node behind masks, matches, and one-hots

Data Analysis
Pt Evaluate Classification Model

Pt Evaluate Classification Model — the report card for a model you trained in the graph

Training
Pt Exp

Raise any tensor to e^x, one node at a time

Data Analysis
Ptf GELU

The transformer's favorite activation, served as a function

Data Analysis
Pt Flatten

The bridge between conv layers and your classifier head

Data Analysis
Ptf Leaky ReLU

ReLU's fix for dead neurons, with one knob to turn

Data Analysis
Pt Float Create

Type numbers, get a float32 tensor

Data Analysis
Ptf Log Softmax

Softmax in log space, ready to plug in

Data Analysis
Pt Floor Div

Division that rounds down, on purpose

Data Analysis
Ptf ReLU

The default activation, as a callable component

Data Analysis
Pt From Image

The adapter between ComfyUI pixels and PyTorch math

Data Analysis
Pt From Image Transpose

The bridge that makes images usable by PyTorch models

Data Analysis
Pt From Latent

Crack open a latent so the math graph can see it

Data Analysis
Pt From Numpy

Hand a numpy array to PyTorch without losing its dtype

Data Analysis
Ptf Sigmoid

Squish scores into a 0-to-1 probability

Data Analysis
Ptf SiLU

The smooth ReLU that modern models actually use

Data Analysis
Ptf Softmax

Turn raw scores into a proper probability distribution

Data Analysis
Ptf Softplus

ReLU's smooth, never-quite-zero cousin

Data Analysis
Ptf Tanh

The centered activation that squeezes into -1 to 1

Data Analysis
Pt Full

Conjure a constant tensor out of thin air

Data Analysis
Pt Gather

Pulling specific elements out of a tensor, without losing your mind

Data Analysis
Pt Ge

Is tensor A at least tensor B, everywhere at once

Data Analysis
Pt Gt

Strict greater-than, as a node

Data Analysis
Pt Index Select

Pull the exact rows you want out of a tensor

Data Analysis
Pt Int Create

Type some integers, get a tensor back

Data Analysis
Pt Interpolate By Scale Factor

2x upscale any tensor, not just images

Data Analysis
Pt Interpolate To Size

Resize a tensor to an exact resolution

Data Analysis
Pt Le

The ≤ comparison that turns numbers into masks

Data Analysis
Pt Linspace

Evenly spaced numbers without typing them all

Data Analysis
Pt Load Model

Pick up where your last training run left off

Data Analysis
Pt Log

Natural log, element-wise, with a footgun in the docs

Data Analysis
Pt Logical And

The AND that makes masks composable

Data Analysis
Pt Logical Not

Flip a mask so True becomes False

Data Analysis
Pt Logical Or

Union of two masks, element-wise

Data Analysis
Pt Logical Xor

The 'exactly one' operator

Data Analysis
Pt Lt

The strict less-than comparison

Data Analysis
Pt Masked Select

Grab exactly the elements your mask says yes to

Data Analysis
Pt Mat Mul

The general matrix multiply, batches welcome

Data Analysis
Pt Max

The max along a dimension, values only — no argmax

Data Analysis
Pt Mean

The average along a dimension, for pooling and stats

Data Analysis
Pt Median

The middle value, with a torch quirk you should know

Data Analysis
Pt Min

The min along a dimension, values only

Data Analysis
Pt Mm

Matrix multiply, but strictly 2D only

Data Analysis
Pt Mul

Element-wise multiply — the scaling workhorse

Data Analysis
Ptn Avg Pool 2d

Shrink spatial dimensions the boring, reliable way

Training
Ptn Batch Norm 2d

The layer that keeps your conv net training sane

Training
Ptn BCE Loss

Binary cross-entropy for probabilities, not logits

Training
Ptn BCE With Logits Loss

The numerically stable binary classifier loss

Training
Ptn Chained Model

The glue node that lets you build your own network

Training
Ptn Chained Model With Attention Mask

Chaining models that need a mask

Training
Ptn Conv 2d

The single convolutional layer node

Training
Ptn Conv Model

A whole CNN from a few text fields, no coding

Training
Ptn Cross Entropy Loss

The default loss for multiclass classification

Training
Pt Ne

The not-equal comparison node

Data Analysis
Pt Neg

Flip every sign in a tensor at once

Data Analysis
Ptn Embedding

Turning token IDs into dense vectors

Training
Ptn Embedding RNN Linear

A text classifier in one node

Training
Ptn Embedding Transformer Linear

A Transformer text classifier in one node

Training
Ptn GRU

A gated recurrent layer for sequence data

Training
Ptn GRU Linear

The ready-made GRU text classifier

Training
Ptn Hf Fine Tuned Classification Model

Fine-tune BERT for sentiment analysis in ComfyUI, no Python required

Training
Ptn Hf Lora Classification Model

LoRA fine-tuning for HF text classifiers, without touching code

Training
Ptn Huber Loss

Huber loss as a node — MSE and L1, and you pick the boundary

Training
Ptn Instance Norm 2d

InstanceNorm2d for image feature maps, as a ComfyUI node

Training
Ptn KL Div Loss

KL divergence as a node — measuring how far one distribution is from another

Training
Ptn L1 Loss

Mean absolute error as a node — the outlier-proof regression loss

Training
Ptn Layer Norm

The stabilizer for transformer and image models

Training
Ptn Linear

The atom of every MLP you'll build

Training
Ptn Linear Model

Dim_list in, classifier out

Training
Ptn LSTM

Drop a real LSTM layer into ComfyUI without writing a single tensor

Training
Ptn LSTM Linear

The LSTM + classifier head combo node for text classification

Training
Ptn Masked Mean Pooling

Mean-pool a sequence while ignoring the padding tokens

Training
Ptn Max Pool 2d

Max pooling for 2D feature maps, as a string-typed node

Training
Ptn Model With Closure

Tack a sigmoid or softmax onto the end of any model, as a node

Training
Ptn MSE Loss

MSE as a node — the default regression loss, squared and averaged

Training
Ptn Multihead Attention

The multi-head attention block for building a transformer encoder

Training
Ptn Multihead Attention Custom

The multi-head attention you can read — the from-scratch version

Training
Ptn NLL Loss

NLL loss as a node — and why it needs log-probabilities, not logits

Training
Ptn Pre Add Channel Axis

Make grayscale images look like 4D tensors before your conv net sees them

Training
Ptn Pre Flatten

Flatten images into vectors before the MLP sees them

Training
Ptn Residual Connection Model

Building a residual block without a single line of Python

Training
Ptn Residual Connection Model With Attention Mask

A residual connection that knows about your attention mask

Training
Ptn Resnet Model

A real ResNet you can train, built from a few boxes

Training
Ptn RNN

Ptn RNN is the old-school sequence workhorse

Training
Ptn RNN Linear

Ptn RNN Linear goes from sequences straight to class scores

Training
Ptn Smooth L1 Loss

Ptn Smooth L1 Loss sits between L1 and L2

Training
Pto Adam

Pto Adam wraps Adam for the node graph

Training
Pto AdamW

Pto AdamW is Adam with weight decay done right

Training
Pto Lr Scheduler Cosine Annealing

Pto Lr Scheduler Cosine Annealing

Training
Pto Lr Scheduler Reduce On Plateau

Pto Lr Scheduler Reduce On Plateau lowers the rate only when progress stalls

Training
Pto Lr Scheduler Step

Pto Lr Scheduler Step drops the rate every N epochs

Training
Pt Ones

Pt Ones makes the ones() utility a node

Data Analysis
Pto SGD

Pto SGD does the classic update, momentum and all

Training
Pto Simple

Pto Simple does W -= lr * G

Training
Pt Pad

Pad an image tensor to a target size, centered, with black borders

Data Analysis
Pt Permute

Pt Permute is the transpose glue of this pack

Data Analysis
Pt Pow

Pt Pow raises one tensor to the power of another

Data Analysis
Pt Predict Classification Model

Pt Predict Classification Model runs your model on real inputs

Training
Pt Predict Regression Model

Run a trained regressor on new inputs and get a prediction tensor back

Training
Pt Prod

Pt Prod is the reduction nobody thinks about

Data Analysis
Pt Rand

Pt Rand rolls uniform noise in the shape you ask for

Data Analysis
Pt Rand Int

Random integer tensors without writing a line of Python

Data Analysis
Pt Randn

Gaussian noise on demand, straight into your graph

Data Analysis
Pt Remainder

The modulo operator, finally, as a node

Data Analysis
Pt Reshape

Reshape any tensor without touching its data

Data Analysis
Pt Save Model

Save your trained model without ever touching a terminal

Data Analysis
Pt Scatter

Write values into a tensor at exact positions

Data Analysis
Pt Show Size

See the shape of a tensor without printing to the console

Data Analysis
Pt Show Text

Look inside a tensor without leaving the ComfyUI window

Data Analysis
Pt Sin

For wave math, oscillators, and signal-style data

Data Analysis
Pt Sinh

The math node you'll use exactly when you need it

Data Analysis
Pt Size

Extract a tensor's shape as a first-class value

Data Analysis
Pt Size Create

Build a size object from a typed list — no tensor needed

Data Analysis
Pt Size To Numpy

Turn a tensor shape into a NumPy array

Data Analysis
Pt Size To String

A tensor shape as a string you can read, log, or wire onward

Data Analysis
Pt Sqrt

Square root, element-wise — the stats workhorse

Data Analysis
Pt Squeeze

Drop the pointless size-1 dimensions

Data Analysis
Pt Stack

Stack two tensors into one with a brand-new dimension

Data Analysis
Pt Std

Standard deviation along any dimension, with the correction you actually want

Data Analysis
Pt Sub

Subtract one tensor from another, element-wise

Data Analysis
Pt Sum

Add up a tensor along any dimension, or all of them

Data Analysis
Pt Tan

Tangent of a tensor? It's a node, and here's when you'd actually use it

Data Analysis
Pt Tanh

Tanh as a node — the activation you've been using without knowing it

Data Analysis
Pt To Bfloat16

The half-precision cast that keeps your gradients alive

Data Analysis
Pt To Float16

Half the memory, double the speed — casting tensors to fp16 mid-pipeline

Data Analysis
Pt To Float32

Casting tensors back to full-precision float32

Data Analysis
Pt To Float64

Need 64-bit precision? Pt To Float64 is the honest way to ask for it

Data Analysis
Pt To Image

The bridge that lets Pt tensors talk to the rest of ComfyUI

Data Analysis
Pt To Image Transpose

For when your tensor refuses to look like an image

Data Analysis
Pt To Int16

The dtype cast for when float32 feels like overkill

Data Analysis
Pt To Int32

The quiet workhorse cast of the Pt-Wrapper dtype family

Data Analysis
Pt To Int64

The cast that fixes every 'expected Long' error

Data Analysis
Pt To Int8

A naive cast to int8 — don't mistake it for quantization

Data Analysis
Pt Tokenizer

Turn sentences into the token IDs a transformer can eat

Data Analysis
Pt To Latent

Re-badge a tensor as a latent — no VAE involved

Data Analysis
Pt To Numpy

Step out of the tensor world without leaving the graph

Data Analysis
Pt To Rgb Tensors

Split an image into channels you can do real math on

Data Analysis
Pt To Uint8

Casting to image bytes — mind the wrapping

Data Analysis
Pt Train Classification Model

The simplest on-ramp to no-code training

Training
Pt Train Classification Model Lr

Train an image classifier in the graph — with a learning-rate schedule

Training
Pt Train Classification Transformer Model

Train a Transformer for text classification, built node by node

Training
Pt Train Fine Tune Classification Transformer Model

Fine-tune DistilBERT (or friends) for classification — no code, just nodes

Training
Pt Train Model

The do-anything trainer in Pt-Wrapper's no-code zoo

Training
Pt Train Regression Model

Predict numbers, not categories — the pack's regression trainer

Training
Pt Train RNN Model

Train an RNN, GRU, or LSTM for text classification — padding-aware and all

Training
Pt Unsqueeze

Grow a dimension where you need one

Data Analysis
Pt Var

Sample variance, population variance, and the one dial between them

Data Analysis
Ptv Dataset

Download a real ML dataset without leaving the graph

Training
Ptv Dataset Len

A sanity check for your training data

Training
Ptv Dataset Loader

The Pt Wrapper node that turns a public dataset into a training-ready DataLoader

Training
Ptv Hf Dataset With Token Encode

Text classification data, straight from Hugging Face

Training
Ptv Hf Glove Dataset

Skip the transformer, embed text with static GloVe vectors

Training
Ptv Hf Local Dataset

Feed your own JSONL or CSV into a text classifier

Training
Pt View

Reshape a tensor without leaving the graph

Data Analysis
Ptv Image Folder Dataset

Train a classifier on your own photos

Training
Ptv Sequential Tensor Dataset

Sliding windows for sequence models

Training
Ptv Transforms Data Augment

Make your tiny image dataset last longer

Training
Ptv Transforms Resize

Resize your training images without leaving the graph

Training
Ptv Transforms To Tensor

The image-to-tensor step every training pipeline needs

Training
Pt Where

The element-wise if/else your tensor math keeps needing

Data Analysis
Pt Zeros

A tensor full of zeros, on demand — more useful than it sounds

Data Analysis
Sp Encode

Tokenize text in the graph, then hand it off as a callable

Data Analysis
Sp Load Model

Load a SentencePiece tokenizer model — the text-tokenization on-ramp

Data Analysis
Readme

Logo

Update — April 6, 2025

Now You Can Try Building a Transformer Model from Scratch

You can use ComfyUI-Pt-Wrapper to build a Transformer encoder model from scratch for text classification.

Learn how to construct a Transformer encoder using basic components such as multi-head attention, layer normalization, linear layers, embedding layers, and residual connections. This workflow allows you to train the model for IMDB text classification and achieve around 85% accuracy!

Overview
The complete setup of all required nodes is included in the example workflow.

Check out the Building Transformer From Scratch guide.


ComfyUI-Pt-Wrapper

ComfyUI-Pt-Wrapper brings PyTorch model building and training into ComfyUI's node graph environment—no coding required.

It is built for ComfyUI users who want to explore machine learning without writing Python, and for researchers who want to prototype directly in visual workflows. Every operation, from tensor math to full training pipelines, can be configured through nodes.

Originally a focused spin-off of ComfyUI-Data-Analysis, this extension supports a wide range of ML workflows in image and text domains.


What It Offers

  • No-code training workflows for image and text classification
  • Use pre-built model nodes for major architecture such as ResNet, LSTM, GRU, Transformer, or create your own model from various model nodes.
  • Perform tensor operations like add, gather, scatter, where, etc.
  • Support for processing text (e.g. tokenization, embedding) to feed to a model
  • Featuring 200 nodes as of March 28, 2025.

Example Workflows

Dog vs. Cat Classifier — No Code Needed

Train an image classifier on your own dataset—entirely in ComfyUI nodes.

Step-by-step guide

ResNet on CIFAR-10

Train a ResNet achieving 94% validation accuracy. A flexible baseline for your own image classification tasks.

Training
Evaluation

Transformer for Text Classification

Train a text classification model using a configurable Transformer model—all node-based.

embedding_transformer_classification.json


Getting Started


Contributing

This project does not accept pull requests. Unsolicited PRs will be closed without review.

To suggest a feature or report an issue, open an Issue. All issues are reviewed and prioritized.


Node Reference

Every supported node is documented in detail. Browse the Node Reference to explore tensor operations, models, tokenization, distributions, loss functions, tensor operations and more.

Links in the reference section point directly to individual node docs for quick lookup.