Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
169b989e
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看板
提交
169b989e
编写于
8月 04, 2020
作者:
M
mamingjie-China
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support for bert
上级
2c831a8d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
96 addition
and
0 deletion
+96
-0
x2paddle/op_mapper/tf_op_mapper_nhwc.py
x2paddle/op_mapper/tf_op_mapper_nhwc.py
+96
-0
未找到文件。
x2paddle/op_mapper/tf_op_mapper_nhwc.py
浏览文件 @
169b989e
...
...
@@ -550,6 +550,12 @@ class TFOpMapperNHWC(OpMapper):
transpose_x
=
transpose_a
,
transpose_y
=
transpose_b
)
def
BatchMatMul
(
self
,
node
):
return
self
.
MatMul
(
node
)
def
BatchMatMulV2
(
self
,
node
):
return
self
.
MatMul
(
node
)
def
DepthwiseConv2dNative
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
])
kernel
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
])
...
...
@@ -1043,3 +1049,93 @@ class TFOpMapperNHWC(OpMapper):
inputs
=
{
"x"
:
node
.
name
,
"y"
:
node
.
name
}
program
.
add_layer
(
"fluid.layers.elementwise_mul"
,
inputs
=
inputs
,
outputs
=
[
node
.
name
])
def
OneHot
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
])
depth
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
])
on_value
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
2
])
off_value
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
3
])
assert
depth
.
layer_type
==
'Const'
,
'Parameter depth should be Const in OneHot'
assert
on_value
.
layer_type
==
'Const'
,
'Parameter on_value should be Const in OneHot'
assert
off_value
.
layer_type
==
'Const'
,
'Parameter off_value should be Const in OneHot'
attr
=
{
'depth'
:
depth
.
value
}
on_value
=
on_value
.
value
off_value
=
off_value
.
value
assert
math
.
fabs
(
on_value
-
1.0
)
<
1e-06
,
"on_value should be 1 in OneHot"
assert
math
.
fabs
(
off_value
-
0.0
)
<
1e-06
,
"off_value should be 0 in OneHot"
program
.
add_layer
(
"fluid.one_hot"
,
inputs
=
{
"input"
:
input
.
name
},
outputs
=
[
node
.
name
],
depth
=
depth
.
value
)
def
Pow
(
self
,
node
):
x
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
])
factor
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
])
inputs
=
{
"x"
:
x
.
name
}
attr
=
dict
()
if
factor
.
layer_type
==
'Const'
:
attr
[
"factor"
]
=
factor
.
value
.
tolist
()
else
:
inputs
[
"factor"
]
=
factor
.
name
program
.
add_layer
(
"fluid.layers.pow"
,
inputs
=
inputs
,
outputs
=
[
node
.
name
],
**
attr
)
def
All
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
])
reduce_idx
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
])
assert
reduce_idx
.
layer_type
==
"Const"
,
"Only support Const parameter[reduce_idx]"
attr
=
dict
()
attr
[
"dim"
]
=
reduce_idx
.
value
.
tolist
()
attr
[
"keep_dim"
]
=
node
.
get_attr
(
"keep_dims"
)
program
.
add_layer
(
"fluid.layers.reduce_all"
,
inputs
=
{
"input"
:
input
.
name
},
outputs
=
[
node
.
name
],
**
attr
)
def
GatherV2
(
self
,
node
):
embeddings
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
])
index
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
])
axis
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
2
])
assert
axis
.
layer_type
==
'Const'
,
"Only support Const parameter[axis]"
axis
=
axis
.
value
.
tolist
()
assert
axis
==
0
,
"Only support axis=0 in GatherV2 OP"
index_name
=
index
.
name
if
len
(
index
.
out_shapes
[
0
])
!=
1
:
reshape_name
=
gen_name
(
"gather"
,
"reshape"
)
index_name
=
reshape_name
program
.
add_layer
(
"fluid.layers.reshape"
,
inputs
=
{
"x"
:
index
.
name
},
outputs
=
[
reshape_name
],
shape
=
[
-
1
])
inputs
=
{
'input'
:
embeddings
.
name
,
'index'
:
index_name
}
program
.
add_layer
(
"fluid.layers.gather"
,
inputs
=
inputs
,
outputs
=
[
node
.
name
],
overwrite
=
False
)
def
ExpandDims
(
self
,
node
):
x
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
y
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
inputs
=
{
"input"
:
x
.
name
}
attr
=
dict
()
if
y
.
layer_type
==
'Const'
:
dim
=
y
.
value
.
tolist
()
if
not
isinstance
(
dim
,
list
):
dim
=
[
dim
]
attr
[
'axes'
]
=
dim
else
:
inputs
[
'axes'
]
=
y
.
name
program
.
add_layer
(
"fluid.layers.unsqueeze"
,
inputs
=
inputs
,
outputs
=
[
node
.
name
],
**
attr
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录