diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py index 9eaa9ff58cc0d..fcc04c828b1e1 100644 --- a/python/tvm/relay/frontend/onnx.py +++ b/python/tvm/relay/frontend/onnx.py @@ -6168,10 +6168,13 @@ def _impl_v11(cls, inputs, attr, params): else: position = -1 + seq_len = len(input_sequence) + assert -seq_len <= position and position < seq_len, "Position is out of bounds" + if position < 0: - position = len(input_sequence) + position + position = seq_len + position # Convert sequence to a list, insert tensors before erased, and repackage as Tuple. - tensor_list = [input_sequence[i] for i in range(len(input_sequence)) if i != position] + tensor_list = [input_sequence[i] for i in range(seq_len) if i != position] # Create new tuple and return. return _expr.Tuple(tensor_list)