Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
aab6c75d
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看板
未验证
提交
aab6c75d
编写于
4月 28, 2022
作者:
J
Jason
提交者:
GitHub
4月 28, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #769 from wjj19950828/add_linear
Add aten::linear
上级
45dc29c1
4a162161
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
60 addition
and
5 deletion
+60
-5
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
+49
-0
x2paddle/optimizer/fusion/trace_fc_fuser.py
x2paddle/optimizer/fusion/trace_fc_fuser.py
+7
-4
x2paddle/optimizer/pattern_matcher.py
x2paddle/optimizer/pattern_matcher.py
+3
-0
未找到文件。
docs/inference_model_convertor/op_list.md
浏览文件 @
aab6c75d
...
...
@@ -114,7 +114,7 @@ Aten:
| 117 | aten::bitwise
\_
not | 118 | aten::bitwise
\_
xor | 119 | aten::bitwise
\_
and | 120 | aten::silu |
| 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 |
|
|
| 129 | aten::fft
\_
irfftn | 130 | aten::hardsigmoid | 131 | aten::hardswish |
132 | aten::linear
|
Prim:
...
...
x2paddle/op_mapper/pytorch2paddle/aten.py
浏览文件 @
aab6c75d
...
...
@@ -3238,6 +3238,55 @@ def aten_len(mapper, graph, node):
return
current_inputs
,
current_outputs
def
aten_linear
(
mapper
,
graph
,
node
):
"""
TorchScript Code:
%x.6 : Float(1, 128, strides=[128, 1]) = aten::linear(%input.305, %weight.629, %bias.317)
Parameter meaning:
%x.6 (Tensor): output
%input.305 (Tensor): input tensor
%weight.629 (Tensor): weight tensor
%bias.317 (Tensor): bias tensor
"""
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
)
# outputs list
current_outputs
=
[
output_name
]
# inputs list
mapper
.
_check_input
(
graph
,
inputs_node
[
0
],
inputs_name
[
0
],
current_outputs
,
scope_name
)
layer_inputs
[
"x"
]
=
inputs_name
[
0
]
# transpose weight
mapper
.
_check_input
(
graph
,
inputs_node
[
1
],
inputs_name
[
1
],
current_outputs
,
scope_name
)
layer_attrs_transpose
=
{}
layer_attrs_transpose
[
"perm"
]
=
[
1
,
0
]
graph
.
add_layer
(
"paddle.transpose"
,
inputs
=
{
"x"
:
inputs_name
[
1
]},
outputs
=
[
inputs_name
[
1
]
+
"_transpose"
],
scope_name
=
scope_name
,
**
layer_attrs_transpose
)
layer_inputs
[
"weight"
]
=
inputs_name
[
1
]
+
"_transpose"
if
len
(
inputs_name
)
==
3
:
mapper
.
_check_input
(
graph
,
inputs_node
[
2
],
inputs_name
[
2
],
current_outputs
,
scope_name
)
layer_inputs
[
"bias"
]
=
inputs_name
[
2
]
current_inputs
=
list
(
layer_inputs
.
values
())
graph
.
add_layer
(
"paddle.nn.functional.linear"
,
inputs
=
layer_inputs
,
outputs
=
layer_outputs
,
scope_name
=
scope_name
,
**
layer_attrs
)
return
current_inputs
,
current_outputs
def
aten_log
(
mapper
,
graph
,
node
):
""" 构构造log的PaddleLayer。
TorchScript示例:
...
...
x2paddle/optimizer/fusion/trace_fc_fuser.py
浏览文件 @
aab6c75d
...
...
@@ -113,10 +113,13 @@ class TraceFcFuser(FuseBase):
attrs
[
"out_features"
]
=
parameters
[
weight_name
].
shape
[
0
]
linear_name
=
"linear{}"
.
format
(
self
.
linear_index
)
self
.
linear_index
+=
1
parameters
[
"{}.weight"
.
format
(
linear_name
)]
=
parameters
[
weight_name
].
transpose
((
1
,
0
))
parameters
[
"{}.bias"
.
format
(
linear_name
)]
=
np
.
squeeze
(
parameters
[
bias_name
])
weight_numpy
=
parameters
[
weight_name
]
parameters
[
"{}.weight"
.
format
(
linear_name
)]
=
weight_numpy
.
transpose
(
(
1
,
0
))
self
.
rm_params
.
add
(
weight_name
)
bias_numpy
=
parameters
[
bias_name
]
parameters
[
"{}.bias"
.
format
(
linear_name
)]
=
np
.
squeeze
(
bias_numpy
)
self
.
rm_params
.
add
(
bias_name
)
new_layer
=
PaddleLayer
(
layers_id
[
0
],
"paddle.nn.Linear"
,
...
...
x2paddle/optimizer/pattern_matcher.py
浏览文件 @
aab6c75d
...
...
@@ -325,6 +325,7 @@ class FuseBase(object):
def
__init__
(
self
):
self
.
pattern
=
PaddleGraph
()
self
.
patterns
=
list
()
self
.
rm_params
=
set
()
def
operate
(
self
,
graph
,
match_kind
=
"topo"
):
parameters
=
graph
.
parameters
...
...
@@ -335,6 +336,8 @@ class FuseBase(object):
subgraph
=
get_subgraph
(
""
,
first_layer_id
,
graph
)
self
.
insert_new_layer
(
subgraph
,
parameters
,
match
)
self
.
delete_match
(
graph
)
for
param_name
in
self
.
rm_params
:
parameters
.
pop
(
param_name
)
graph
.
build
()
def
perform_pattern_matcher
(
self
,
graph
,
match_kind
=
"topo"
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录