youxiudeshouyeren opened a new pull request, #15682:
URL: https://github.com/apache/tvm/pull/15682

   When I specify the ReLU6 activation function in yolov5, This redundancy 
occurs.
   For example:
   
![image](https://github.com/apache/tvm/assets/41790911/add17bfa-2f3c-4553-b8fe-7c140e50d847)
   It generates this IR:
   ```
     %233 = nn.conv2d(%231, meta[relay.Constant][54] /* ty=Tensor[(256, 256, 1, 
1), int8] */, padding=[0, 0, 0, 0], channels=256, kernel_size=[1, 1], 
out_dtype="int32") /* ty=Tensor[(1, 256, 16, 16), int32] */;
     %234 = add(%233, meta[relay.Constant][55] /* ty=Tensor[(256, 1, 1), int32] 
*/) /* ty=Tensor[(1, 256, 16, 16), int32] */;
     %235 = fixed_point_multiply(%234, multiplier=2097356939, shift=-6) /* 
ty=Tensor[(1, 256, 16, 16), int32] */;
     %236 = clip(%235, a_min=-128f, a_max=127f) /* ty=Tensor[(1, 256, 16, 16), 
int32] */;
     %237 = cast(%236, dtype="int8") /* ty=Tensor[(1, 256, 16, 16), int8] */;
     %238 = clip(%237, a_min=0f, a_max=48f) /* ty=Tensor[(1, 256, 16, 16), 
int8] */;
   ```
   
   The redundancy pattern is:
   ```
    Example:
     %1 = clip(%0, a_min=0f, a_max=255f) [type=int32]
     %2 = cast(%1, dtype="uint8") [type=uint8]
     %3 = clip(%2, a_min=20f, a_max=66f) [type=uint8]
   ```
   
   It can be optimized to:
   ```
    %1 = clip(%0, a_min=20f, a_max=66f) [type=uint8]
    %2 = cast(%1, dtype="uint8") [type=uint8]
   ```
   
   This PR is to simplify `clip->cast->clip` to `clip->cast`


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