You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/09/27 12:33:11 UTC

[GitHub] [tvm] masahi commented on a change in pull request #9116: [Forntend] add onnx SplitToSequence and SequenceAt op

masahi commented on a change in pull request #9116:
URL: https://github.com/apache/tvm/pull/9116#discussion_r716645516



##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -1506,6 +1506,51 @@ def _impl_v1(cls, inputs, attr, params):
         return output
 
 
+class SplitToSequence(OnnxOpConverter):
+    """Operator converter for SplitToSequence"""
+
+    @classmethod
+    def _impl_v11(cls, inputs, attr, params):
+
+        # TODO: Split operator requires an explicit list,
+        # so SplitToSequence does not support dynamic shapes yet.
+        in_shape = infer_shape(inputs[0])
+        if len(inputs) == 1:
+            indices_or_sections = in_shape[attr["axis"]]
+            attr["split"] = [1 for x in range(indices_or_sections)]
+        else:
+            try:
+                indices_or_sections = infer_value(inputs[1], params).asnumpy().tolist()
+                if isinstance(indices_or_sections, int):
+                    target_dim = in_shape[attr["axis"]]
+                    cnt = (
+                        int(target_dim / indices_or_sections)
+                        if int(target_dim / indices_or_sections) == target_dim / indices_or_sections
+                        else int(target_dim / indices_or_sections) + 1
+                    )
+                    attr["split"] = [indices_or_sections] * cnt
+            except:
+                raise ValueError("Can't find indice or sections.")
+        if isinstance(indices_or_sections, list):
+            attr["split"] = indices_or_sections
+        out = Split._impl_v1(inputs, attr, params)
+        return _expr.Tuple(list(out))
+
+
+class SequenceAt(OnnxOpConverter):
+    """Operator converter for SequenceAt"""
+
+    @classmethod
+    def _impl_v11(cls, inputs, attr, params):
+        assert isinstance(inputs[0], _expr.Tuple)
+        try:
+            # TODO: SequenceAt does not yet support dynamic shapes
+            position = infer_value(inputs[1], params).asnumpy().tolist()
+        except:
+            raise ValueError("Can't find position.")
+        return inputs[0][position]

Review comment:
       See https://github.com/apache/tvm/pull/9113#discussion_r716644828 I don't think this is the right way to support Sequence.




-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org