Skip to content

Optional tag like keepdim may have been removed in several funcs #151104

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

Closed
ILCSFNO opened this issue Apr 11, 2025 · 1 comment
Closed

Optional tag like keepdim may have been removed in several funcs #151104

ILCSFNO opened this issue Apr 11, 2025 · 1 comment
Labels
actionable module: docs Related to our documentation, both in docs/ and docblocks module: python frontend For issues relating to PyTorch's Python frontend triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@ILCSFNO
Copy link
Contributor

ILCSFNO commented Apr 11, 2025

📚 The doc issue

Seen from #146156 and its PR pull#146485, maybe some other funcs also have optional tags removed:

What I met is torch.any(), but suggest fix this by change the description of keepdim and any other similar arguments, for that there may be more funcs that have similar problem.

Note that there may have some funcs that has keepdim or any other similar arguments not optional. So change the description of them may have risk!

.. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
:noindex:
For each row of :attr:`input` in the given dimension :attr:`dim`,
returns `True` if any element in the row evaluate to `True` and `False` otherwise.
{keepdim_details}
Args:
{input}
{dim}
{keepdim}
Keyword args:
{out}
Example::
>>> a = torch.randn(4, 2) < 0
>>> a
tensor([[ True, True],
[False, True],
[ True, True],
[False, False]])
>>> torch.any(a, 1)
tensor([ True, True, True, False])
>>> torch.any(a, 0)
tensor([True, True])
""".format(**multi_dim_common),

While keepdim is showed here:

multi_dim_common = merge_dicts(
reduceops_common_args,
parse_kwargs(
"""
dim (int or tuple of ints): the dimension or dimensions to reduce.
"""
),

reduceops_common_args = merge_dicts(
common_args,
parse_kwargs(
"""
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
keepdim (bool): whether the output tensor has :attr:`dim` retained or not.
"""
),

Some similar arguments may include dim, etc.

Suggest to solve it together with #146156

Suggest a potential alternative/fix

I suggest any one below:

  • Change the description of keepdim and any other similar arguments from origin def (have risk)
  • Change the description of keepdim and any other similar arguments one by one (long time to fix)

Thanks for noting!

cc @svekars @sekyondaMeta @AlannaBurke @albanD

@soulitzer soulitzer added module: docs Related to our documentation, both in docs/ and docblocks triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: python frontend For issues relating to PyTorch's Python frontend actionable labels Apr 11, 2025
@soulitzer
Copy link
Contributor

Thanks for the report, we'd accept PRs to fix missing optional tags
Although it also looks like we aren't very good at tagging with optional in general, e.g. for dim as well.

amathewc pushed a commit to amathewc/pytorch that referenced this issue Apr 17, 2025
Fixes pytorch#151104

Fix optional description of `dim`  and `keepdim`, except `torch.quantile` which already fixed in pytorch#146485

## Test Result

### Before

![image](https://github.com/user-attachments/assets/69f1824d-3d15-407e-8c92-f25a22e16914)

### After

![image](https://github.com/user-attachments/assets/e5aac674-ab8f-4988-a5f1-7400c36bdc99)

Pull Request resolved: pytorch#151197
Approved by: https://github.com/mikaylagawarecki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable module: docs Related to our documentation, both in docs/ and docblocks module: python frontend For issues relating to PyTorch's Python frontend triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants