Fixed LSTM#219
Open
veblush wants to merge 1 commit into
Open
Conversation
Contributor
|
Thank you Esun! Please update date/revisions. That would be the patch version to update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes two critical issues in
arm_lstm_unidirectional_s8ands16that prevent state persistence in streaming models and cause out-of-bounds reads during non-time-major inference. These issues are closely related to in tensorflow/tflite-micro#3564.Problem:
arm_lstm_unidirectional_*unconditionally setshidden_intoNULLand memsetscell_stateto 0. This discards theHiddenStateTensorandCellStateTensorthat TFLM relies on to persist state acrossInvoke()calls for streaming models.time_major=falseblock ofarm_lstm_unidirectional_*, CMSIS-NN attempts to jump between batches by passingbatch_offset=params->time_stepstoarm_nn_lstm_step_*. However,arm_nn_lstm_step_*forwards thisbatch_offsettoarm_nn_vec_mat_mul_result_acc_s8_s16for both thedata_inandhidden_inpointers. Since thehidden_statebuffer is contiguous (stride 1) and not strided likedata_in, passingbatch_offset=params->time_stepscauses out-of-bounds reads on the hidden_in buffer attimestept=0.Solution:
hidden_statepointer tocmsis_nn_lstm_context.hidden_stateashidden_inwhen present, skipping thecell_statewiping if so.batch_sizein thetime_major=falsecase when computing step sizes, which forcesbatch_offset= 1 and avoids the buggy out-of-bounds stride entirely while writing to the final memory buffer sequentially.