[OpenVINO] Implements LSTM and GRU, fixes RNN shape bug#22436
[OpenVINO] Implements LSTM and GRU, fixes RNN shape bug#22436goyaladitya05 wants to merge 7 commits intokeras-team:masterfrom
Conversation
Summary of ChangesHello, 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 significantly enhances the OpenVINO backend by providing native implementations for LSTM and GRU recurrent neural network layers, moving away from a generic fallback. Concurrently, it resolves a critical shape-related bug within the existing RNN backend, ensuring the stability and correctness of all RNN-based operations. These changes improve performance and reliability for recurrent models on the OpenVINO platform. 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. Changelog
Activity
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
|
There was a problem hiding this comment.
Code Review
This pull request introduces OpenVINO backend implementations for lstm and gru, which is a significant feature addition. It also includes a crucial fix for a shape-related bug in the generic rnn implementation. My review has identified a critical issue in the new lstm implementation concerning bias handling that requires attention. Additionally, I've provided a few suggestions to enhance code quality and enable masking support, which appears to be mostly implemented but is currently disabled.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #22436 +/- ##
==========================================
- Coverage 84.93% 83.24% -1.70%
==========================================
Files 596 596
Lines 66936 67019 +83
Branches 10449 10451 +2
==========================================
- Hits 56855 55790 -1065
- Misses 7292 8549 +1257
+ Partials 2789 2680 -109
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:
|
| SpectralNormalizationTest::test_apply_layer | ||
| StackedRNNTest::test_correctness_single_state_stack | ||
| StackedRNNTest::test_correctness_two_states_stack | ||
| StackedRNNTest::test_return_state_stacked_lstm_cell |
There was a problem hiding this comment.
StackedRNNTest::test_return_state_stacked_lstm_cell can be enabled once qr op is implemented in linalg.py. It won't pass right now.
This PR implements
lstm()andgru()for the OpenVINO backend usingov_opset.lstm_sequenceandgru_sequence, replacing thebackend.rnn()fallback for the common case.This PR also fixes a pre-existing shape bug in
backend.rnn()that caused all RNN-based layers (LSTM, GRU, SimpleRNN, StackedRNN) to fail or produce wrong results withimplementation=2(the default).Fix: Declared body params as
[1, batch, features], squeeze axis 0 before callingstep_function, and unsqueeze the step output back to[1, batch, units]beforeget_concatenated_slices.LSTMandGRUimplementationUses
ov_opset.lstm_sequence,gru_sequencewhen all of the following hold:reset_after=TrueWeight layout differences handled:
[i, f, c, o]vs OV[f, i, c, o](reordered via split/concat)[z, r, h]in both; bias[2, 3*units]vs OV[1, 4*units]=[b_z+rb_z, b_r+rb_r, b_h, rb_h]forlinear_before_reset=TrueRemoved
numpy_scanfrom rnn.py. It was implemented to throwNotImplementedError, and was not present at all for other backends (Tensorflow, Torch, JAX).Removed
unstackfrom rnn.py. Tensorflow and Torch have it being implemented in core.py, and not in rnn.py.Tests
Enabled 30 tests releted to RNN,LSTM and GRU from
excluded_concrete_tests.txtCloses: #22435, Closes: openvinotoolkit/openvino/issues/34403, Closes: openvinotoolkit/openvino/issues/34408
Note
After this PR, rnn.py is at parity with other backends.
RNN,LSTM,GRU, andcudnn_okare all implemented.