jwfromm commented on a change in pull request #4825: [Frontend][ONNX] LSTM 
Support
URL: https://github.com/apache/incubator-tvm/pull/4825#discussion_r376092067
 
 

 ##########
 File path: python/tvm/relay/frontend/onnx.py
 ##########
 @@ -1190,6 +1250,145 @@ def expand_shape(in_shape, shape):
         return _op.broadcast_to(inputs[0], shape=tuple(shape))
 
 
+class LSTM(OnnxOpConverter):
+    """ Operator converter for LSTM.
+    """
+
+    @classmethod
+    def _activation_helper(cls, activation, alpha, beta):
+        convert_map = _get_convert_map(1)
+        attrs = {}
+        if alpha is not None:
+            attrs['alpha'] = alpha
+        if beta is not None:
+            attrs['beta'] = beta
+        return lambda x: convert_map[activation.decode("utf-8")]([x], attrs, 
{})
+
+    @classmethod
+    def _activation_needs_alpha(cls, activation):
+        needs_alpha = [
+            "Affine",
+            "LeakyRelu",
+            "ThresholdedRelu",
+            "ScaledTanh",
+            "HardSigmoid",
+            "Elu",
+        ]
+        return activation.decode("utf-8") in needs_alpha
+
+    @classmethod
+    def _activation_needs_beta(cls, activation):
+        needs_beta = [
+            "Affine",
+            "ScaledTanh",
+            "HardSigmoid",
+        ]
+        return activation.decode("utf-8") in needs_beta
+
+    @classmethod
+    def _impl_v7(cls, inputs, attr, params):
+        # Unpack inputs, note that if optional and not provided then value 
will be None.
+        X = inputs[0]
+        W = inputs[1]
 
 Review comment:
   I think in almost all cases it'd be safe to assume weights are constant. 
However, the fold constant pass in relay will eliminate all operations on the 
weights anyway. Since treating the weights as a non-constant is slightly more 
flexible I prefer it.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to