Update SkipLayerNorm fusion rules (#13350)

### Description
<!-- Describe your changes. -->

The subgraph below meet the SkipLayerNorm fusion pattern, but the fusion
rules also required every input dimension has a certain value. So the
subgraph below cannot fused to SkipLayerNorm.

subgraph we want to fuse

![image](https://user-images.githubusercontent.com/94887879/196386821-3e678a4c-83e4-4bca-8900-5ef4ea996868.png)

     
fusion pattern 3
 [Sub1]   [Sub2]
         \       /
          \     /
           \   /
            Add1
             |
     LayerNormalization

This change allow inputs of FirstAdd operator has dimension which only
has dim_param.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

Co-authored-by: peixuanzuo <peixuanzuo@linmif39a000004.zvflicr54joexhdgnhvmxrxygg.phxx.internal.cloudapp.net>
This commit is contained in:
PeixuanZuo 2022-10-26 16:15:27 +08:00 committed by GitHub
parent ac48bdec89
commit a0cc289be6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,8 +48,13 @@ static bool CheckFirstAdd(Node& add, ProviderType providertype) {
if (!utils::HasDimValue(add_input1_shape->dim(i)) ||
!utils::HasDimValue(add_input2_shape->dim(i)) ||
add_input1_shape->dim(i).dim_value() != add_input2_shape->dim(i).dim_value()) {
is_valid_input = false;
break;
// Allow dimension only has dim_param.
if (!utils::HasDimParam(add_input1_shape->dim(i)) ||
!utils::HasDimParam(add_input2_shape->dim(i)) ||
add_input1_shape->dim(i).dim_param() != add_input2_shape->dim(i).dim_param()) {
is_valid_input = false;
break;
}
}
}
return is_valid_input;