Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
48ef3d78
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
未验证
提交
48ef3d78
编写于
6月 30, 2023
作者:
L
lzydev
提交者:
GitHub
6月 30, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
suppot auto-gen norm (#54943)
上级
150ca413
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
29 addition
and
147 deletion
+29
-147
paddle/fluid/operators/norm_op.cc
paddle/fluid/operators/norm_op.cc
+0
-111
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+9
-0
paddle/phi/api/yaml/static_backward.yaml
paddle/phi/api/yaml/static_backward.yaml
+10
-0
paddle/phi/api/yaml/static_ops.yaml
paddle/phi/api/yaml/static_ops.yaml
+10
-0
paddle/phi/ops/compat/norm_sig.cc
paddle/phi/ops/compat/norm_sig.cc
+0
-36
未找到文件。
paddle/fluid/operators/norm_op.cc
已删除
100644 → 0
浏览文件 @
150ca413
/* Copyright (c) 2016 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.
Indicesou 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 <memory>
#include <string>
#include <vector>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/infermeta/unary.h"
namespace
paddle
{
namespace
operators
{
class
NormOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"X"
,
"(Tensor) A tensor of rank >= axis."
);
AddAttr
<
int
>
(
"axis"
,
"The axis on which to apply normalization. If axis < 0, "
"the dimension to normalization is rank(X) + axis. -1 is "
"the last dimension."
);
AddAttr
<
float
>
(
"epsilon"
,
"(float, default 1e-10) The epsilon value is used "
"to avoid division by zero."
)
.
SetDefault
(
1.0e-10
f
);
AddOutput
(
"Norm"
,
"(Tensor) A tensor saved the `sqrt(sum(x) + epsion)` will "
"be used in backward kernel."
)
.
AsIntermediate
()
.
AsExtra
();
AddAttr
<
bool
>
(
"is_test"
,
"(bool, default false) Set to true for inference only, false "
"for training."
)
.
SetDefault
(
false
);
AddOutput
(
"Out"
,
"(Tensor) A tensor of the same shape as X."
);
AddComment
(
R"DOC(
Given a tensor, apply 2-normalization along the provided axis.
$$
y = \frac{x}{ \sqrt{\sum {x^2} + epsion }}
$$
where, $\sum {x^2}$ is calculated along the `axis` dimension.
)DOC"
);
}
};
class
NormOp
:
public
framework
::
OperatorWithKernel
{
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
};
class
NormOpGrad
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"NormOpGrad"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)),
"Input"
,
"X@GRAD"
,
"NormOpGrad"
);
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"X"
));
}
};
template
<
typename
T
>
class
NormOpGradOpMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
public:
using
framework
::
SingleGradOpMaker
<
T
>::
SingleGradOpMaker
;
protected:
void
Apply
(
GradOpPtr
<
T
>
op
)
const
override
{
op
->
SetType
(
"norm_grad"
);
op
->
SetAttrMap
(
this
->
Attrs
());
op
->
SetInput
(
"X"
,
this
->
Input
(
"X"
));
op
->
SetInput
(
framework
::
GradVarName
(
"Out"
),
this
->
OutputGrad
(
"Out"
));
op
->
SetInput
(
"Norm"
,
this
->
Output
(
"Norm"
));
op
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
this
->
InputGrad
(
"X"
));
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
using
CPU
=
phi
::
CPUContext
;
DECLARE_INFER_SHAPE_FUNCTOR
(
norm
,
NormInferShapeFunctor
,
PD_INFER_META
(
phi
::
NormInferMeta
));
REGISTER_OPERATOR
(
norm
,
ops
::
NormOp
,
ops
::
NormOpMaker
,
ops
::
NormOpGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
NormOpGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
NormInferShapeFunctor
);
REGISTER_OPERATOR
(
norm_grad
,
ops
::
NormOpGrad
);
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
48ef3d78
...
@@ -1888,6 +1888,15 @@
...
@@ -1888,6 +1888,15 @@
outputs
:
outputs
:
out
:
Out
out
:
Out
-
op
:
norm
backward
:
norm_grad
inputs
:
x
:
X
outputs
:
{
out
:
Out
,
norm
:
Norm
}
extra
:
outputs
:
[
norm
]
-
op
:
not_equal
-
op
:
not_equal
inputs
:
inputs
:
{
x
:
X
,
y
:
Y
}
{
x
:
X
,
y
:
Y
}
...
...
paddle/phi/api/yaml/static_backward.yaml
浏览文件 @
48ef3d78
...
@@ -188,6 +188,16 @@
...
@@ -188,6 +188,16 @@
kernel
:
kernel
:
func
:
min_grad
func
:
min_grad
-
backward_op
:
norm_grad
forward
:
norm (Tensor x, int axis, float epsilon=1.0e-10f, bool is_test=false) -> Tensor(out), Tensor(norm)
args
:
(Tensor x, Tensor norm, Tensor out_grad, int axis, float epsilon, bool is_test)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
norm_grad
-
backward_op
:
pool2d_double_grad
-
backward_op
:
pool2d_double_grad
forward
:
pool2d_grad(Tensor x, Tensor out, Tensor grad_out, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x)
forward
:
pool2d_grad(Tensor x, Tensor out, Tensor grad_out, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x)
args
:
(Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm)
args
:
(Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm)
...
...
paddle/phi/api/yaml/static_ops.yaml
浏览文件 @
48ef3d78
...
@@ -369,6 +369,16 @@
...
@@ -369,6 +369,16 @@
param
:
[
x
,
axis
,
keepdim
,
reduce_all
]
param
:
[
x
,
axis
,
keepdim
,
reduce_all
]
backward
:
min_grad
backward
:
min_grad
-
op
:
norm
args
:
(Tensor x, int axis, float epsilon=1.0e-10f, bool is_test=false)
output
:
Tensor(out), Tensor(norm)
infer_meta
:
func
:
NormInferMeta
kernel
:
func
:
norm
backward
:
norm_grad
intermediate
:
norm
-
op
:
not_equal
-
op
:
not_equal
args
:
(Tensor x, Tensor y, int axis = -1, bool force_cpu=false)
args
:
(Tensor x, Tensor y, int axis = -1, bool force_cpu=false)
output
:
Tensor(out)
output
:
Tensor(out)
...
...
paddle/phi/ops/compat/norm_sig.cc
已删除
100644 → 0
浏览文件 @
150ca413
// 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
NormOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
UNUSED
)
{
return
KernelSignature
(
"norm"
,
{
"X"
},
{
"axis"
,
"epsilon"
,
"is_test"
},
{
"Out"
,
"Norm"
});
}
KernelSignature
NormGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
UNUSED
)
{
return
KernelSignature
(
"norm_grad"
,
{
"X"
,
"Norm"
,
"Out@GRAD"
},
{
"axis"
,
"epsilon"
,
"is_test"
},
{
"X@GRAD"
});
}
}
// namespace phi
PD_REGISTER_ARG_MAPPING_FN
(
norm
,
phi
::
NormOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
norm_grad
,
phi
::
NormGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录