@@ -669,16 +669,38 @@ 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
- 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' ]
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 )
676
688
else :
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 )
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
+
682
704
layer = network .add_convolution_nd (
683
705
input = input_tensor ,
684
706
num_output_maps = n_output ,
0 commit comments