Skip to content

To fix inconsistency between signature and doc on torch.bernoulli()Β #152095

@ILCSFNO

Description

@ILCSFNO

πŸ“š The doc issue

The doc of torch.bernoulli() shows its description as below:

torch.bernoulli(input: Tensor, *, generator: Optional[Generator], out: Optional[Tensor]) β†’ Tensor
Draws binary random numbers (0 or 1) from a Bernoulli distribution.
...

For its signatures in codes, it showed like this:

@overload
def bernoulli(input: Tensor, *, generator: Optional[Generator] = None, out: Optional[Tensor] = None) -> Tensor: 
@overload
def bernoulli(input: Tensor, p: _float, *, generator: Optional[Generator] = None) -> Tensor: 

They diff on the param p, for validate, repro below shows that torch.bernoulli() can have this param:

Repro

import torch
import numpy as np
input_data = torch.empty(10, 2).uniform_(0, 1)
output_data = torch.bernoulli(input_data, 0.3)
print(output_data)

Output

tensor([[0., 0.],
        [0., 0.],
        [0., 0.],
        [0., 0.],
        [0., 1.],
        [1., 0.],
        [0., 0.],
        [1., 0.],
        [0., 0.],
        [0., 1.]])

Suggest to fix the doc to meet the signatures in codes.

Thanks for noting.

Suggest a potential alternative/fix

  • Suggest to fix the doc to meet the signature in codes.

cc @fritzo @neerajprad @alicanb @nikitaved @svekars @sekyondaMeta @AlannaBurke

Metadata

Metadata

Assignees

No one assigned

    Labels

    actionablemodule: distributionsRelated to torch.distributionsmodule: docsRelated to our documentation, both in docs/ and docblockstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions