ComfyUI Node

Ptdm Log Prob

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

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptdm Log Prob
  • distribution
  • TENSOR
x

Everybody reaches for the PDF. The people who actually build things use the log-probability. PtdmLogProb computes log P(x) for a value under your distribution - and that's the form you want for real work, because raw probabilities underflow to zero the moment values get a little extreme, while log-probabilities stay sane. If you're scoring how well a model's distribution explains some observed data, this is the node.

It's part of ComfyUI-Pt-Wrapper, HowToSD's no-code PyTorch environment. It consumes a PTDISTRIBUTION from a Ptd* constructor and is one of the query nodes that actually gets used in the pack's training workflows - log-likelihood is how you'd compare distributions or compute a loss term in the graph.

How it works

The node parses your x with literal_eval, picks a dtype based on whether the distribution is discrete (int64 for the Poisson/Binomial/Categorical family, float32 otherwise), and calls distribution.log_prob(x). Note it returns the log of the probability directly - the pack's PtdmPdf node is literally torch.exp() of this. If the input isn't a number literal, you get the family's familiar "You need to specify a float or an int." error.

Inputs that matter

  • distribution - a PTDISTRIBUTION from a Ptd* node.
  • x - the value to score, as a text literal: 1.5, 0, or a tuple like (0.0, 1.0, 2.0).

Output is a TENSOR of log-probabilities. They'll be negative (or -inf for impossible values), and more negative = less likely. Wire it into a loss node or a plot to see the log-likelihood landscape.

Installing it

ComfyUI Manager → Install Custom Nodes → search "Pt Wrapper" → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

Restart ComfyUI after. Heavy first install (matplotlib, pandas, scipy, scikit-learn, transformers, datasets, pinned gensim), no model downloads for this node.

Common issues

The usual text-input trap applies - x must be a number literal. Beyond that, remember the output is a log, so a probability of 0 shows up as -inf and a value of 1.0 shows up as 0.0. Seeing -inf isn't a crash; it means your distribution assigns zero probability there, which is genuinely useful information when you're debugging a model that's confident in the wrong places.

CategoryDistribution

Inputs (2)

NameTypeDefaultDescription
distributionPTDISTRIBUTION
xSTRING

Outputs (1)

NameTypeDescription
TENSORTENSOR