Skip to content

Conversation

@vladimirrotariu
Copy link
Contributor

The current formula behind torch.isclose, according to the docs, is
imagen

However, torch.isclose acts element-wise, so this formula may be misleading at first, given that the docs said that input and other are the first, respectively second tensor to compare. I propose the following change, to stress the element-wise nature of the norms in the equation:
imagen

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 21, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/138459

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures

As of commit 9762576 with merge base 14fc6b7 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the release notes: python_frontend python frontend release notes category label Oct 21, 2024
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 21, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Contributor

@soulitzer soulitzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is clearer. Adding the "forall" here feels like could be confused with the behavior of allclose.

@soulitzer soulitzer added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Oct 28, 2024
@vladimirrotariu
Copy link
Contributor Author

Hi @soulitzer, thanks for stepping in! In case you refer to the equation that is in the docs for torch.allclose, I would indeed also change that one with \forall as well, as torch.allclose also acts element-wise, and moreover it bases the comparisons on the same equation.

@vladimirrotariu vladimirrotariu deleted the dev_improve_eq_isclose branch October 28, 2024 22:42
@vladimirrotariu vladimirrotariu restored the dev_improve_eq_isclose branch October 28, 2024 22:43
.. math::
\lvert \text{input} - \text{other} \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other} \rvert
\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other}_i \rvert \quad \forall i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove \forall ?

I do agree that it makes sense to add the subscript, e.g. to match https://pytorch.org/docs/stable/generated/torch.add.html#torch.add and other element-wise type operations.

But for me that forall seems to indicate that the function will return True/False based on whether EVERY element-wise comparison returned true.

\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other}_i \rvert \quad \forall i
"""
+ r"""
elementwise, for all elements of :attr:`input` and :attr:`other`. The behaviour of this function is analogous to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO \forall does make sense for allclose, but it is already mentioned here in text. We should keep one or the other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soulitzer now I see what you mean :)

@vladimirrotariu
Copy link
Contributor Author

@soulitzer, do you have any other suggestions?

Copy link
Contributor

@soulitzer soulitzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@soulitzer
Copy link
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 31, 2024
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@vladimirrotariu
Copy link
Contributor Author

Hi @soulitzer, I cannot explain to myself why these 2 checks failed, given that we modified just the docstrings. Could you please indicate to me what would be the next step?

@soulitzer
Copy link
Contributor

@vladimirrotariu those tests should be unrelated :) I will retry the land

@soulitzer
Copy link
Contributor

@pytorchbot merge -i

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: pull / linux-jammy-py3-clang12-executorch / test (executorch, 1, 1, linux.2xlarge), trunk / linux-focal-cuda12.4-py3.10-gcc9-sm86 / test (default, 3, 5, linux.g5.4xlarge.nvidia.gpu)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

rahulsingh-intel pushed a commit to rahulsingh-intel/pytorch that referenced this pull request Nov 5, 2024
The current formula behind torch.isclose, according to the docs, is
![imagen](https://github.com/user-attachments/assets/6b79f6d8-e675-4585-b26b-0c6933f7ecdd)

However, torch.isclose acts element-wise, so this formula may be misleading at first, given that the docs said that `input` and `other` are the first, respectively second tensor to compare. I propose the following change, to stress the element-wise nature of the norms in the equation:
![imagen](https://github.com/user-attachments/assets/2926a1c6-c4fa-4c48-8874-106521d3f54c)
Pull Request resolved: pytorch#138459
Approved by: https://github.com/soulitzer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: python_frontend python frontend release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants