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

Add TorchLog1pVisitor #77

Merged
merged 2 commits into from
Sep 17, 2024
Merged

Add TorchLog1pVisitor #77

merged 2 commits into from
Sep 17, 2024

Conversation

kit1980
Copy link
Contributor

@kit1980 kit1980 commented Sep 16, 2024

Suggest using torch.log1p(x) instead of torch.log(1 + x).
Only a checker for now, probably not worth spending time on a codemod as it's not a very common issue.

I used this to create a PR to botorch pytorch/botorch#2539

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 16, 2024
@@ -28,15 +29,16 @@

ALL_VISITOR_CLS = [
TorchDeprecatedSymbolsVisitor,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any ideas how to avoid this ugly duplication of all visitors?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, we can automatically pick them up with a registry pattern. Already got something in progress for this.

b = torch.log(1 + a)
c = torch.log(a + 1)
b = torch.log(1.0 + a)
c = torch.log(a + 1.0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we already add Array API examples here? We don't have the capability of automatically detecting them at the moment, but it's good to be explicit about the known false negatives, especially when we can catch them later

import torch

a = torch.randn(5)

print((a + 1).log())
print(a.log1p())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a false negative.

@sbrugman
Copy link
Collaborator

Nice catch, LGTM

@sbrugman
Copy link
Collaborator

sbrugman commented Sep 17, 2024

Let's also add pytorch/botorch#2541 / pytorch/botorch#2540 in a follow-up

@kit1980
Copy link
Contributor Author

kit1980 commented Sep 17, 2024

Let's also add pytorch/botorch#2541 / pytorch/botorch#2540 in a follow-up

I'll add expm1. Looks like Botorch guys were hinted by my PR about log1p.

@kit1980 kit1980 merged commit 7bf6f67 into main Sep 17, 2024
3 checks passed
@sbrugman sbrugman deleted the sdym/log1p branch September 17, 2024 17:53
@kit1980 kit1980 mentioned this pull request Sep 17, 2024
kit1980 added a commit that referenced this pull request Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants