Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a7070f34
P
Paddle
项目概览
PaddlePaddle
/
Paddle
接近 2 年 前同步成功
通知
2322
Star
20933
Fork
5424
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a7070f34
编写于
4月 13, 2023
作者:
W
Wang Xin
提交者:
GitHub
4月 13, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add autogen code support for expand_as op (#52797)
* add autogen code support for expand_as op * bug fixed
上级
9bdf7f02
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
31 addition
and
183 deletion
+31
-183
paddle/fluid/operators/expand_as_v2_op.cc
paddle/fluid/operators/expand_as_v2_op.cc
+0
-124
paddle/phi/api/yaml/backward.yaml
paddle/phi/api/yaml/backward.yaml
+11
-0
paddle/phi/api/yaml/legacy_backward.yaml
paddle/phi/api/yaml/legacy_backward.yaml
+0
-11
paddle/phi/api/yaml/legacy_ops.yaml
paddle/phi/api/yaml/legacy_ops.yaml
+0
-10
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+2
-2
paddle/phi/api/yaml/op_version.yaml
paddle/phi/api/yaml/op_version.yaml
+7
-0
paddle/phi/api/yaml/ops.yaml
paddle/phi/api/yaml/ops.yaml
+11
-0
paddle/phi/ops/compat/expand_as_sig.cc
paddle/phi/ops/compat/expand_as_sig.cc
+0
-36
未找到文件。
paddle/fluid/operators/expand_as_v2_op.cc
已删除
100644 → 0
浏览文件 @
9bdf7f02
/* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/expand_as_v2_op.h"
#include <memory>
#include <vector>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/phi/infermeta/binary.h"
namespace
paddle
{
namespace
operators
{
class
ExpandAsV2Op
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
return
phi
::
KernelKey
(
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"X"
),
ctx
.
device_context
().
GetPlace
());
}
};
class
ExpandAsV2OpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"X"
,
"(Tensor, default Tensor<float>). A tensor with rank in [1, 6]."
"X is the input to be expanded."
);
AddInput
(
"Y"
,
"(Tensor, default Tensor<float>). A tensor with rank in [1, 6]."
"Expand X according to the shape of Y."
)
.
AsDispensable
();
AddOutput
(
"Out"
,
"(Tensor, default Tensor<float>). A tensor with rank in [1, 6]."
"The rank of Output(Out) have the same with Input(X). "
"After expanding, size of each dimension of Output(Out) is equal "
"to size of the corresponding dimension of Input(X) multiplying "
"the corresponding value given by Attr(expand_times)."
);
AddAttr
<
std
::
vector
<
int
>>
(
"target_shape"
,
"Expand shape for each dimension."
)
.
SetDefault
({});
AddComment
(
R"DOC(
Expand the input to the given shape.
)DOC"
);
}
};
class
ExpandAsV2GradOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"ExpandAsV2Grad"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
"Input"
,
framework
::
GradVarName
(
"Out"
),
"ExpandAsV2Grad"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
x_grad_name
=
framework
::
GradVarName
(
"X"
);
if
(
ctx
->
HasOutput
(
x_grad_name
))
{
ctx
->
SetOutputDim
(
x_grad_name
,
x_dims
);
}
}
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
phi
::
KernelKey
(
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
framework
::
GradVarName
(
"Out"
)),
ctx
.
device_context
().
GetPlace
());
}
};
template
<
typename
T
>
class
ExpandAsV2GradOpMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
public:
using
framework
::
SingleGradOpMaker
<
T
>::
SingleGradOpMaker
;
protected:
void
Apply
(
GradOpPtr
<
T
>
op
)
const
override
{
op
->
SetType
(
"expand_as_v2_grad"
);
op
->
SetInput
(
"X"
,
this
->
Input
(
"X"
));
op
->
SetInput
(
framework
::
GradVarName
(
"Out"
),
this
->
OutputGrad
(
"Out"
));
op
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
this
->
InputGrad
(
"X"
));
op
->
SetAttrMap
(
this
->
Attrs
());
}
};
DECLARE_NO_NEED_BUFFER_VARS_INFERER
(
ExpandAsV2GradNoNeedBufVarsInferer
,
"X"
);
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
expand_as_v2
,
ExpandAsInferShapeFunctor
,
PD_INFER_META
(
phi
::
ExpandAsInferMeta
));
REGISTER_OPERATOR
(
expand_as_v2
,
ops
::
ExpandAsV2Op
,
ops
::
ExpandAsV2OpMaker
,
ops
::
ExpandAsV2GradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
ExpandAsV2GradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
ExpandAsInferShapeFunctor
);
REGISTER_OPERATOR
(
expand_as_v2_grad
,
ops
::
ExpandAsV2GradOp
,
ops
::
ExpandAsV2GradNoNeedBufVarsInferer
);
REGISTER_OP_VERSION
(
expand_as_v2
)
.
AddCheckpoint
(
R"ROC(fix expand_as_v2 and add new input [Y])ROC"
,
paddle
::
framework
::
compatible
::
OpVersionDesc
().
NewInput
(
"Y"
,
"Expand X according to the shape of Y"
));
paddle/phi/api/yaml/backward.yaml
浏览文件 @
a7070f34
...
...
@@ -543,6 +543,17 @@
inplace
:
(out_grad -> x_grad)
composite
:
exp_grad(out, out_grad, x_grad)
-
backward_op
:
expand_as_grad
forward
:
expand_as (Tensor x, Tensor y, int[] target_shape = {}) -> Tensor(out)
args
:
(Tensor x, Tensor out_grad, int[] target_shape)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
expand_as_grad
no_need_buffer
:
x
-
backward_op
:
expm1_grad
forward
:
expm1 (Tensor x) -> Tensor(out)
args
:
(Tensor out, Tensor out_grad)
...
...
paddle/phi/api/yaml/legacy_backward.yaml
浏览文件 @
a7070f34
...
...
@@ -348,17 +348,6 @@
invoke
:
embedding_grad_impl(x, weight, out_grad, padding_idx, sparse, weight_grad)
no_need_buffer
:
weight
-
backward_op
:
expand_as_grad
forward
:
expand_as (Tensor x, Tensor y, int[] target_shape) -> Tensor(out)
args
:
(Tensor x, Tensor out_grad, int[] target_shape)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
expand_as_grad
no_need_buffer
:
x
-
backward_op
:
expand_double_grad
forward
:
expand_grad (Tensor x, Tensor grad_out, IntArray shape) -> Tensor(grad_x)
args
:
(Tensor grad_x_grad, IntArray shape)
...
...
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
a7070f34
...
...
@@ -435,16 +435,6 @@
func
:
expand
backward
:
expand_grad
-
op
:
expand_as
args
:
(Tensor x, Tensor y, int[] target_shape)
output
:
Tensor(out)
infer_meta
:
func
:
ExpandAsInferMeta
kernel
:
func
:
expand_as
optional
:
y
backward
:
expand_as_grad
-
op
:
exponential_
args
:
(Tensor x, float lam)
output
:
Tensor(out)
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
a7070f34
...
...
@@ -740,9 +740,9 @@
attrs
:
[
bool use_mkldnn = false
,
str mkldnn_data_type = "float32"
]
-
op
:
expand_as (expand_as_v2)
backward
:
expand_as_grad (expand_as_v2_grad)
inputs
:
x
:
X
y
:
Y
{
x
:
X
,
y
:
Y
}
outputs
:
out
:
Out
...
...
paddle/phi/api/yaml/op_version.yaml
浏览文件 @
a7070f34
...
...
@@ -66,6 +66,13 @@
comment
:
In order to force fill output variable to gpu memory.
default
:
"
false"
-
op
:
expand_as_v2
version
:
-
checkpoint
:
fix expand_as_v2 and add new input [Y].
action
:
-
add_input
:
Y
comment
:
Expand X according to the shape of Y.
-
op
:
flip
version
:
-
checkpoint
:
Upgrade flip, add new attr [axis] and delete attr [dims]
...
...
paddle/phi/api/yaml/ops.yaml
浏览文件 @
a7070f34
...
...
@@ -608,6 +608,17 @@
inplace
:
(x -> out)
backward
:
exp_grad
-
op
:
expand_as
args
:
(Tensor x, Tensor y, int[] target_shape = {})
output
:
Tensor(out)
infer_meta
:
func
:
ExpandAsInferMeta
kernel
:
func
:
expand_as
data_type
:
x
optional
:
y
backward
:
expand_as_grad
-
op
:
expm1
args
:
(Tensor x)
output
:
Tensor
...
...
paddle/phi/ops/compat/expand_as_sig.cc
已删除
100644 → 0
浏览文件 @
9bdf7f02
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/core/compat/op_utils.h"
namespace
phi
{
KernelSignature
ExpandAsOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"expand_as"
,
{
"X"
,
"Y"
},
{
"target_shape"
},
{
"Out"
});
}
KernelSignature
ExpandAsGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"expand_as_grad"
,
{
"X"
,
"Out@GRAD"
},
{
"target_shape"
},
{
"X@GRAD"
});
}
}
// namespace phi
PD_REGISTER_BASE_KERNEL_NAME
(
expand_as_v2
,
expand_as
);
PD_REGISTER_BASE_KERNEL_NAME
(
expand_as_v2_grad
,
expand_as_grad
);
PD_REGISTER_ARG_MAPPING_FN
(
expand_as_v2
,
phi
::
ExpandAsOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
expand_as_v2_grad
,
phi
::
ExpandAsGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录