ComfyUI Node

Ptdm Sample

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

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptdm Sample
  • distribution
  • TENSOR
sample_shape

Sampling is where a distribution stops being a formula and becomes data. PtdmSample draws random values from any Ptd* distribution and hands them to you as a TENSOR - and this is probably the node you'll reach for most in the whole family. Generate synthetic training data, inject noise with a principled shape, bootstrap a dataset, or just see what a distribution actually produces. One distribution in, a tensor of random draws out.

It's part of ComfyUI-Pt-Wrapper, HowToSD's no-code PyTorch environment. Sampling slots directly into the pack's wider story - if you're building a synthetic-data pipeline to feed a PtDataLoader before training a classifier, this is the node that manufactures the data.

How it works

It parses your sample_shape with literal_eval, and here's a nice touch: if you give it a plain integer like 100, it wraps it into a tuple (100,) for you. Then it calls distribution.sample(shape) and returns the tensor. The shape you give is the sample shape - it stacks on top of the distribution's own batch shape. So a single normal sampled with (1000,) gives you a 1000-element tensor; a batch of three normals sampled with (1000,) gives you a (1000, 3) tensor.

Inputs that matter

  • distribution - a PTDISTRIBUTION from a Ptd* constructor.
  • sample_shape - text literal. 100 for a flat batch, (4, 100) for a structured one.

Output is a TENSOR of random draws. Discrete distributions (Poisson, etc.) produce integer draws; continuous ones produce floats.

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) - sampling itself is pure torch, no model downloads.

Common issues

Two things. First, the text input: 100 and (100,) are the same, but 100.0 is not - a float shape raises a type error, so keep it integer syntax. Second, remember torch sampling is seeded from whatever RNG state ComfyUI has; if you need reproducible draws, seed upstream with the pack's seed/tensor-creation nodes, because every run through PtdmSample will otherwise differ. That's usually what you want, but it bites when you're debugging.

CategoryDistribution

Inputs (2)

NameTypeDefaultDescription
distributionPTDISTRIBUTION
sample_shapeSTRING

Outputs (1)

NameTypeDescription
TENSORTENSOR