Alexey-Yazev commented on code in PR #13772:
URL: https://github.com/apache/tvm/pull/13772#discussion_r1071955879


##########
tests/python/contrib/test_ethosu/test_legalize.py:
##########
@@ -951,20 +962,30 @@ def verify(ext_func):
         assert op.checked_type.dtype == dtype
         assert op.attrs.operator_type == operator_type
         assert op.attrs.reversed_operands == reversed_operands
-        if activation_function == "RELU":
+        if activation_function != None:
             assert str(op.attrs.activation) == "CLIP"
 
             if operator_type in ["MIN", "MAX"]:
-                # MIN and MAX with an activation must have a requantize 
operation
-                # baked into the output. To check the extra requantize node was
-                # picked up by the pattern, we can make sure the quantization
-                # information is not default.
-                assert float(op.attrs.ifm_scale) != 1.0
-                assert int(op.attrs.ifm_zero_point) != 0
-                assert float(op.attrs.ifm2_scale) != 1.0
-                assert int(op.attrs.ifm2_zero_point) != 0
-                assert float(op.attrs.ofm_scale) != 1.0
-                assert int(op.attrs.ofm_zero_point) != 0
+                if has_separate_requantize:
+                    # In case when requantize cannot be fused with MIN/MAX + 
CLIP due to hardware constraints
+                    # there should be default quantization values since 
requantize is separate operation.
+                    assert float(op.attrs.ifm_scale) == 1.0
+                    assert int(op.attrs.ifm_zero_point) == 0
+                    assert float(op.attrs.ifm2_scale) == 1.0
+                    assert int(op.attrs.ifm2_zero_point) == 0
+                    assert float(op.attrs.ofm_scale) == 1.0
+                    assert int(op.attrs.ofm_zero_point) == 0
+                else:
+                    # MIN and MAX with an activation must have a requantize 
operation
+                    # baked into the output. To check the extra requantize 
node was
+                    # picked up by the pattern, we can make sure the 
quantization
+                    # information is not default.
+                    assert float(op.attrs.ifm_scale) != 1.0
+                    assert int(op.attrs.ifm_zero_point) != 0
+                    assert float(op.attrs.ifm2_scale) != 1.0
+                    assert int(op.attrs.ifm2_zero_point) != 0
+                    assert float(op.attrs.ofm_scale) != 1.0
+                    assert int(op.attrs.ofm_zero_point) != 0

Review Comment:
   Yes, both of these blocks get run, the first block is run for cases with MAX 
operation and relu_n1_to_1 activation for example 
test_tflite_binary_elemwise_legalize[relu_n1_to_1-ifm_shape0-ifm2_shape0-False-MAX]
 
   ```
   fn (%tvmgen_default_ethos_u_main_0_ifms: Tensor[(48), int8] /* 
ty=Tensor[(48), int8] */, Inline=1, Compiler="ethos-u", 
global_symbol="tvmgen_default_ethos_u_main_0", Primitive=1) -> Tensor[(1, 2, 3, 
4), int8] {
     %0 = split(%tvmgen_default_ethos_u_main_0_ifms, indices_or_sections=[24]) 
/* ty=(Tensor[(24), int8], Tensor[(24), int8]) */;
     %1 = %0.0 /* ty=Tensor[(24), int8] */;
     %2 = %0.1 /* ty=Tensor[(24), int8] */;
     %3 = reshape(%1, newshape=[1, 2, 3, 4]) /* ty=Tensor[(1, 2, 3, 4), int8] 
*/;
     %4 = reshape(%2, newshape=[1, 2, 3, 4]) /* ty=Tensor[(1, 2, 3, 4), int8] 
*/;
     %5 = contrib.ethosu.binary_elementwise(%3, %4, meta[relay.Constant][0] /* 
ty=Tensor[(0), int8] */, operator_type="MAX", ifm_scale=1f, ifm_zero_point=0, 
ifm2_scale=1f, ifm2_zero_point=0, ofm_scale=1f, ofm_zero_point=0, 
ifm_channels=4, ifm2_channels=4, activation="CLIP", clip_min=-128, 
ofm_dtype="int8") /* ty=Tensor[(1, 2, 3, 4), int8] */;
     contrib.ethosu.identity(%5, meta[relay.Constant][1] /* ty=Tensor[(0), 
int8] */, ifm_scale=0.00783747f, ifm_zero_point=-128, ofm_scale=0.00392157f, 
ofm_zero_point=-128) /* ty=Tensor[(1, 2, 3, 4), int8] */
   } /* ty=fn (Tensor[(48), int8]) -> Tensor[(1, 2, 3, 4), int8] */
   ```
   in this cases the scales are different in others the same.



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