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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The unexpected behavior of min() #126758

Open
hyperkai opened this issue May 21, 2024 · 1 comment
Open

The unexpected behavior of min() #126758

hyperkai opened this issue May 21, 2024 · 1 comment
Labels
actionable module: error checking Bugs related to incorrect/lacking error checking triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@hyperkai
Copy link

hyperkai commented May 21, 2024

🐛 Describe the bug

min() with input and keepdim argument gets the error but min() with input and dim doesn't get error even though the error message doesn't have such a combination as shown below:

import torch

my_tensor = torch.tensor([0, 1, 2])

torch.min(input=my_tensor, keepdim=True) # Error

torch.min(input=my_tensor, dim=0)
# torch.return_types.min(
# values=tensor(0),
# indices=tensor(0))
TypeError: min() received an invalid combination of arguments - got (keepdim=bool, input=Tensor, ), but expected one of:
 * (Tensor input, *, Tensor out)
 * (Tensor input, Tensor other, *, Tensor out)
 * (Tensor input, int dim, bool keepdim, *, tuple of Tensors out)
 * (Tensor input, name dim, bool keepdim, *, tuple of Tensors out)

And following the error message above, I couldn't use min() with input and the name type of dim argument as shown below but the name type of dim argument is not explained in the doc of min():

import torch

my_tensor = torch.tensor([0, 1, 2])

torch.min(input=my_tensor, dim='zero') # RuntimeError: Name 'zero' not found in Tensor[None].

Versions

import torch

torch.__version__ # 2.2.1+cu121

cc @malfet

@janeyx99
Copy link
Contributor

We would accept a PR making the typechecking consistent with what is supported.

@janeyx99 janeyx99 added module: error checking Bugs related to incorrect/lacking error checking triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module actionable labels May 21, 2024
pytorchmergebot pushed a commit that referenced this issue May 28, 2024
Fixes #[126758](#126758) and #[126759](#126759)

The output information in the issue is not accurate because `FunctionSignature::toString()` print the schema strings without default.
https://github.com/pytorch/pytorch/blob/cb6ef68caa22c1a2f7a4e8583c0e7c923c8bfd17/torch/csrc/utils/python_arg_parser.cpp#L1282-L1283
This pr, by adding a `default_value` to save the default str ,which shoule be priented. Of course, can also add an new api to reverse `default_bool/default_int` to string, which is slightly more complicated.
result:
![image](https://github.com/pytorch/pytorch/assets/37650440/f58a4cbf-b0f4-4c81-9106-59f0d35c54ea)

Pull Request resolved: #127059
Approved by: https://github.com/janeyx99
Aidyn-A pushed a commit to tinglvv/pytorch that referenced this issue May 30, 2024
Fixes #[126758](pytorch#126758) and #[126759](pytorch#126759)

The output information in the issue is not accurate because `FunctionSignature::toString()` print the schema strings without default.
https://github.com/pytorch/pytorch/blob/cb6ef68caa22c1a2f7a4e8583c0e7c923c8bfd17/torch/csrc/utils/python_arg_parser.cpp#L1282-L1283
This pr, by adding a `default_value` to save the default str ,which shoule be priented. Of course, can also add an new api to reverse `default_bool/default_int` to string, which is slightly more complicated.
result:
![image](https://github.com/pytorch/pytorch/assets/37650440/f58a4cbf-b0f4-4c81-9106-59f0d35c54ea)

Pull Request resolved: pytorch#127059
Approved by: https://github.com/janeyx99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable module: error checking Bugs related to incorrect/lacking error checking triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

2 participants