KJlaccHoeUM9l commented on code in PR #13865:
URL: https://github.com/apache/tvm/pull/13865#discussion_r1090424116


##########
python/tvm/relay/frontend/onnx.py:
##########
@@ -6148,13 +6148,35 @@ def _impl_v11(cls, inputs, attr, params):
         return _expr.Tuple(inputs)
 
 
-class SequenceLength(OnnxOpConverter):
-    """Operator converter for sequence length op."""
+class SequenceErase(OnnxOpConverter):
+    """Operator converter for sequence erase op."""
 
     @classmethod
     def _impl_v11(cls, inputs, attr, params):
-        # Get length of input sequence
-        return _expr.const(len(inputs[0]), dtype="int64")
+        # Erase tensor from sequence on specified position
+        input_sequence = inputs[0]
+
+        if len(inputs) == 2:
+            position = inputs[1]
+            # Non constant position is not supported.
+            if isinstance(position, _expr.Constant):
+                position = position.data.numpy()
+            elif position.name_hint in params:
+                position = params[position.name_hint].numpy()
+            else:
+                raise NotImplementedError("Position must be a constant.")
+        else:
+            position = -1
+
+        if position < 0:
+            position = len(input_sequence) + position + 1
+        # Convert sequence to a list, insert tensors before erased, and 
repackage as Tuple.
+        tensor_list = [input_sequence[i] for i in range(position)]

Review Comment:
   Looks like it could be simplified like this:
   ```Python
   tensor_list = [input_sequence[i] for i in range(len(input_sequence)) if i != 
position]
   ```
   This `if` will not affect performance in any way, because everything will be 
done at compile time. However, this code looks more readable.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to