Skip to content

Commit 325bfc3

Browse files
author
Pei Yang
authored
Revert "add trt transpose and flatten converter (#31022) (#31139)" (#31343)
This reverts commit 20e68a2.
1 parent 0a8ebb0 commit 325bfc3

File tree

11 files changed

+55
-258
lines changed

11 files changed

+55
-258
lines changed

paddle/fluid/inference/analysis/ir_pass_manager.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ void IRPassManager::CreatePasses(Argument *argument,
141141
pass->Set("optim_input_shape",
142142
new std::map<std::string, std::vector<int>>(
143143
argument->optim_input_shape()));
144-
bool with_dynamic_shape = argument->max_input_shape().size() > 0 &&
145-
argument->min_input_shape().size() > 0 &&
146-
argument->optim_input_shape().size() > 0;
147-
pass->Set("with_dynamic_shape", new bool(with_dynamic_shape));
148144
pass->Set("trt_disabled_ops", new std::vector<std::string>(
149145
argument->tensorrt_disabled_ops()));
150146
pass->Set("trt_use_dla", new bool(argument->tensorrt_use_dla()));

paddle/fluid/inference/analysis/ir_passes/tensorrt_subgraph_pass.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ void analysis::TensorRtSubgraphPass::ApplyImpl(
4040
auto use_calib_mode = Get<bool>("use_calib_mode");
4141
bool no_calib_int8 = enable_int8 && !(use_calib_mode);
4242
auto trt_disabled_ops = Get<std::vector<std::string>>("trt_disabled_ops");
43-
auto with_dynamic_shape = Get<bool>("with_dynamic_shape");
4443
auto teller = [&](const framework::ir::Node *node) {
4544
if (!node->IsOp() || !node->Op()) return false;
4645
if (find(trt_disabled_ops.begin(), trt_disabled_ops.end(),
@@ -49,8 +48,8 @@ void analysis::TensorRtSubgraphPass::ApplyImpl(
4948
<< " is diabled by config in TensorRT";
5049
return false;
5150
}
52-
return tensorrt::OpTeller::Global().Tell(node, no_calib_int8,
53-
with_dynamic_shape);
51+
return tensorrt::OpTeller::Global().Tell(node->Op()->Type(), *node->Op(),
52+
no_calib_int8);
5453
};
5554

5655
framework::ir::SubGraphFuser fuser(

paddle/fluid/inference/api/analysis_predictor.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,8 +1158,6 @@ USE_TRT_CONVERTER(elementwise_mul_tensor);
11581158
USE_TRT_CONVERTER(elementwise_max_tensor);
11591159
USE_TRT_CONVERTER(elementwise_min_tensor);
11601160
USE_TRT_CONVERTER(elementwise_pow_tensor);
1161-
USE_TRT_CONVERTER(transpose);
1162-
USE_TRT_CONVERTER(flatten);
11631161
USE_TRT_CONVERTER(matmul);
11641162
USE_TRT_CONVERTER(conv2d);
11651163
USE_TRT_CONVERTER(relu);

paddle/fluid/inference/tensorrt/convert/CMakeLists.txt

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,50 @@ nv_library(tensorrt_converter
33
SRCS matmul_op.cc conv2d_op.cc fc_op.cc pool2d_op.cc elementwise_op.cc
44
batch_norm_op.cc activation_op.cc softmax_op.cc concat_op.cc dropout_op.cc group_norm_op.cc
55
pad_op.cc split_op.cc prelu_op.cc leaky_relu_op.cc gelu_op.cc layer_norm_op.cc multihead_matmul_op.cc
6-
shuffle_channel_op.cc swish_op.cc instance_norm_op.cc stack_op.cc transpose_op.cc flatten_op.cc
6+
shuffle_channel_op.cc swish_op.cc instance_norm_op.cc stack_op.cc
77
emb_eltwise_layernorm.cc skip_layernorm.cc scale_op.cc slice_op.cc hard_sigmoid_op.cc hard_swish_op.cc clip_op.cc
88
DEPS tensorrt_engine tensorrt_plugin operator scope framework_proto op_registry)
99

1010
nv_test(test_op_converter SRCS test_op_converter.cc DEPS
1111
paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine tensorrt_converter)
12+
13+
# TODO(xingzhaolong): fix the the following ci ut error.
14+
15+
#nv_test(test_io_converter SRCS test_io_converter.cc io_converter.cc DEPS dynload_cuda dynamic_loader lod_tensor)
16+
#nv_test(test_trt_mul_op SRCS test_mul_op.cc mul_op.cc
17+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine mul_op)
18+
#nv_test(test_trt_fc_op SRCS test_fc_op.cc fc_op.cc
19+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine mul_op)
20+
#nv_test(test_trt_activation_op SRCS test_activation_op.cc activation_op.cc
21+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine activation_op)
22+
#nv_test(test_trt_conv_op SRCS test_conv2d_op.cc conv2d_op.cc
23+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine conv_op conv_transpose_op)
24+
#nv_test(test_trt_pool2d_op SRCS test_pool2d_op.cc pool2d_op.cc
25+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine pool_op tensorrt_plugin)
26+
#nv_test(test_trt_elementwise_op SRCS test_elementwise_op.cc elementwise_op.cc
27+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine tensorrt_plugin
28+
# elementwise_add_op elementwise_mul_op)
29+
#nv_test(test_trt_softmax_op SRCS test_softmax_op.cc softmax_op.cc
30+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine softmax_op)
31+
#nv_test(test_trt_batch_norm_op SRCS test_batch_norm_op.cc batch_norm_op.cc
32+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine batch_norm_op)
33+
#nv_test(test_trt_concat_op SRCS test_concat_op.cc concat_op.cc
34+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine concat_op)
35+
#nv_test(test_trt_dropout_op SRCS test_dropout_op.cc dropout_op.cc
36+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine dropout_op)
37+
#nv_test(test_trt_pad_op SRCS test_pad_op.cc pad_op.cc
38+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine pad_op)
39+
#nv_test(test_trt_split_op SRCS test_split_op.cc split_op.cc
40+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine tensorrt_plugin
41+
# split_op concat_op)
42+
#nv_test(test_trt_prelu_op SRCS test_prelu_op.cc prelu_op.cc
43+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine tensorrt_plugin
44+
# prelu_op)
45+
#nv_test(test_trt_leaky_relu_op SRCS test_leaky_relu_op.cc leaky_relu_op.cc
46+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine activation_op)
47+
48+
#nv_test(test_shuffle_channel_op SRCS test_shuffle_channel_op.cc shuffle_channel_op.cc
49+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine shuffle_channel_op)
50+
51+
#nv_test(test_swish_op SRCS test_swish_op.cc swish_op.cc
52+
# DEPS paddle_framework ${GLOB_OPERATOR_DEPS} tensorrt_engine activation_op tensorrt_plugin)

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

Lines changed: 0 additions & 62 deletions
This file was deleted.

paddle/fluid/inference/tensorrt/convert/op_converter.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,7 @@ class OpConverter {
109109
it, platform::errors::Unimplemented("no OpConverter for optype [%s]",
110110
op_desc.Type()));
111111
}
112-
if (op_desc.Type() == "transpose2") {
113-
it = Registry<OpConverter>::Global().Lookup("transpose");
114-
PADDLE_ENFORCE_NOT_NULL(
115-
it, platform::errors::Unimplemented("no OpConverter for optype [%s]",
116-
op_desc.Type()));
117-
}
118-
if (op_desc.Type() == "flatten2") {
119-
it = Registry<OpConverter>::Global().Lookup("flatten");
120-
PADDLE_ENFORCE_NOT_NULL(
121-
it, platform::errors::Unimplemented("no OpConverter for optype [%s]",
122-
op_desc.Type()));
123-
}
112+
124113
if (!it) {
125114
it = Registry<OpConverter>::Global().Lookup(op_desc.Type());
126115
}

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

Lines changed: 0 additions & 84 deletions
This file was deleted.

paddle/fluid/inference/tensorrt/op_teller.cc

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,11 @@ struct SimpleOpTypeSetTeller : public Teller {
106106
"layer_norm",
107107
"scale",
108108
"stack",
109-
"transpose2",
110-
"transpose",
111-
"flatten2",
112-
"flatten",
113109
};
114110
};
115111

116-
bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
117-
bool with_dynamic_shape) {
118-
const std::string op_type = node->Op()->Type();
119-
const framework::OpDesc desc = *node->Op();
112+
bool OpTeller::Tell(const std::string& op_type, const framework::OpDesc& desc,
113+
bool use_no_calib_int8) {
120114
// do not support the op which is labeled the `skip_quant`
121115
if ((desc.HasAttr("namescope") &&
122116
BOOST_GET_CONST(std::string, desc.GetAttr("op_namescope")) ==
@@ -168,26 +162,6 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
168162
if (axis <= 0) return false;
169163
}
170164
}
171-
if (op_type == "transpose2" || op_type == "transpose") {
172-
if (!desc.HasAttr("axis")) {
173-
return false;
174-
} else {
175-
std::vector<int> axis =
176-
BOOST_GET_CONST(std::vector<int>, desc.GetAttr("axis"));
177-
if (!with_dynamic_shape && axis[0] != 0) return false;
178-
if (axis.size() >= nvinfer1::Dims::MAX_DIMS) return false;
179-
}
180-
}
181-
if (op_type == "flatten2" || op_type == "flatten") {
182-
// flatten doesn't support dynamic shape currently
183-
if (!desc.HasAttr("axis")) {
184-
return false;
185-
} else {
186-
if (with_dynamic_shape) return false;
187-
int axis = BOOST_GET_CONST(int, desc.GetAttr("axis"));
188-
if (axis != 1) return false;
189-
}
190-
}
191165
if ((*teller)(op_type, desc, use_no_calib_int8)) return true;
192166
}
193167
return false;

paddle/fluid/inference/tensorrt/op_teller.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <string>
1818
#include <unordered_set>
1919
#include <vector>
20-
#include "paddle/fluid/framework/ir/node.h"
20+
2121
#include "paddle/fluid/framework/op_desc.h"
2222
#include "paddle/fluid/inference/tensorrt/engine.h"
2323

@@ -65,8 +65,8 @@ class OpTeller {
6565
return *x;
6666
}
6767

68-
bool Tell(const framework::ir::Node* node, bool use_no_calib_int8 = false,
69-
bool with_dynamic_shape = false);
68+
bool Tell(const std::string& op_type, const framework::OpDesc& desc,
69+
bool use_no_calib_int8 = false);
7070

7171
private:
7272
OpTeller();

python/paddle/fluid/tests/unittests/ir/inference/test_trt_subgraph_pass.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -287,59 +287,6 @@ def test_check_output(self):
287287
PassVersionChecker.IsCompatible('tensorrt_subgraph_pass'))
288288

289289

290-
class TensorRTSubgraphPassTransposeTest(InferencePassTest):
291-
def setUp(self):
292-
with fluid.program_guard(self.main_program, self.startup_program):
293-
data = fluid.data(
294-
name="data", shape=[-1, 6, 64, 64], dtype="float32")
295-
transpose_out = self.append_transpose(data)
296-
out = fluid.layers.batch_norm(transpose_out, is_test=True)
297-
self.feeds = {
298-
"data": np.random.random([1, 6, 64, 64]).astype("float32"),
299-
}
300-
self.enable_trt = True
301-
self.trt_parameters = TensorRTSubgraphPassTransposeTest.TensorRTParam(
302-
1 << 30, 32, 0, AnalysisConfig.Precision.Float32, False, False)
303-
self.fetch_list = [out]
304-
305-
def append_transpose(self, data):
306-
return fluid.layers.transpose(data, [0, 3, 1, 2])
307-
308-
def test_check_output(self):
309-
if core.is_compiled_with_cuda():
310-
use_gpu = True
311-
self.check_output_with_option(use_gpu)
312-
self.assertTrue(
313-
PassVersionChecker.IsCompatible('tensorrt_subgraph_pass'))
314-
315-
316-
class TensorRTSubgraphPassFlattenTest(InferencePassTest):
317-
def setUp(self):
318-
with fluid.program_guard(self.main_program, self.startup_program):
319-
data = fluid.data(
320-
name="data", shape=[-1, 6, 64, 64], dtype="float32")
321-
flatten_out = self.append_flatten(data)
322-
reshape_out = fluid.layers.reshape(flatten_out, [-1, 0, 1, 1])
323-
out = fluid.layers.batch_norm(reshape_out, is_test=True)
324-
self.feeds = {
325-
"data": np.random.random([1, 6, 64, 64]).astype("float32"),
326-
}
327-
self.enable_trt = True
328-
self.trt_parameters = TensorRTSubgraphPassFlattenTest.TensorRTParam(
329-
1 << 30, 32, 0, AnalysisConfig.Precision.Float32, False, False)
330-
self.fetch_list = [out]
331-
332-
def append_flatten(self, data):
333-
return fluid.layers.flatten(data, axis=1)
334-
335-
def test_check_output(self):
336-
if core.is_compiled_with_cuda():
337-
use_gpu = True
338-
self.check_output_with_option(use_gpu)
339-
self.assertTrue(
340-
PassVersionChecker.IsCompatible('tensorrt_subgraph_pass'))
341-
342-
343290
class TensorRTSubgraphPassLayerNormTest(InferencePassTest):
344291
def setUp(self):
345292
self.set_params()

0 commit comments

Comments
 (0)