Skip to content

Conversation

@Aryaman9999
Copy link

🛠️ Fix: Handle zero-length sequences correctly in ReverseSequence

Problem

In the ReverseSequence implementation, when sequence_length == 0, the code used a continue statement 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:

if (seq_len == 0) {
  continue;
}

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:

if (seq_len > 0) {
  // reverse first seq_len elements
  for (int64_t j = 0; j < seq_len; j++) {
    // reversed copy…
  }
}

// always copy the tail (even if seq_len == 0)
for (int64_t j = seq_len; j < max_seq_len; j++) {
  // direct copy…
}

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

@Aryaman9999
Copy link
Author

@microsoft-github-policy-service agree

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.

1 participant