Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
822ea0f9
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
822ea0f9
编写于
1月 03, 2023
作者:
S
Sanbu
提交者:
GitHub
1月 03, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add not_equal trt converter (#49393)
上级
c5137b22
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
100 addition
and
45 deletion
+100
-45
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+1
-0
paddle/fluid/inference/tensorrt/convert/equal_op.cc
paddle/fluid/inference/tensorrt/convert/equal_op.cc
+57
-6
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+3
-1
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_equal.py
...id/tests/unittests/ir/inference/test_trt_convert_equal.py
+39
-38
未找到文件。
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
822ea0f9
...
...
@@ -2396,6 +2396,7 @@ USE_TRT_CONVERTER(cast)
USE_TRT_CONVERTER
(
recover_padding
)
USE_TRT_CONVERTER
(
remove_padding
)
USE_TRT_CONVERTER
(
equal
);
USE_TRT_CONVERTER
(
not_equal
);
USE_TRT_CONVERTER
(
top_k
)
USE_TRT_CONVERTER
(
top_k_v2
)
USE_TRT_CONVERTER
(
range
)
...
...
paddle/fluid/inference/tensorrt/convert/equal_op.cc
浏览文件 @
822ea0f9
...
...
@@ -35,7 +35,6 @@ class EqualOpConverter : public OpConverter {
void
operator
()(
const
framework
::
proto
::
OpDesc
&
op
,
const
framework
::
Scope
&
scope
,
bool
test_mode
)
override
{
#if IS_TRT_VERSION_GE(8000)
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
nvinfer1
::
ILayer
*
layer
=
nullptr
;
...
...
@@ -79,11 +78,62 @@ class EqualOpConverter : public OpConverter {
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
ElementWise
,
*
X
,
*
Y
,
nvinfer1
::
ElementWiseOperation
::
kEQUAL
);
RreplenishLayerAndOutput
(
layer
,
"equal"
,
{
output_name
},
test_mode
);
#else
PADDLE_THROW
(
platform
::
errors
::
Fatal
(
"ElementWise Equal Operation is only supported "
"on TRT 8 or higher version."
));
#endif
}
};
class
NotEqualOpConverter
:
public
OpConverter
{
public:
NotEqualOpConverter
()
{}
void
operator
()(
const
framework
::
proto
::
OpDesc
&
op
,
const
framework
::
Scope
&
scope
,
bool
test_mode
)
override
{
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
nvinfer1
::
ILayer
*
layer
=
nullptr
;
auto
*
X
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
).
front
());
auto
*
Y
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"Y"
).
front
());
nvinfer1
::
Dims
dims_x
=
X
->
getDimensions
();
nvinfer1
::
Dims
dims_y
=
Y
->
getDimensions
();
int
axis
=
PADDLE_GET_CONST
(
int
,
op_desc
.
GetAttr
(
"axis"
));
if
(
axis
<
0
)
{
axis
=
std
::
abs
(
dims_x
.
nbDims
-
dims_y
.
nbDims
);
}
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
nvinfer1
::
IShuffleLayer
*
expand_layer
=
nullptr
;
if
(
dims_x
.
nbDims
>
dims_y
.
nbDims
)
{
nvinfer1
::
Dims
expand_shape
;
expand_shape
.
nbDims
=
dims_x
.
nbDims
;
for
(
int
i
=
0
;
i
<
expand_shape
.
nbDims
;
i
++
)
{
expand_shape
.
d
[
i
]
=
1
;
}
for
(
int
i
=
0
;
i
<
dims_y
.
nbDims
;
i
++
)
{
expand_shape
.
d
[
i
+
axis
]
=
dims_y
.
d
[
i
];
}
expand_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Shuffle
,
*
Y
);
expand_layer
->
setReshapeDimensions
(
expand_shape
);
Y
=
expand_layer
->
getOutput
(
0
);
}
else
if
(
dims_x
.
nbDims
<
dims_y
.
nbDims
)
{
nvinfer1
::
Dims
expand_shape
;
expand_shape
.
nbDims
=
dims_y
.
nbDims
;
for
(
int
i
=
0
;
i
<
expand_shape
.
nbDims
;
i
++
)
{
expand_shape
.
d
[
i
]
=
1
;
}
for
(
int
i
=
0
;
i
<
dims_x
.
nbDims
;
i
++
)
{
expand_shape
.
d
[
i
+
axis
]
=
dims_x
.
d
[
i
];
}
expand_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Shuffle
,
*
X
);
expand_layer
->
setReshapeDimensions
(
expand_shape
);
X
=
expand_layer
->
getOutput
(
0
);
}
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
ElementWise
,
*
X
,
*
Y
,
nvinfer1
::
ElementWiseOperation
::
kEQUAL
);
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Unary
,
*
layer
->
getOutput
(
0
),
nvinfer1
::
UnaryOperation
::
kNOT
);
RreplenishLayerAndOutput
(
layer
,
"not_equal"
,
{
output_name
},
test_mode
);
}
};
...
...
@@ -92,3 +142,4 @@ class EqualOpConverter : public OpConverter {
}
// namespace paddle
REGISTER_TRT_OP_CONVERTER
(
equal
,
EqualOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
not_equal
,
NotEqualOpConverter
);
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
822ea0f9
...
...
@@ -2341,7 +2341,7 @@ struct SimpleOpTypeSetTeller : public Teller {
}
#endif
if
(
op_type
==
"equal"
)
{
if
(
op_type
==
"equal"
||
op_type
==
"not_equal"
)
{
#if !IS_TRT_VERSION_GE(8000)
VLOG
(
3
)
<<
"compare is not supported when TensorRT < 8.0"
;
return
false
;
...
...
@@ -2493,6 +2493,7 @@ struct SimpleOpTypeSetTeller : public Teller {
"elementwise_max"
,
"elementwise_floordiv"
,
"equal"
,
"not_equal"
,
"less_than"
,
"greater_than"
,
"logical_or"
,
...
...
@@ -2639,6 +2640,7 @@ struct SimpleOpTypeSetTeller : public Teller {
"elementwise_max"
,
"elementwise_floordiv"
,
"equal"
,
"not_equal"
,
"less_than"
,
"greater_than"
,
"logical_or"
,
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_equal.py
浏览文件 @
822ea0f9
...
...
@@ -39,45 +39,46 @@ class TrtConvertElementwiseTest_one_input_corner_case(TrtLayerAutoScanTest):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
for
batch
in
[
1
,
2
,
4
]:
for
shape
in
[[
batch
,
1
],
[
batch
,
1
,
32
],
[
batch
,
1
,
16
,
32
]]:
for
axis
in
[
-
1
if
len
(
shape
)
==
1
else
1
]:
self
.
dims
=
len
(
shape
)
dics
=
[{
"axis"
:
axis
},
{
"in_dtype"
:
0
,
"out_dtype"
:
5
}]
ops_config
=
[
{
"op_type"
:
"equal"
,
"op_inputs"
:
{
"X"
:
[
"input_data1"
],
"Y"
:
[
"input_data2"
],
for
op_type
in
[
"equal"
,
"not_equal"
]:
for
batch
in
[
1
,
2
,
4
]:
for
shape
in
[[
batch
,
1
],
[
batch
,
1
,
32
],
[
batch
,
1
,
16
,
32
]]:
for
axis
in
[
-
1
if
len
(
shape
)
==
1
else
1
]:
self
.
dims
=
len
(
shape
)
dics
=
[{
"axis"
:
axis
},
{
"in_dtype"
:
0
,
"out_dtype"
:
5
}]
ops_config
=
[
{
"op_type"
:
op_type
,
"op_inputs"
:
{
"X"
:
[
"input_data1"
],
"Y"
:
[
"input_data2"
],
},
"op_outputs"
:
{
"Out"
:
[
"compare_output_data"
]},
"op_attrs"
:
dics
[
0
],
},
"op_outputs"
:
{
"Out"
:
[
"compare_output_data"
]},
"op_attrs"
:
dics
[
0
],
},
{
"op_type"
:
"cast"
,
"op_inputs"
:
{
"X"
:
[
"compare_output_data"
]},
"op_outputs"
:
{
"Out"
:
[
"output_data"
]},
"op_attrs"
:
dics
[
1
],
},
]
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
ops
=
ops
,
weights
=
{},
inputs
=
{
"input_data1"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
shape
)
),
"input_data2"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
shape
)
),
},
outputs
=
[
"output_data"
],
)
yield
program_config
{
"op_type"
:
"cast"
,
"op_inputs"
:
{
"X"
:
[
"compare_output_data"
]},
"op_outputs"
:
{
"Out"
:
[
"output_data"
]},
"op_attrs"
:
dics
[
1
],
},
]
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
ops
=
ops
,
weights
=
{},
inputs
=
{
"input_data1"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
shape
)
),
"input_data2"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
shape
)
),
},
outputs
=
[
"output_data"
],
)
yield
program_config
def
sample_predictor_configs
(
self
,
program_config
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录