-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Request for adding support for torch.rand_like, torch.randn_like, torch.randint_like with torch.Generator #101974
Description
🚀 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