Skip to content

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 meta-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
DISABLED_BY_DEFAULT = ["TOR3", "TOR4", "TOR9"]

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
Contributor

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
Contributor

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
Contributor

Nice catch, LGTM

@sbrugman
Copy link
Contributor

sbrugman commented Sep 17, 2024

Let's also add meta-pytorch/botorch#2541 / meta-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
@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.

4 participants