Ptdm Sample
Ptdm Sample — actually draw from the distribution, as a tensor
- distribution
- TENSOR
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
PTDISTRIBUTIONfrom aPtd*constructor. - sample_shape - text literal.
100for 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.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| distribution | PTDISTRIBUTION | — | |
| sample_shape | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |