Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
34d68f24
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看板
提交
34d68f24
编写于
11月 03, 2017
作者:
W
wwhu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix doc and code style
上级
65451b5c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
12 addition
and
37 deletion
+12
-37
paddle/operators/clip_by_norm_op.cc
paddle/operators/clip_by_norm_op.cc
+7
-26
paddle/operators/clip_by_norm_op.cu
paddle/operators/clip_by_norm_op.cu
+2
-3
paddle/operators/clip_by_norm_op.h
paddle/operators/clip_by_norm_op.h
+0
-3
python/paddle/v2/framework/tests/test_clip_by_norm_op.py
python/paddle/v2/framework/tests/test_clip_by_norm_op.py
+3
-5
未找到文件。
paddle/operators/clip_by_norm_op.cc
浏览文件 @
34d68f24
...
...
@@ -39,15 +39,14 @@ template <typename AttrType>
class
ClipByNormOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
ClipByNormOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"(Tensor)The input of clip_by_norm op."
"(Tensor)
The input of clip_by_norm op."
"The number of dimensions must be between [1, 9]."
);
AddOutput
(
"Out"
,
"(Tensor)The output of clip_by_norm op with shape as input(X)"
);
AddAttr
<
AttrType
>
(
"max_norm"
,
"(float)The maximum norm value."
);
"(Tensor) The output of clip_by_norm op with shape as input(X)"
);
AddAttr
<
AttrType
>
(
"max_norm"
,
"(float)The maximum norm value."
);
AddComment
(
R"DOC(
ClipByNorm operator limits the L2 norm of the input 'X' within 'max_norm'.
If the L2 norm of 'X' is less than or equal to 'max_norm', 'Out' will be
...
...
@@ -62,29 +61,11 @@ where norm('X') represents the L2 norm of 'X'.
}
};
class
ClipByNormOpGrad
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) should not be null"
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
"Input(Out@GRAD) should not be null"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
if
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)))
{
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
x_dims
);
}
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_WITHOUT_GRADIENT
(
clip_by_norm
,
ops
::
ClipByNormOp
,
REGISTER_OP_WITHOUT_GRADIENT
(
clip_by_norm
,
ops
::
ClipByNormOp
,
ops
::
ClipByNormOpMaker
<
float
>
);
REGISTER_OP_CPU_KERNEL
(
clip_by_norm
,
ops
::
ClipByNormKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
clip_by_norm
,
ops
::
ClipByNormKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
paddle/operators/clip_by_norm_op.cu
浏览文件 @
34d68f24
...
...
@@ -15,6 +15,5 @@
#include "paddle/operators/clip_by_norm_op.h"
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
clip_by_norm
,
ops
::
ClipByNormKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
REGISTER_OP_GPU_KERNEL
(
clip_by_norm
,
ops
::
ClipByNormKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
paddle/operators/clip_by_norm_op.h
浏览文件 @
34d68f24
...
...
@@ -25,9 +25,6 @@ using Tensor = framework::Tensor;
template
<
typename
T
,
int
MajorType
=
Eigen
::
RowMajor
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenVector
=
framework
::
EigenVector
<
T
,
MajorType
,
IndexType
>
;
template
<
typename
T
,
int
MajorType
=
Eigen
::
RowMajor
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenScalar
=
framework
::
EigenScalar
<
T
,
MajorType
,
IndexType
>
;
template
<
typename
Place
,
typename
T
>
class
ClipByNormKernel
:
public
framework
::
OpKernel
<
T
>
{
...
...
python/paddle/v2/framework/tests/test_clip_by_norm_op.py
浏览文件 @
34d68f24
...
...
@@ -18,21 +18,19 @@ class TestClipByNormOp(OpTest):
output
=
self
.
max_norm
*
input
/
norm
else
:
output
=
input
self
.
outputs
=
{
'Out'
:
output
}
self
.
outputs
=
{
'Out'
:
output
}
def
test_check_output
(
self
):
self
.
check_output
()
def
initTestCase
(
self
):
self
.
shape
=
(
100
,)
self
.
shape
=
(
100
,
)
self
.
max_norm
=
1.0
class
TestCase1
(
TestClipByNormOp
):
def
initTestCase
(
self
):
self
.
shape
=
(
100
,)
self
.
shape
=
(
100
,
)
self
.
max_norm
=
1e20
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录