@@ -669,38 +669,16 @@ def convert_conv2d(network, paddle_op, inputs):
669
669
if paddle_op .name () == "pd_op.fused_conv2d_add_act" :
670
670
constant_manager = TensorRTConstantManager ()
671
671
bias_source_op = paddle_op .operands ()[2 ].source ().get_defining_op ()
672
-
673
- def get_bias_weights (current_op ):
674
- if current_op .name () == "builtin.parameter" :
675
- bias_name = current_op .attrs ()["parameter_name" ]
676
- elif current_op .name () == "builtin.constant" :
677
- bias_name = current_op .attrs ()["value" ]
678
- else :
679
- raise ValueError (
680
- f"Unsupported bias source operation: { current_op .name ()} "
681
- )
682
-
683
- bias_np = constant_manager .get_constant_value (bias_name )
684
- return trt .Weights (bias_np )
685
-
686
- if bias_source_op .name () in ["builtin.parameter" , "builtin.constant" ]:
687
- bias_weights = get_bias_weights (bias_source_op )
672
+ if bias_source_op .name () == "builtin.parameter" :
673
+ bias_name = bias_source_op .attrs ()['parameter_name' ]
674
+ elif bias_source_op .name () == "builtin.constant" :
675
+ bias_np = bias_source_op .attrs ()['value' ]
688
676
else :
689
- while bias_source_op .name () == "pd_op.reshape" :
690
- bias_source_op = (
691
- bias_source_op .operands ()[0 ].source ().get_defining_op ()
692
- )
693
- if bias_source_op .name () in [
694
- "builtin.parameter" ,
695
- "builtin.constant" ,
696
- ]:
697
- bias_weights = get_bias_weights (bias_source_op )
698
- break
699
- else :
700
- raise ValueError (
701
- f"Unsupported bias source operation: { bias_source_op .name ()} "
702
- )
703
-
677
+ raise ValueError (
678
+ f"Unsupported bias source op: { bias_source_op .name ()} "
679
+ )
680
+ bias_np = constant_manager .get_constant_value (bias_name )
681
+ bias_weights = trt .Weights (bias_np )
704
682
layer = network .add_convolution_nd (
705
683
input = input_tensor ,
706
684
num_output_maps = n_output ,
@@ -897,27 +875,32 @@ def add_cast_reduce_layer(network, paddle_op, inputs, op_type):
897
875
898
876
axis = paddle_op .attrs ().get ("axis" )
899
877
input_shape = paddle_op .operands ()[0 ].source ().shape
900
- keepdim = paddle_op .attrs ()["keepdim" ]
901
- if network .has_implicit_batch_dimension :
902
- assert (
903
- axis != 0
904
- ), "can't reduce on axis == 0 when network has implicit batch dimension"
905
- output_shape = []
878
+ input_dims = len (input_shape )
879
+ keepdim = paddle_op .attrs ().get ("keepdim" )
880
+
906
881
if len (axis ) == 0 :
907
- axis = list (range (len (input_shape )))
908
- for i in range (len (axis )):
909
- if axis [i ] < 0 :
910
- axis [i ] = len (input_shape ) + axis [i ]
911
- layer = network .add_reduce (
882
+ axes = 0
883
+ for i in range (input_dims ):
884
+ axes |= 1 << i
885
+ else :
886
+ for i in range (len (axis )):
887
+ if axis [i ] < 0 :
888
+ axis [i ] += input_dims
889
+
890
+ axes = get_axes_for_reduce_op (axis )
891
+
892
+ reduce_layer = network .add_reduce (
912
893
cast_layer .get_output (0 ),
913
894
op_type ,
914
- axes = get_axes_for_reduce_op ( axis ) ,
895
+ axes = axes ,
915
896
keep_dims = keepdim ,
916
897
)
917
- set_layer_name (layer , paddle_op )
918
- layer .set_output_type (0 , trt .bool )
919
- layer .get_output (0 ).dtype = cast_layer .get_output (0 ).dtype
920
- return layer .get_output (0 )
898
+ set_layer_name (reduce_layer , paddle_op )
899
+ bool_layer = network .add_identity (reduce_layer .get_output (0 ))
900
+ set_layer_name (bool_layer , paddle_op )
901
+ bool_layer .set_output_type (0 , trt .bool )
902
+ bool_layer .get_output (0 ).dtype = trt .bool
903
+ return bool_layer .get_output (0 )
921
904
922
905
923
906
def fix_negative_indices (network , input_shape , indices , name = None ):
0 commit comments