Skip to content

Fix CPU ReverseSequence returning zeros for zero-length sequences#28759

Merged
xadupre merged 1 commit into
microsoft:mainfrom
tairenpiao:fix-reversesequence-zero-len
Jun 4, 2026
Merged

Fix CPU ReverseSequence returning zeros for zero-length sequences#28759
xadupre merged 1 commit into
microsoft:mainfrom
tairenpiao:fix-reversesequence-zero-len

Conversation

@tairenpiao

Copy link
Copy Markdown
Contributor

Description

ReverseSequenceImpl skips a batch with continue when seq_len == 0, but the output isn't pre-copied from the input, so that column is left as zeros instead of unchanged. Removing the early continue lets the existing [seq_len, max_seq_len) loop copy the whole column through.

Adds ReverseSequenceTest.ZeroSequenceLength.

Motivation and Context

Fixes #28490. Labelled [OpenVINO] but the bug is in the CPU EP.

…crosoft#28490)

Remove the early continue for seq_len == 0; the output isn't pre-copied, so the pass-through loop must run to leave the column unchanged. Add a regression test.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes an incorrect CPU ReverseSequence result when a batch’s sequence_lens[i] == 0, where the output column was previously left uninitialized (observed as zeros) instead of matching the input. The fix removes the early continue so the existing [seq_len, max_seq_len) copy loop runs and preserves the unchanged portion as required by the operator semantics.

Changes:

  • Remove the seq_len == 0 early-continue in the CPU ReverseSequenceImpl so the “copy-through” loop executes for zero-length sequences.
  • Add a regression unit test covering sequence_lens containing a zero (ReverseSequenceTest.ZeroSequenceLength).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
onnxruntime/core/providers/cpu/tensor/reverse_sequence.cc Removes the seq_len == 0 early exit so zero-length batches are copied through instead of leaving output uninitialized.
onnxruntime/test/providers/cpu/tensor/reverse_sequence_test.cc Adds a regression test validating that a zero sequence length leaves the corresponding batch column unchanged.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@xadupre
xadupre merged commit 1686e08 into microsoft:main Jun 4, 2026
85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OpenVINO] ReverseSequence returns zeros for batch with sequence length 0

3 participants