Not fuse SkipLayerNorm when add has initializer input (#5123)

This commit is contained in:
Ye Wang 2020-09-11 11:46:31 -07:00 committed by GitHub
parent cd56ab197c
commit 89509f256a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,17 @@ class FusionSkipLayerNormalization(Fusion):
def fuse(self, node, input_name_to_nodes, output_name_to_node):
add = self.model.get_parent(node, 0, output_name_to_node)
# In some models there is input_ids->gather->add->LayerNorm and one of input of the
# add node is initializer with fixed shape which should not be fused into SkipLayerNorm
for add_input in add.input:
if self.model.get_initializer(add_input) != None:
return
# The number of input node of add should be 2
if len(self.model.get_parents(add)) != 2:
return
if add is not None and add.op_type == 'Add' and self.model.is_safe_to_fuse_nodes(
[add, node], node.output, input_name_to_nodes, output_name_to_node):
self.nodes_to_remove.extend([add, node])