ComfyUI Node

Ptd Bernoulli

Coin-flip probabilities as a real distribution object

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptd Bernoulli
    • PTDISTRIBUTION
    probs
    logits

    The Bernoulli distribution is the probability model for a single coin flip: an outcome that's 0 or 1, with some probability p of landing on 1. Ptd Bernoulli builds that distribution as a proper PyTorch Distribution object so the rest of the pack can sample from it, score it, and use it in loss functions. If your workflow involves dropout-style stochasticity, binary decisions, or any "success/failure" modeling, this is the distribution node you want.

    How it works

    You type in either probs or logits (exactly one - more on that below), the node parses it and hands back a PTDISTRIBUTION object. It's a genuine torch.distributions.Bernoulli under the hood, with one upgrade: the author subclasses it to add cdf and icdf methods that stock PyTorch doesn't provide, computing them through scipy. That's a large part of why scipy sits in this pack's requirements, and it means you can compute cumulative probabilities and their inverses right in the graph instead of reaching for a calculator.

    The output plugs into the pack's distribution-math nodes: Ptdm Sample (draw samples of a given shape), Ptdm LogProb (score a value), Ptdm Cdf / Icdf, Ptdm Pmf. Sample a bunch of Bernoulli draws and you've got a coin-flip generator; feed the distribution into a loss or a model closure and you're doing stochastic modeling without writing Python.

    The inputs that matter

    • probs - a Python literal: a scalar like 0.3, or a tuple like (0.2, 0.8) for a batched distribution.
    • logits - the log-odds form, same style of literal.

    The rule, enforced with a hard error: specify one or the other, never both, never neither. The author is explicit about it - pass both and you get "specify either probabilities or logits, but not both"; pass neither and you get a "you have to specify either" error. The fields default to empty strings, so leaving both blank is the most common way to trigger the second error.

    Where people get burned

    • The probs/logits exclusivity rule above - leave one empty, literally "".
    • Type what Python can parse: 0.5 and (0.1, 0.9) work; 0.5, 0.9 without parentheses doesn't, because it's parsed with ast.literal_eval.
    • Probabilities outside [0,1] won't be rejected at construction - Bernoulli will just behave oddly when you sample. Garbage in, weird coins out.

    Installing it

    It's in ComfyUI-Pt-Wrapper:

    • ComfyUI Manager → search "ComfyUI-Pt-Wrapper" → Install → restart.
    • Or cd ComfyUI/custom_nodes && git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper and restart.

    The pack installs a heavy dependency stack - transformers, datasets, peft, accelerate, scikit-learn, scipy, gensim, sentencepiece - so the first launch after install takes a while. The scipy dependency specifically matters here because these distribution nodes lean on it. No model files needed. It's a niche educational pack (by HowToSD) with little community chatter; docs/reference/ in the repo is the authoritative doc.

    CategoryDistribution

    Inputs (2)

    NameTypeDefaultDescription
    probsSTRING
    logitsSTRING

    Outputs (1)

    NameTypeDescription
    PTDISTRIBUTIONPTDISTRIBUTION