Skip to content

Request for adding support for torch.rand_like, torch.randn_like, torch.randint_like with torch.Generator #101974

@liang-hou

Description

@liang-hou

🚀 The feature, motivation and pitch

This issue proposes adding support for torch.rand_like, torch.randn_like, and torch.randint_like with the torch.Generator parameter in PyTorch.

Motivation
The motivation behind this proposal is to provide users with greater flexibility and control over random number generation when using these functions. Currently, the torch.rand_like, torch.randn_like, and torch.randint_like functions do not support the torch.Generator parameter, while their underlying functions, torch.rand, torch.randn, and torch.randint, already do. By adding support for the torch.Generator parameter to these functions, users can have consistent control over random number generation across different operations.

Pitch
I suggest updating the function signatures as follows:

def rand_like(input, *, generator=None, ...):
    ...

def randn_like(input, *, generator=None, ...):
    ...

def randint_like(input, low, high=None, *, generator=None, ...):
    ...

The generator parameter would allow users to pass a torch.Generator object, with None as the default value. This would enable users to customize the random number generation process according to their specific requirements.

Alternatives

No response

Additional context

No response

cc @pbelevich

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: randomRelated to random number generation in PyTorch (rng generator)triagedThis 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