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 check for second value in sum: Logsumexp #90

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shivam096
Copy link

Added conditions to check if second value exists in "sum" for Logsumexp update. If not then no change.

Files updated:

  • torchfix/visitors/misc/init.py
  • tests/fixtures/misc/checker/logsumexp.py

@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 Jan 23, 2025
@@ -183,7 +183,7 @@ def visit_Call(self, node):
node.args[0].value.args[0].value
)
== "torch.exp"
):
) and len(node.args[0].value.args) > 1 and node.args[0].value.args[1].value is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Use get_specific_arg from https://github.com/pytorch-labs/torchfix/blob/main/torchfix/common.py#L64 because dim can be passed as a positional or as a keyword argument.

Copy link
Author

Choose a reason for hiding this comment

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

Updated and added condition to check for dim. But I used has_specific_arg since we just want to check its presence

@shivam096 shivam096 requested a review from kit1980 January 24, 2025 20:18
message=self.ERRORS[0].message(),
replacement=None,
)
if len(node.args[0].value.args) > 1 and (
Copy link
Contributor

@kit1980 kit1980 Jan 24, 2025

Choose a reason for hiding this comment

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

I don't think value.args[1] is always correct, because the order may be different for keyword arguments.
For example, add test y = torch.log(torch.sum(torch.exp(x)), keepdim=True, dim=None).

I think you can delete most if this and just use get_specific_arg("dim", 1), which will return None if the argument is not present.

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