Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
0d9185b9
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0d9185b9
编写于
1月 31, 2023
作者:
W
wenbin
提交者:
GitHub
1月 31, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Unary (#49914)
* disable integer * disable integer * add cast layer
上级
c3cd8502
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
3 deletion
+64
-3
paddle/fluid/inference/tensorrt/convert/unary_op.cc
paddle/fluid/inference/tensorrt/convert/unary_op.cc
+23
-3
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_unary.py
...id/tests/unittests/ir/inference/test_trt_convert_unary.py
+41
-0
未找到文件。
paddle/fluid/inference/tensorrt/convert/unary_op.cc
浏览文件 @
0d9185b9
...
@@ -52,13 +52,33 @@ class UnaryOpConverter : public OpConverter {
...
@@ -52,13 +52,33 @@ class UnaryOpConverter : public OpConverter {
nvinfer1
::
ITensor
*
input_tensor
=
nvinfer1
::
ITensor
*
input_tensor
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
)[
0
]);
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
)[
0
]);
auto
op_pair
=
ops
.
find
(
op_type_
);
auto
op_pair
=
ops
.
find
(
op_type_
);
nvinfer1
::
ILayer
*
layer
;
nvinfer1
::
IUnaryLayer
*
layer
=
nullptr
;
#if !IS_TRT_VERSION_GE(8500)
nvinfer1
::
DataType
org_type
=
input_tensor
->
getType
();
bool
cast
=
org_type
==
nvinfer1
::
DataType
::
kINT8
||
org_type
==
nvinfer1
::
DataType
::
kINT32
;
if
(
cast
)
{
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Identity
,
*
input_tensor
);
if
(
engine_
->
precision
()
==
AnalysisConfig
::
Precision
::
kFloat32
)
{
layer
->
setOutputType
(
0
,
nvinfer1
::
DataType
::
kFLOAT
);
}
else
{
layer
->
setOutputType
(
0
,
nvinfer1
::
DataType
::
kHALF
);
}
input_tensor
=
layer
->
getOutput
(
0
);
}
#endif
for
(
auto
trt_op
:
op_pair
->
second
)
{
for
(
auto
trt_op
:
op_pair
->
second
)
{
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Unary
,
*
input_tensor
,
trt_op
);
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Unary
,
*
input_tensor
,
trt_op
);
input_tensor
=
layer
->
getOutput
(
0
);
input_tensor
=
layer
->
getOutput
(
0
);
}
}
#if !IS_TRT_VERSION_GE(8500)
// type restore
if
(
cast
)
{
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Identity
,
*
input_tensor
);
layer
->
setOutputType
(
0
,
org_type
);
input_tensor
=
layer
->
getOutput
(
0
);
}
#endif
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
RreplenishLayerAndOutput
(
layer
,
op_type_
,
{
output_name
},
test_mode
);
RreplenishLayerAndOutput
(
layer
,
op_type_
,
{
output_name
},
test_mode
);
}
}
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_unary.py
浏览文件 @
0d9185b9
...
@@ -42,6 +42,14 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
...
@@ -42,6 +42,14 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
else
:
else
:
return
np
.
random
.
random
([
batch
,
3
,
32
,
32
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
32
,
32
]).
astype
(
np
.
float32
)
def
generate_int_input
(
dims
,
batch
,
attrs
:
List
[
Dict
[
str
,
Any
]]):
if
dims
==
2
:
return
np
.
random
.
random
([
3
,
32
]).
astype
(
np
.
int32
)
elif
dims
==
3
:
return
np
.
random
.
random
([
3
,
32
,
32
]).
astype
(
np
.
int32
)
else
:
return
np
.
random
.
random
([
batch
,
3
,
32
,
32
]).
astype
(
np
.
int32
)
for
dims
in
[
2
,
3
,
4
]:
for
dims
in
[
2
,
3
,
4
]:
for
batch
in
[
1
,
4
]:
for
batch
in
[
1
,
4
]:
for
op_type
in
[
for
op_type
in
[
...
@@ -96,6 +104,39 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
...
@@ -96,6 +104,39 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
yield
program_config
yield
program_config
for
op_type
in
[
"exp"
,
"abs"
,
]:
self
.
dims
=
dims
self
.
op_type
=
op_type
dics
=
[{}]
ops_config
=
[
{
"op_type"
:
op_type
,
"op_inputs"
:
{
"X"
:
[
"input_data"
]},
"op_outputs"
:
{
"Out"
:
[
"output_data"
]},
"op_attrs"
:
dics
[
0
],
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
ops
=
ops
,
weights
=
{},
inputs
=
{
"input_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_int_input
,
dims
,
batch
,
dics
)
)
},
outputs
=
[
"output_data"
],
)
yield
program_config
def
sample_predictor_configs
(
def
sample_predictor_configs
(
self
,
program_config
self
,
program_config
)
->
(
paddle_infer
.
Config
,
List
[
int
],
float
):
)
->
(
paddle_infer
.
Config
,
List
[
int
],
float
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录