Implementation of Bernoulli distribution

Hi everybody,

I am exploring Pytorch code. I manage to run the code in debug mode.


   m = Bernoulli(torch.tensor([0.3]))
    s = m.sample()  # 30% chance 1; 70% chance 0
    print('a sample: ', s)

    # calling directly
    print('calling directly torch.bernoulli()', torch.bernoulli(torch.Tensor([0.3])))

I tried to find where torch.bernoulli was implemented but couldn’t find it. Pycharm just indicates this is a built-in function.

Thank you for your time!

You can find Bernoulli and other distributions in torch.distributions.

torch.distributions.Bernoulli called torch.bernoulli(), which, I think, is implemented using C++.

Sorry, I clearly misunderstood your question,
I thought you are looking for the documentation.

I think the source code can be found here:

Thanks for your help! (sorry for the late thanks)