Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
5f30dc7f
X
X2Paddle
项目概览
PaddlePaddle
/
X2Paddle
大约 1 年 前同步成功
通知
328
Star
698
Fork
167
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
26
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
X2Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
26
Issue
26
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5f30dc7f
编写于
5月 06, 2022
作者:
W
wjj19950828
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support Marian model
上级
b9c2c898
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
85 addition
and
85 deletion
+85
-85
docs/inference_model_convertor/op_list.md
docs/inference_model_convertor/op_list.md
+1
-1
x2paddle/op_mapper/pytorch2paddle/aten.py
x2paddle/op_mapper/pytorch2paddle/aten.py
+84
-84
未找到文件。
docs/inference_model_convertor/op_list.md
浏览文件 @
5f30dc7f
...
...
@@ -115,7 +115,7 @@ Aten:
| 121 | aten::repeat
\_
interleave | 122 | aten::maxpool1d | 123 | aten::frobenius
\_
norm | 124 | aten::format |
| 125 | aten::complex | 126 | aten::real | 127 | aten::imag | 128 | aten::fft
\_
rfftn |
| 129 | aten::fft
\_
irfftn | 130 | aten::hardsigmoid | 131 | aten::hardswish | 132 | aten::linear |
| 133 | aten::rsqrt |
|
| | | | |
| 133 | aten::rsqrt |
134 | aten::full
| | | | |
Prim:
...
...
x2paddle/op_mapper/pytorch2paddle/aten.py
浏览文件 @
5f30dc7f
...
...
@@ -2416,6 +2416,53 @@ def aten_format(mapper, graph, node):
return
current_inputs
,
current_outputs
def
aten_full
(
mapper
,
graph
,
node
):
"""
TorchScript Code:
%159 : Tensor = aten::full(%775, %50, %49, %56, %48, %53)
Parameter meaning:
%159 (Tensor): Output Tensor
%775 (Tensor): size
%50 (int/float/bool): fill_value
%49 (int): dtype
%56 (int): layout
%48 (int): device
%53 (bool): requires_grad
"""
scope_name
=
mapper
.
normalize_scope_name
(
node
)
output_name
=
mapper
.
_get_outputs_name
(
node
)[
0
]
layer_outputs
=
[
output_name
]
layer_inputs
=
{}
layer_attrs
=
{}
inputs_name
,
inputs_node
=
mapper
.
_get_inputs_name
(
node
)
# output list
current_outputs
=
[
output_name
]
mapper
.
_check_input
(
graph
,
inputs_node
[
0
],
inputs_name
[
0
],
current_outputs
,
scope_name
)
layer_inputs
[
"shape"
]
=
inputs_name
[
0
]
# input list
current_inputs
=
list
(
layer_inputs
.
values
())
if
inputs_name
[
1
]
in
mapper
.
attrs
:
layer_attrs
[
"fill_value"
]
=
mapper
.
attrs
[
inputs_name
[
1
]]
else
:
mapper
.
_check_input
(
graph
,
inputs_node
[
1
],
inputs_name
[
1
],
current_outputs
,
scope_name
)
layer_inputs
[
"fill_value"
]
=
inputs_name
[
1
]
current_inputs
.
append
(
inputs_name
[
1
])
# dtype
if
mapper
.
attrs
[
inputs_name
[
2
]]
is
not
None
:
layer_attrs
[
"dtype"
]
=
dtype_dict
[
mapper
.
attrs
[
inputs_name
[
2
]]]
graph
.
add_layer
(
"paddle.full"
,
inputs
=
layer_inputs
,
outputs
=
layer_outputs
,
scope_name
=
scope_name
,
**
layer_attrs
)
return
current_inputs
,
current_outputs
def
aten_full_like
(
mapper
,
graph
,
node
):
""" 构造创建一个与输入具有相同的形状并且数据类型固定的Tensor的PaddleLayer。
TorchScript示例:
...
...
@@ -3489,109 +3536,62 @@ def aten_lt(mapper, graph, node):
def
aten_masked_fill
(
mapper
,
graph
,
node
):
"""
构造填充mask的PaddleLayer。
TorchScript
示例
:
"""
TorchScript
Code
:
%input.4 : Tensor = aten::masked_fill(%scores.2, %mask.2, %46)
参数含义
:
%input.4 (Tensor):
输出,填充后的结果。
%scores.2 (Tensor):
需要填充的Tensor。
%mask.2 (Tensor): bool
型的Tensor,哪些位置需要填充。
%46 (-):
填充的值。
Parameter meaning
:
%input.4 (Tensor):
Output Tensor
%scores.2 (Tensor):
Input Tensor
%mask.2 (Tensor): bool
mask
%46 (-):
fill value
"""
scope_name
=
mapper
.
normalize_scope_name
(
node
)
output_name
=
mapper
.
_get_outputs_name
(
node
)[
0
]
layer_outputs
=
[
output_name
]
inputs_name
,
inputs_node
=
mapper
.
_get_inputs_name
(
node
)
# 获取当前节点输入的list
layer_full_inputs
=
{}
layer_full_attrs
=
{}
layer_where_inputs
=
{}
current_inputs
=
[]
# 获取当前节点输出的list
current_outputs
=
[
output_name
]
#
处理输入0,即%input.4
#
input list
mapper
.
_check_input
(
graph
,
inputs_node
[
0
],
inputs_name
[
0
],
current_outputs
,
scope_name
)
current_inputs
.
append
(
inputs_name
[
0
])
# paddle.full
graph
.
add_layer
(
"prim.
ty
pe"
,
"prim.
sha
pe"
,
inputs
=
{
"input"
:
inputs_name
[
0
]},
outputs
=
[
inputs_name
[
0
]
+
"_type"
],
scope_name
=
scope_name
)
# 处理输入1,即%scores.2
mapper
.
_check_input
(
graph
,
inputs_node
[
1
],
inputs_name
[
1
],
current_outputs
,
scope_name
)
current_inputs
.
append
(
inputs_name
[
1
])
graph
.
add_layer
(
"paddle.logical_not"
,
inputs
=
{
"x"
:
inputs_name
[
1
]},
outputs
=
[
inputs_name
[
1
]
+
"_not"
],
outputs
=
[
inputs_name
[
0
]
+
"_shape"
],
scope_name
=
scope_name
)
layer_full_inputs
[
"shape"
]
=
inputs_name
[
0
]
+
"_shape"
if
inputs_name
[
2
]
in
mapper
.
attrs
:
layer_full_attrs
[
"fill_value"
]
=
mapper
.
attrs
[
inputs_name
[
2
]]
else
:
mapper
.
_check_input
(
graph
,
inputs_node
[
2
],
inputs_name
[
2
],
current_outputs
,
scope_name
)
layer_full_inputs
[
"fill_value"
]
=
inputs_name
[
2
]
current_inputs
.
append
(
inputs_name
[
2
])
graph
.
add_layer
(
"paddle.cast"
,
inputs
=
{
"x"
:
inputs_name
[
1
]},
outputs
=
[
inputs_name
[
1
]
+
"_mask"
],
scope_name
=
scope_name
,
dtype
=
inputs_name
[
0
]
+
"_type"
)
graph
.
add_layer
(
"paddle.cast"
,
inputs
=
{
"x"
:
inputs_name
[
1
]
+
"_not"
},
outputs
=
[
inputs_name
[
1
]
+
"_not_mask"
],
scope_name
=
scope_name
,
dtype
=
inputs_name
[
0
]
+
"_type"
)
graph
.
add_layer
(
"paddle.multiply"
,
inputs
=
{
"x"
:
inputs_name
[
0
],
"y"
:
inputs_name
[
1
]
+
"_not_mask"
},
outputs
=
[
inputs_name
[
0
]
+
"_not_mask"
],
"prim.type"
,
inputs
=
{
"input"
:
inputs_name
[
0
]},
outputs
=
[
inputs_name
[
0
]
+
"_type"
],
scope_name
=
scope_name
)
# 处理输入2,即%46
mapper
.
_check_input
(
graph
,
inputs_node
[
2
],
inputs_name
[
2
],
current_outputs
,
scope_name
)
layer_full_attrs
[
"dtype"
]
=
inputs_name
[
0
]
+
"_type"
graph
.
add_layer
(
"prim.eq"
,
inputs
=
{
"x"
:
inputs_name
[
2
]},
outputs
=
[
inputs_name
[
2
]
+
"_cond1"
],
scope_name
=
scope_name
,
y
=
"-float('inf')"
)
graph
.
add_layer
(
"prim.eq"
,
inputs
=
{
"x"
:
inputs_name
[
2
]},
outputs
=
[
inputs_name
[
2
]
+
"_cond2"
],
"paddle.full"
,
inputs
=
layer_full_inputs
,
outputs
=
[
inputs_name
[
0
]
+
"_full"
],
scope_name
=
scope_name
,
y
=
"float('inf')"
)
graph
.
add_layer
(
"prim.or"
,
inputs
=
{
"x"
:
inputs_name
[
2
]
+
"_cond1"
,
"y"
:
inputs_name
[
2
]
+
"_cond2"
},
outputs
=
[
inputs_name
[
2
]
+
"_cond"
],
scope_name
=
scope_name
)
**
layer_full_attrs
)
# paddle.where
layer_where_inputs
[
"condition"
]
=
inputs_name
[
1
]
layer_where_inputs
[
"x"
]
=
inputs_name
[
0
]
+
"_full"
layer_where_inputs
[
"y"
]
=
inputs_name
[
0
]
graph
.
add_layer
(
"prim.if"
,
{
'input'
:
inputs_name
[
2
]
+
"_cond"
},
outputs
=
[
inputs_name
[
2
]
+
"_if"
],
scope_name
=
scope_name
)
if_layer
=
graph
.
layers
[
list
(
graph
.
layers
.
keys
())[
-
1
]]
block
=
PaddleGraph
(
source_type
=
"pytorch"
,
parent_layer
=
if_layer
)
block
.
add_layer
(
"prim.equal"
,
inputs
=
{
"input"
:
inputs_name
[
1
]
+
"_mask"
},
outputs
=
[
inputs_name
[
2
]
+
"_1"
],
scope_name
=
scope_name
)
if_layer
.
add_block
(
block
)
block
=
PaddleGraph
(
source_type
=
"pytorch"
,
parent_layer
=
if_layer
)
block
.
add_layer
(
"prim.mul"
,
inputs
=
{
"x"
:
inputs_name
[
1
]
+
"_mask"
,
"y"
:
inputs_name
[
2
]},
outputs
=
[
inputs_name
[
2
]
+
"_1"
],
scope_name
=
scope_name
)
if_layer
.
add_block
(
block
)
if_layer
.
inputs
[
"input-0"
]
=
inputs_name
[
1
]
+
"_mask"
if_layer
.
inputs
[
"input-1"
]
=
inputs_name
[
2
]
if_layer
.
outputs
.
append
(
inputs_name
[
2
]
+
"_1"
)
graph
.
add_layer
(
"paddle.add"
,
inputs
=
{
"x"
:
inputs_name
[
2
]
+
"_1"
,
"y"
:
inputs_name
[
0
]
+
"_not_mask"
},
"paddle.where"
,
inputs
=
layer_where_inputs
,
outputs
=
layer_outputs
,
scope_name
=
scope_name
)
return
current_inputs
,
current_outputs
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录