lhutton1 commented on a change in pull request #9627:
URL: https://github.com/apache/tvm/pull/9627#discussion_r761119882



##########
File path: tests/python/contrib/test_ethosu/test_codegen.py
##########
@@ -1038,5 +1038,70 @@ def representative_dataset():
     infra.verify_source(compiled_models, accel_type)
 
 
[email protected]("accel_type", ACCEL_TYPES)
[email protected]("ifm_shape", [[1, 115, 32, 7], [1, 4, 5, 2]])
+def test_tflite_sigmoid(accel_type, ifm_shape):
+    dtype = "int8"
+
+    def create_tflite_graph():
+        tf.config.run_functions_eagerly(True)
+
+        class Model(tf.Module):
+            @tf.function
+            def tanh_function(self, x):

Review comment:
       ```suggestion
               def sigmoid_function(self, x):
   ```

##########
File path: python/tvm/relay/op/contrib/ethosu.py
##########
@@ -944,6 +944,35 @@ def tanh_pattern():
     return quant
 
 
+class SigmoidParams:
+    """
+    This class will parse a call to a ethos-u.sigmoid composite function
+    and extract the parameter information.
+    """
+
+    composite_name = "ethos-u.sigmoid"
+
+    def __init__(self, func_body: Call):
+        self.ofm = TensorParams(func_body)
+        self.ifm = TensorParams(func_body.args[0].args[0].args[0])
+
+    def is_valid(self):
+        """
+        This function checks whether reshape has compatible attributes with 
the NPU

Review comment:
       ```suggestion
           This function checks whether sigmoid has compatible attributes with 
the NPU
   ```

##########
File path: python/tvm/relay/backend/contrib/ethosu/legalize.py
##########
@@ -194,6 +194,76 @@ def __call__(self, *args, **kwargs):
         pass
 
 
+def sigmoid_calc_func(x):
+    """Function to calculate the values for sigmoid"""
+    # Thse limits are inherited from TFLite
+    upper_limit = 8.0
+    lower_limit = -8.0
+
+    if x <= lower_limit:
+        y = 0.0
+    elif x >= upper_limit:
+        y = 1.0
+    else:
+        y = 1 / (1 + math.exp(-x))
+    return y
+
+
+class SigmoidRewriter(DFPatternCallback):

Review comment:
       This looks very similar to `TanhRewriter`, is it worth creating a 
subclass?




-- 
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