-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Fix arctan2 NaN propagation in OpenVINO backend #22064
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
base: master
Are you sure you want to change the base?
Fix arctan2 NaN propagation in OpenVINO backend #22064
Conversation
Summary of ChangesHello @MalyalaKarthik66, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue in the OpenVINO backend where the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #22064 +/- ##
=======================================
Coverage 82.80% 82.80%
=======================================
Files 592 592
Lines 62463 62468 +5
Branches 9783 9783
=======================================
+ Hits 51723 51728 +5
Misses 8210 8210
Partials 2530 2530
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request addresses an issue with NaN propagation in the OpenVINO backend for the arctan2 function. The changes involve adding NaN checks for the input tensors x1 and x2, creating a NaN mask, and using this mask to selectively output NaN values when either input is NaN. A new test case is also added to verify the correct NaN propagation.
| # Generate NaN safely for all floating dtypes (including bf16) | ||
| nan_value = ov_opset.divide(zero_const, zero_const) | ||
| final_out = ov_opset.select(nan_mask, nan_value, value_out) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dividing by zero can be unsafe. While this is intended to generate NaN, it might be better to use ov_opset.constant(float('nan'), ov_type) directly if OpenVINO supports it for all floating-point types, as it would be more explicit and potentially more efficient. If it doesn't support it for all floating point types, then the current approach is fine, but it would be good to add a comment explaining why this approach is necessary to generate NaN safely for all floating-point types, including bf16.
| neg_half_pi = ov_opset.constant(-float(np.pi / 2), ov_type) | ||
| zero_const = ov_opset.constant(0.0, ov_type) | ||
|
|
||
| cond_x2_gt0 = ov_opset.greater(x2, zero_const).output(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .output(0) call is unnecessary here. The ov_opset.greater op already returns an Output object, so you can remove this to simplify the code.
| cond_x2_gt0 = ov_opset.greater(x2, zero_const).output(0) | |
| cond_x2_gt0 = ov_opset.greater(x2, zero_const) | |
| cond_x2_lt0 = ov_opset.less(x2, zero_const) |
References
- Design end-to-end workflows, not individual functions and classes. Features only exist to support a workflow. (link)
| cond_x2_gt0 = ov_opset.greater(x2, zero_const) | ||
| cond_x2_lt0 = ov_opset.less(x2, zero_const) | ||
|
|
||
| cond_x1_ge0 = ov_opset.greater_equal(x1, zero_const).output(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .output(0) call is unnecessary here. The ov_opset.greater_equal op already returns an Output object, so you can remove this to simplify the code.
| cond_x1_ge0 = ov_opset.greater_equal(x1, zero_const).output(0) | |
| cond_x1_ge0 = ov_opset.greater_equal(x1, zero_const) | |
| cond_x1_gt0 = ov_opset.greater(x1, zero_const) | |
| cond_x1_eq0 = ov_opset.equal(x1, zero_const) |
References
- Design end-to-end workflows, not individual functions and classes. Features only exist to support a workflow. (link)
This PR fixes incorrect NaN propagation in the OpenVINO backend for arctan2.
Fixes #22061