Fix ReverseSequence handling when sequence_length == 0 #24320
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.
🛠️ Fix: Handle zero-length sequences correctly in
ReverseSequenceProblem
In the
ReverseSequenceimplementation, whensequence_length == 0, the code used acontinuestatement which caused both the reversal and the tail copy loop to be skipped. This left the output buffer uninitialized or filled with default values, which is incorrect.Root Cause
The original logic:
This skips the reversal and the straight-through copy for that batch index, resulting in incomplete output.
Fix
Remove the continue and instead guard only the reversal block. Updated logic:
Behavior After Fix
If seq_len > 0: reverses prefix and copies the rest.
If seq_len == 0: skips reversal but copies the entire row as-is.
This change ensures the operator acts as a no-op when sequence_length == 0, preserving expected behavior and output consistency.
✅ Additional Notes
Verified against test cases with sequence_length == 0
Ensures correctness for edge cases
Fix is safe, minimal, and isolated