ComfyUI Node

Pt Log

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

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Log
  • tens_a
  • TENSOR

One input, one output, no settings: Pt Log applies the natural logarithm - base e - to every element of a tensor. It's torch.log, and if you know why you're logging something you already know why this node exists. If you don't, here's the pitch: logarithms turn multiplicative relationships into additive ones and compress big ranges, which is why they show up in loss functions, feature normalization, and anywhere you're rescaling something that spans orders of magnitude.

How it works

f(tens_a) literally returns torch.log(tens_a). That's the entire mechanism - element-wise ln(x) for every value in the input tensor, same shape out. The single input is tens_a (TENSOR, required), and the output is a single TENSOR.

The footgun the docs themselves warn about

The pack's own docstring says the input "must contain only positive values," and it means it. The math is unforgiving:

  • log(0)-inf. It won't crash, it'll just quietly inject negative infinity into your tensor and poison everything downstream.
  • log(negative)NaN. Same story, quieter.

So if your data could ever touch zero or go negative - logits with negative values, differences that can be zero, anything un-clamped - you must clamp or shift it first with a math node before it hits Pt Log. Getting a wall of NaN out of a downstream training run is the classic way people discover they skipped that step.

When you'd actually use it

In the pack's world: computing log-loss style objectives, normalizing values that live on wildly different scales, or turning probabilities into log-probabilities for stable math. It's a utility node - rarely the star of a workflow, always quietly necessary when the math calls for it.

Installing

Pt Log is part of the HowToSD/ComfyUI-Pt-Wrapper pack, in the "Data Analysis" menu. Install the pack once for this plus ~200 siblings. ComfyUI Manager: search ComfyUI-Pt-Wrapper, install, restart. Or:

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

The pack's requirements.txt is heavy (transformers, datasets, peft, accelerate…) - that's for training, not for log. This node needs only PyTorch, already present, so skip the pip line if you're just doing math. No models to download.

Standard pack reminder: its tensors use the custom TENSOR type, separate from ComfyUI's IMAGE/LATENT. Bridge with Pt From Image (Pt From Image Transpose for (b, c, h, w)) and Pt To Image.

CategoryData Analysis

Inputs (1)

NameTypeDefaultDescription
tens_aTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR