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

Fix Frontend Failing Test: torch - math.paddle.stanh #28493

Merged
merged 5 commits into from
May 2, 2024

Conversation

ZJay07
Copy link
Contributor

@ZJay07 ZJay07 commented Mar 6, 2024

PR Description

Failing because of exp returning NaN or inf due to large x, scale_a, scale_b values. Fixed by limit those values from being too large

Related Issue

Close #28492
Close #28547
Close #28546
Close #28545
Close #28544

Checklist

  • Did you add a function?
  • Did you add the tests?
  • Did you run your tests and are your tests passing?
  • Did pre-commit not fail on any check?
  • Did you follow the steps we provided?

Socials

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

PR Compliance Checks

Thank you for your Pull Request! We have run several checks on this pull request in order to make sure it's suitable for merging into this project. The results are listed in the following section.

Issue Reference

In order to be considered for merging, the pull request description must refer to a specific issue number. This is described in our contributing guide and our PR template.
This check is looking for a phrase similar to: "Fixes #XYZ" or "Resolves #XYZ" where XYZ is the issue number that this PR is meant to address.

Conventional Commit PR Title

In order to be considered for merging, the pull request title must match the specification in conventional commits. You can edit the title in order for this check to pass.
Most often, our PR titles are something like one of these:

  • docs: correct typo in README
  • feat: implement dark mode"
  • fix: correct remove button behavior

Linting Errors

  • Found type "null", must be one of "feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"
  • No subject found

@ivy-leaves ivy-leaves added the Paddle Frontend Developing the Paddle Frontend, checklist triggered by commenting add_frontend_checklist label Mar 6, 2024
Copy link
Contributor

@Ishticode Ishticode left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR @ZJay07 :)

Copy link
Contributor

@Ishticode Ishticode left a comment

Choose a reason for hiding this comment

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

Although, the test_paddle_stanh seems to still fail with paddle and torch backends. You can see that in the logs at https://github.com/unifyai/ivy/actions/runs/8232013594/job/22509022640?pr=28493
Are you able to fix for these two?

@ZJay07
Copy link
Contributor Author

ZJay07 commented Mar 11, 2024

Yup, happy to fix it, seems like some results are producing NaN or 0 instead, do you think reducing the min and max of x, scale_a, scale_b values would be sufficient?

The error seems hard to replicate since it still passes on my local branch

@ZJay07 ZJay07 requested a review from Ishticode March 11, 2024 16:55
Copy link
Contributor

@Ishticode Ishticode left a comment

Choose a reason for hiding this comment

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

You shold be able to reproduce the errors using the falsifying examples in the failure logs. Like one example for the failure of test_paddle_stanh is given as

[array([[[-1.0000000e+00, -1.0000000e+00],
E                 [-1.0000000e+00, -1.0000000e+00],
E                 [-1.0000000e+00, -1.0000000e+00],
E                 [-1.0000000e+00, -1.0000000e+00]],
E         
E                [[-9.0909090e+00, -1.2930438e-38],
E                 [-1.8302815e-38, -2.3399685e-38],
E                 [-1.2930438e-38, -1.9542594e-38],
E                 [-1.2930438e-38, -1.0000000e+00]]], dtype=float32)]),
E       scale_a=10.0,
E       scale_b=1.0,

so you can write something like

import ivy
import ivy.functional.frontends.paddle as ivy_paddle
ivy.set_backend("torch")
x = ivy.arrayarray([[[-1.0000000e+00, -1.0000000e+00],
[-1.0000000e+00, -1.0000000e+00],
[-1.0000000e+00, -1.0000000e+00],
[-1.0000000e+00, -1.0000000e+00]],

[-9.0909090e+00, -1.2930438e-38],
[-1.8302815e-38, -2.3399685e-38],
[-1.2930438e-38, -1.9542594e-38],
[-1.2930438e-38, -1.0000000e+00]]], dtype="float32")])
scale_a=10.0
scale_b=1.0

and add the same with native paddle

import paddle
x = paddle.to_tensor([[[-1.0000000e+00, -1.0000000e+00],
                [-1.0000000e+00, -1.0000000e+00],
                [-1.0000000e+00, -1.0000000e+00],
                [-1.0000000e+00, -1.0000000e+00]],
               [[-9.0909090e+00, -1.2930438e-38],
               [-1.8302815e-38, -2.3399685e-38],
               [-1.2930438e-38, -1.9542594e-38],
               [-1.2930438e-38, -1.0000000e+00]]], dtype="float32")
scale_a=10.0
scale_b=1.0
print(paddle.stanh(x, scale_a, scale_b))

and you will see the value difference and why the test failed as ivy's paddle frontend's behaviour differs from native paddle.

My point is try to reconstruct the failing example from the falsifying examples provided in the logs and this way you can always reproduce and debug quickly. Thank you very much :)

@ZJay07 ZJay07 requested a review from Ishticode April 2, 2024 17:00
@ZJay07
Copy link
Contributor Author

ZJay07 commented Apr 2, 2024

Hey @Ishticode, I just updated the backend paddle code to accept stanh and re-cast it back to the same dtype as x as per paddle docs, also added some factors to scale_a and scale_b that is similar to addmm in the same file

Copy link
Contributor

@Ishticode Ishticode left a comment

Choose a reason for hiding this comment

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

now it seems to behave well :) haha
Thanks @ZJay07 for the fix

@Ishticode Ishticode merged commit a609e40 into ivy-llc:main May 2, 2024
249 of 277 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Paddle Frontend Developing the Paddle Frontend, checklist triggered by commenting add_frontend_checklist
Projects
None yet
3 participants