@@ -1675,7 +1675,7 @@ def _convert_gelu(self, node):
16751675 name = node .name ,
16761676 input_name = input_names [0 ],
16771677 output_name = node .name ,
1678- mode = 'EXACT ' )
1678+ mode = 'TANH_APPROXIMATION ' )
16791679
16801680 output_shape = self ._get_tensor_shape_from_type (node .datatype )
16811681 shapes .propagate_single_layer (layer , self .tensor_shapes ,
@@ -1786,58 +1786,6 @@ def _convert_resize_nearest_neighbor(self, node):
17861786 output_shapes = [output_shape ])
17871787
17881788
1789- def _convert_layer_normalization (self , node ):
1790- assert len (node .inputs ) == 1
1791- input_nodes , input_names , input_types = self ._get_input_tensors (node )
1792- input_name = input_names [0 ]
1793- builder = self ._get_builder ()
1794- gamma = node .attr ['gamma' ]
1795- beta = node .attr ['beta' ]
1796- axes = node .attr ['axes' ]
1797- epsilon = node .attr ['epsilon' ]
1798- input_shape = list (input_types [0 ].get_shape ())
1799-
1800- if (len (input_shape ) in [2 ,3 ] and len (axes ) == 1 and \
1801- axes [0 ] == len (input_shape ) - 1 ):
1802- # Performance enhancement for some models with layer-norm
1803- builder .add_reshape_static (name = input_name + '_reshape' ,
1804- input_name = input_name ,
1805- output_name = input_name + '_reshape' ,
1806- output_shape = input_shape + [1 ,1 ])
1807-
1808- builder .add_mvn (name = input_name + '_mvn' ,
1809- input_name = input_name + '_reshape' ,
1810- output_name = input_name + '_mvn' , across_channels = True ,
1811- normalize_variance = True , epsilon = epsilon )
1812-
1813- builder .add_scale (name = node .name + '_5d' ,
1814- input_name = input_name + '_mvn' ,
1815- output_name = node .name + '_5d' , W = gamma , b = beta , has_bias = True ,
1816- shape_scale = [len (gamma )], shape_bias = [len (beta )])
1817-
1818- builder .add_reshape_static (name = node .name ,
1819- input_name = node .name + '_5d' ,
1820- output_name = node .name ,
1821- output_shape = input_shape )
1822-
1823- else :
1824- # General implementation
1825- input_shape = input_types [0 ].get_shape ()
1826- rdims = len (axes )
1827- normalized_shape = node .datatype .get_shape ()[- rdims :]
1828- if gamma .shape != normalized_shape :
1829- gamma = np .zeros (normalized_shape ) + gamma
1830- if beta .shape != normalized_shape :
1831- beta = np .zeros (normalized_shape ) + beta
1832-
1833- builder .add_layer_normalization (node .name , input_name , node .name ,
1834- normalized_shape , gamma , beta , eps = 1e-5 )
1835-
1836- self .tensor_shapes [node .name ] = self ._get_tensor_shape_from_type (
1837- node .datatype )
1838-
1839-
1840-
18411789 def _convert_layer_normalization (self , node ):
18421790 assert len (node .inputs ) == 1
18431791 input_nodes , input_names , input_types = self ._get_input_tensors (node )
0 commit comments