ComfyUI Node

Ptd Gamma

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

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptd Gamma
    • PTDISTRIBUTION
    alpha
    beta

    The Gamma distribution is the workhorse of Bayesian stats - it models wait times, rainfall, insurance claims, and most usefully, it's the conjugate prior for the rate of a Poisson. PtdGamma is how you create one inside ComfyUI without leaving the graph. You give it a shape and a rate, it hands you a PTDISTRIBUTION object, and from there you can sample, score, or invert it with the pack's Ptdm* nodes.

    This node comes from ComfyUI-Pt-Wrapper, Hide Inada's no-code PyTorch lab for ComfyUI (a spin-off of his ComfyUI-Data-Analysis). It's not a diffusion node - it's for the crowd doing ML prototyping, statistics, or plotting in the graph instead of in a notebook. If that's not you, this node is dead weight. If it is you, it's genuinely handy.

    How it works

    Under the hood it builds a torch.distributions.Gamma, then wraps it in a small subclass the pack calls GammaEx. That subclass exists for one reason: PyTorch's Gamma implements cdf but not icdf. The Ex version fills that gap using scipy.stats.gamma.ppf, which is exactly why scipy shows up in the pack's requirements. So PtdGamma -> PtdmIcdf works, where plain PyTorch would throw NotImplementedError.

    Inputs that matter

    Both inputs are text boxes, not number widgets, and the pack parses them with Python's literal_eval:

    • alpha - the shape (concentration) parameter. A scalar like 2.0 or a tuple like (1.0, 2.0, 3.0) for a batch of distributions.
    • beta - the rate parameter. Same deal: 1.0, or a tuple to match alpha.

    Just type the literal - no quotes, no torch.tensor(...), no function call. 2.0 not 2 if you want float behavior, and keep the two shapes aligned or you'll get a broadcast error.

    The single output is PTDISTRIBUTION, which is the pack-wide type that every PtdmCdf, PtdmPdf, PtdmSample, and so on consumes. That's the whole flow: build a distribution with a Ptd* node, then hang query nodes off it.

    Installing it

    Through ComfyUI Manager: Install Custom Nodes → Search → "Pt Wrapper" (the pack title is ComfyUI-Pt-Wrapper), install, restart. Or manually:

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

    Then restart ComfyUI. Note the first install is heavy: the pack pulls matplotlib, pandas, scipy, scikit-learn, transformers, datasets, and pins gensim==4.3.2. Give it a few minutes. Nothing here downloads model files - the distribution nodes are pure math.

    Common issues

    The big one is mistyping the text inputs. If alpha is empty or has a typo, literal_eval raises a SyntaxError and the node red-flags. Enter a real Python literal or leave the field sensible before you queue. Also remember beta is the rate, not the scale - a common confusion if you're coming from a stats package that parameterizes by scale. And if you run PtdmCdf on a Gamma you'll get a result, but PtdmIcdf relies on the pack's scipy shim, so don't skip the install of the full requirements or that node breaks while its sibling works.

    CategoryDistribution

    Inputs (2)

    NameTypeDefaultDescription
    alphaSTRING
    betaSTRING

    Outputs (1)

    NameTypeDescription
    PTDISTRIBUTIONPTDISTRIBUTION