OpenVINO keeps that column unchanged, which matches the expected behavior.
import numpy as np
import onnxruntime as ort
from onnx import TensorProto, helper
node = helper.make_node(
"ReverseSequence",
["x", "lens"],
["y"],
time_axis=0,
batch_axis=1,
)
graph = helper.make_graph(
[node],
"g",
[
helper.make_tensor_value_info("x", TensorProto.FLOAT, [5, 3]),
helper.make_tensor_value_info("lens", TensorProto.INT64, [3]),
],
[helper.make_tensor_value_info("y", TensorProto.FLOAT, [5, 3])],
)
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 18)])
model.ir_version = 9
x = np.array(
[
[10, 20, 30],
[11, 21, 31],
[12, 22, 32],
[13, 23, 33],
[14, 24, 34],
],
dtype=np.float32,
)
lens = np.array([4, 0, 2], dtype=np.int64)
sess = ort.InferenceSession(
model.SerializeToString(),
providers=["CPUExecutionProvider"],
)
y = sess.run(None, {"x": x, "lens": lens})[0]
expected = np.array(
[
[13, 20, 31],
[12, 21, 30],
[11, 22, 32],
[10, 23, 33],
[14, 24, 34],
],
dtype=np.float32,
)
print("x:")
print(x)
print("lens:", lens)
print("expected column for length-0 batch:", expected[:, 1])
print("ORT column for length-0 batch: ", y[:, 1])
print("PASS=", np.array_equal(y, expected))
lens: [4 0 2]
expected column for length-0 batch: [20. 21. 22. 23. 24.]
ORT column for length-0 batch: [20. 21. 22. 23. 24.]
PASS=True
lens: [4 0 2]
expected column for length-0 batch: [20. 21. 22. 23. 24.]
ORT column for length-0 batch: [0. 0. 0. 0. 0.]
PASS=False
Describe the issue
ONNX Runtime
CPUExecutionProviderproduces incorrect output forReverseSequencewhen one sequence length is0.In the reproducer below,
time_axis=0,batch_axis=1, andsequence_lens=[4, 0, 2].For the second batch, the sequence length is
0, so no elements should be reversed and the original column should remain unchanged. However, ORT returns zeros for the entire second batch column.OpenVINO keeps that column unchanged, which matches the expected behavior.
To reproduce
Urgency
Expected output
Actual output
Platform
Linux
OS Version
Linux-6.17.0-20-generic-x86_64-with-glibc2.39
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.25.1
ONNX Runtime API
Python
Architecture
X86
Execution Provider
Default CPU
Execution Provider Library Version
No response