Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
a9f3719b
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看板
未验证
提交
a9f3719b
编写于
8月 03, 2022
作者:
Z
zhoutianzi666
提交者:
GitHub
8月 03, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove stack plugin (#44756)
上级
8e9eea7f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
32 deletion
+40
-32
paddle/fluid/inference/tensorrt/convert/stack_op.cc
paddle/fluid/inference/tensorrt/convert/stack_op.cc
+28
-20
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_stack.py
...id/tests/unittests/ir/inference/test_trt_convert_stack.py
+12
-12
未找到文件。
paddle/fluid/inference/tensorrt/convert/stack_op.cc
浏览文件 @
a9f3719b
...
@@ -41,11 +41,10 @@ class StackOpConverter : public OpConverter {
...
@@ -41,11 +41,10 @@ class StackOpConverter : public OpConverter {
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
auto
input
=
op_desc
.
Input
(
"X"
);
auto
input
=
op_desc
.
Input
(
"X"
);
int
input_num
=
input
.
size
();
int
input_num
=
input
.
size
();
nvinfer1
::
ITensor
**
inputs
=
std
::
vector
<
nvinfer1
::
ITensor
*>
inputs
;
(
nvinfer1
::
ITensor
**
)
malloc
(
input_num
*
sizeof
(
nvinfer1
::
ITensor
*
));
for
(
int
i
=
0
;
i
<
input_num
;
++
i
)
{
for
(
int
i
=
0
;
i
<
input_num
;
++
i
)
{
inputs
[
i
]
=
engine_
->
GetITensor
(
input
[
i
]
);
inputs
.
push_back
(
engine_
->
GetITensor
(
input
[
i
])
);
if
(
op_desc
.
HasAttr
(
"out_threshold"
))
{
if
(
op_desc
.
HasAttr
(
"out_threshold"
))
{
float
out_scale
=
float
out_scale
=
PADDLE_GET_CONST
(
float
,
op_desc
.
GetAttr
(
"out_threshold"
));
PADDLE_GET_CONST
(
float
,
op_desc
.
GetAttr
(
"out_threshold"
));
...
@@ -54,28 +53,37 @@ class StackOpConverter : public OpConverter {
...
@@ -54,28 +53,37 @@ class StackOpConverter : public OpConverter {
}
}
int
axis
=
PADDLE_GET_CONST
(
int
,
op_desc
.
GetAttr
(
"axis"
));
int
axis
=
PADDLE_GET_CONST
(
int
,
op_desc
.
GetAttr
(
"axis"
));
int
output_rank
=
inputs
[
0
]
->
getDimensions
().
nbDims
+
1
;
if
(
axis
<
0
)
{
if
(
axis
<
0
)
{
axis
=
axis
+
inputs
[
0
]
->
getDimensions
().
nbDims
+
1
;
axis
=
axis
+
output_rank
;
}
}
// Now, axis is relative to output_rank.
auto
*
shape_tensor
=
Shape
(
inputs
[
0
]);
std
::
vector
<
nvinfer1
::
ITensor
*>
shape_tensor_vec
;
for
(
int
i
=
0
;
i
<
output_rank
;
i
++
)
{
if
(
i
<
axis
)
{
shape_tensor_vec
.
push_back
(
GetEleTensorOfShape
(
shape_tensor
,
i
));
}
else
if
(
i
>
axis
)
{
shape_tensor_vec
.
push_back
(
GetEleTensorOfShape
(
shape_tensor
,
i
-
1
));
}
else
{
shape_tensor_vec
.
push_back
(
Add1DConstantLayer
(
1
));
}
}
auto
*
after_shape_tensor
=
Concat
(
shape_tensor_vec
);
for
(
int
i
=
0
;
i
<
input_num
;
++
i
)
{
auto
*
reshape_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Shuffle
,
*
inputs
[
i
]);
reshape_layer
->
setInput
(
1
,
*
after_shape_tensor
);
inputs
[
i
]
=
reshape_layer
->
getOutput
(
0
);
}
auto
*
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Concatenation
,
inputs
.
data
(),
inputs
.
size
());
layer
->
setAxis
(
axis
);
nvinfer1
::
ILayer
*
layer
=
nullptr
;
#if IS_TRT_VERSION_GE(6000)
bool
with_fp16
=
engine_
->
WithFp16
()
&&
!
engine_
->
disable_trt_plugin_fp16
();
plugin
::
StackPluginDynamic
*
plugin
=
new
plugin
::
StackPluginDynamic
(
axis
,
input_num
,
with_fp16
);
layer
=
engine_
->
AddDynamicPlugin
(
inputs
,
input_num
,
plugin
);
PADDLE_ENFORCE_NOT_NULL
(
layer
,
platform
::
errors
::
InvalidArgument
(
"trt stack layer in converter could not be created."
));
#else
PADDLE_THROW
(
platform
::
errors
::
Fatal
(
"You are running the TRT Dynamic Shape mode, need to confirm that "
"your TRT version is no less than 6.0"
));
#endif
auto
output_name
=
op_desc
.
Output
(
"Y"
).
front
();
auto
output_name
=
op_desc
.
Output
(
"Y"
).
front
();
RreplenishLayerAndOutput
(
layer
,
"stack"
,
{
output_name
},
test_mode
);
RreplenishLayerAndOutput
(
layer
,
"stack"
,
{
output_name
},
test_mode
);
free
(
inputs
);
}
}
};
};
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_stack.py
浏览文件 @
a9f3719b
...
@@ -41,33 +41,33 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
...
@@ -41,33 +41,33 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
ones
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
3
:
elif
self
.
dims
==
3
:
return
np
.
ones
([
batch
,
3
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
2
:
elif
self
.
dims
==
2
:
return
np
.
ones
([
batch
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
1
:
elif
self
.
dims
==
1
:
return
np
.
ones
([
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
24
]).
astype
(
np
.
float32
)
def
generate_input2
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
def
generate_input2
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
ones
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
3
:
elif
self
.
dims
==
3
:
return
np
.
ones
([
batch
,
3
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
2
:
elif
self
.
dims
==
2
:
return
np
.
ones
([
batch
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
1
:
elif
self
.
dims
==
1
:
return
np
.
ones
([
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
24
]).
astype
(
np
.
float32
)
def
generate_input3
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
def
generate_input3
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
ones
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
3
:
elif
self
.
dims
==
3
:
return
np
.
ones
([
batch
,
3
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
2
:
elif
self
.
dims
==
2
:
return
np
.
ones
([
batch
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
1
:
elif
self
.
dims
==
1
:
return
np
.
ones
([
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
24
]).
astype
(
np
.
float32
)
for
dims
in
[
1
,
2
,
3
,
4
]:
for
dims
in
[
1
,
2
,
3
,
4
]:
for
batch
in
[
1
,
4
]:
for
batch
in
[
1
,
4
]:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录