Skip to content

Commit fcbb3af

Browse files
committed
禁止在低版本TRT中使用strides>1的conv (PaddlePaddle#32997)
* revert elementwise and disable trt conv if strides > 1 * strides check * remove useless var * comments
1 parent d7d3090 commit fcbb3af

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

paddle/fluid/inference/tensorrt/convert/activation_op.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ class ActivationOpConverter : public OpConverter {
5252
engine_->GetITensor(op_desc.Input("X")[0]);
5353

5454
auto op_pair = ops.find(op_type_);
55-
if (op_pair == ops.end()) {
56-
PADDLE_THROW(platform::errors::Fatal(
57-
"Wrong activation op type, the trt do not support the %s act type.",
58-
op_type_));
59-
}
6055

6156
nvinfer1::IActivationLayer* layer = TRT_ENGINE_ADD_LAYER(
6257
engine_, Activation, *const_cast<nvinfer1::ITensor*>(input_tensor),

paddle/fluid/inference/tensorrt/convert/affine_channel_op.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ class AffineChannelOpConverter : public OpConverter {
5555
auto* bias_t = bias_v->GetMutable<framework::LoDTensor>();
5656
float* bias_ptr = engine_->GetWeightCPUData(bias_name, bias_t, false);
5757

58-
auto data_layout = framework::StringToDataLayout(
59-
BOOST_GET_CONST(std::string, op_desc.GetAttr("data_layout")));
60-
61-
PADDLE_ENFORCE_EQ(
62-
data_layout, framework::DataLayout::kNCHW,
63-
platform::errors::InvalidArgument(
64-
"TensorRT affine channel converter can only convert NCHW format. "
65-
"Other format should be run in fluid mode. Report a bug on github "
66-
"issue if you see this line."));
67-
6858
// tensorrt scalend layer only support spatial dims >= 2,
6959
// so nhwc is not availabe (spatial dims == 0)
7060
const int channel_axis = engine_->with_dynamic_shape();

paddle/fluid/inference/tensorrt/convert/elementwise_op.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ static bool CheckDims(const nvinfer1::Dims& dims_x,
2525
return false;
2626
}
2727
for (int i = 0; i < dims_x.nbDims; i++) {
28-
// conservative judgment
29-
if (dims_x.d[i] == -1 || dims_y.d[i] == -1) {
30-
return false;
31-
}
3228
if (dims_x.d[i] != dims_y.d[i]) {
3329
return false;
3430
}

paddle/fluid/inference/tensorrt/op_teller.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
143143
BOOST_GET_CONST(std::vector<int>, desc.GetAttr("paddings"));
144144

145145
if (paddings.size() > 2) return false;
146+
// strides > 1 is only supported by trt7.0 above
147+
#if !IS_TRT_VERSION_GE(7000)
148+
if (desc.HasAttr("strides")) {
149+
const std::vector<int> strides =
150+
BOOST_GET_CONST(std::vector<int>, desc.GetAttr("strides"));
151+
// there is no issue if strides.size() less than 2
152+
if (strides.size() > 1) {
153+
for (size_t i = 0; i < strides.size(); i++) {
154+
if (strides[i] > 1) return false;
155+
}
156+
}
157+
}
158+
#endif
146159
}
147160

148161
if (op_type == "pool2d") {
@@ -225,6 +238,20 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
225238
<< desc.Output("Output").size() << " output.";
226239
return false;
227240
}
241+
242+
// strides > 1 is only supported by trt7.0 above
243+
#if !IS_TRT_VERSION_GE(7000)
244+
if (desc.HasAttr("strides")) {
245+
const std::vector<int> strides =
246+
BOOST_GET_CONST(std::vector<int>, desc.GetAttr("strides"));
247+
// there is no issue if strides.size() less than 2
248+
if (strides.size() > 1) {
249+
for (size_t i = 0; i < strides.size(); i++) {
250+
if (strides[i] > 1) return false;
251+
}
252+
}
253+
}
254+
#endif
228255
}
229256

230257
if (op_type == "matmul") {

0 commit comments

Comments
 (0)