Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove out parameter from functions in PyTorch to simplify the functions and the documentation #126016

Closed
hyperkai opened this issue May 12, 2024 · 1 comment

Comments

@hyperkai
Copy link

馃殌 The feature, motivation and pitch

In PyTorch, there is out parameter in many functions like matmul(), rand(), arrange().

For example, I find the pros of matmul() with out parameter is that the result is displayed with one line of code different from matmul() without out parameter which are two lines of code using IPython, Jupyter Notebook, Google Colab, etc as shown below:

import torch

tensor1 = torch.tensor([0, 1, 2])
tensor2 = torch.tensor([3, 4, 5])
new_tensor = torch.tensor(0)

# One line of code
torch.matmul(input=tensor1, other=tensor2, out=new_tensor) # tensor(14)

# Two lines of code
new_tensor = torch.matmul(input=tensor1, other=tensor2)
new_tensor # tensor(14)

About out parameter of functions in PyTorch:

Pros:

  1. Less lines of code.

Cons:

  1. People will write either of 2 ways(with or without out parameter) so it breaks the consistency of how people write code so such a code is less readable, less efficient and less productive which is seriously bad.
  2. It makes PyTorch documentation complicated (I mean It is not simple because of out parameter.).

So, I think out parameter has more disadvantages than advantages so out parameter should be removed to simplify the functions and the documentation.

Alternatives

No response

Additional context

No response

@ezyang
Copy link
Contributor

ezyang commented May 14, 2024

For BC reasons we are not going to do this

@ezyang ezyang closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants