Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
1a417a4c
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1a417a4c
编写于
4月 30, 2021
作者:
C
ceci3
提交者:
GitHub
4月 30, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove is_test=True in grad (#32683)
上级
2817239a
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
5 addition
and
15 deletion
+5
-15
paddle/fluid/operators/batch_norm_op.cc
paddle/fluid/operators/batch_norm_op.cc
+3
-8
paddle/fluid/operators/batch_norm_op.cu
paddle/fluid/operators/batch_norm_op.cu
+2
-7
未找到文件。
paddle/fluid/operators/batch_norm_op.cc
浏览文件 @
1a417a4c
...
@@ -575,7 +575,7 @@ class BatchNormGradKernel<platform::CPUDeviceContext, T>
...
@@ -575,7 +575,7 @@ class BatchNormGradKernel<platform::CPUDeviceContext, T>
// SavedVariance have been reverted in forward operator
// SavedVariance have been reverted in forward operator
const
auto
*
saved_inv_variance
=
ctx
.
Input
<
Tensor
>
(
"SavedVariance"
);
const
auto
*
saved_inv_variance
=
ctx
.
Input
<
Tensor
>
(
"SavedVariance"
);
const
std
::
string
data_layout_str
=
ctx
.
Attr
<
std
::
string
>
(
"data_layout"
);
const
std
::
string
data_layout_str
=
ctx
.
Attr
<
std
::
string
>
(
"data_layout"
);
const
bool
use_global_stats
=
ctx
.
Attr
<
bool
>
(
"use_global_stats"
);
bool
use_global_stats
=
ctx
.
Attr
<
bool
>
(
"use_global_stats"
);
const
bool
is_test
=
ctx
.
Attr
<
bool
>
(
"is_test"
);
const
bool
is_test
=
ctx
.
Attr
<
bool
>
(
"is_test"
);
const
float
epsilon
=
ctx
.
Attr
<
float
>
(
"epsilon"
);
const
float
epsilon
=
ctx
.
Attr
<
float
>
(
"epsilon"
);
const
DataLayout
data_layout
=
const
DataLayout
data_layout
=
...
@@ -585,6 +585,8 @@ class BatchNormGradKernel<platform::CPUDeviceContext, T>
...
@@ -585,6 +585,8 @@ class BatchNormGradKernel<platform::CPUDeviceContext, T>
auto
*
d_scale
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Scale"
));
auto
*
d_scale
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Scale"
));
auto
*
d_bias
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Bias"
));
auto
*
d_bias
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Bias"
));
use_global_stats
=
is_test
||
use_global_stats
;
// batch_norm with inplace as false will take X as grad input, which
// batch_norm with inplace as false will take X as grad input, which
// is same as cuDNN batch_norm backward calculation, batch_norm
// is same as cuDNN batch_norm backward calculation, batch_norm
// with inplace as true only take Y as input and X should be calculate
// with inplace as true only take Y as input and X should be calculate
...
@@ -605,13 +607,6 @@ class BatchNormGradKernel<platform::CPUDeviceContext, T>
...
@@ -605,13 +607,6 @@ class BatchNormGradKernel<platform::CPUDeviceContext, T>
"X@GRAD and Y@GRAD inplaced in non-inplace mode"
));
"X@GRAD and Y@GRAD inplaced in non-inplace mode"
));
}
}
PADDLE_ENFORCE_EQ
(
is_test
,
false
,
platform
::
errors
::
InvalidArgument
(
"`is_test = True` CANNOT be used in train program. If "
"you want to use global status in pre_train model, "
"please set `use_global_stats = True`"
));
// Get the size for each dimension.
// Get the size for each dimension.
// NCHW [batch_size, in_channels, in_height, in_width]
// NCHW [batch_size, in_channels, in_height, in_width]
const
auto
&
x_dims
=
x
->
dims
();
const
auto
&
x_dims
=
x
->
dims
();
...
...
paddle/fluid/operators/batch_norm_op.cu
浏览文件 @
1a417a4c
...
@@ -817,7 +817,7 @@ class BatchNormGradKernel<platform::CUDADeviceContext, T>
...
@@ -817,7 +817,7 @@ class BatchNormGradKernel<platform::CUDADeviceContext, T>
platform
::
errors
::
InvalidArgument
(
"It must use CUDAPlace."
));
platform
::
errors
::
InvalidArgument
(
"It must use CUDAPlace."
));
double
epsilon
=
static_cast
<
double
>
(
ctx
.
Attr
<
float
>
(
"epsilon"
));
double
epsilon
=
static_cast
<
double
>
(
ctx
.
Attr
<
float
>
(
"epsilon"
));
const
std
::
string
data_layout_str
=
ctx
.
Attr
<
std
::
string
>
(
"data_layout"
);
const
std
::
string
data_layout_str
=
ctx
.
Attr
<
std
::
string
>
(
"data_layout"
);
const
bool
use_global_stats
=
ctx
.
Attr
<
bool
>
(
"use_global_stats"
);
bool
use_global_stats
=
ctx
.
Attr
<
bool
>
(
"use_global_stats"
);
const
DataLayout
data_layout
=
const
DataLayout
data_layout
=
framework
::
StringToDataLayout
(
data_layout_str
);
framework
::
StringToDataLayout
(
data_layout_str
);
...
@@ -850,12 +850,7 @@ class BatchNormGradKernel<platform::CUDADeviceContext, T>
...
@@ -850,12 +850,7 @@ class BatchNormGradKernel<platform::CUDADeviceContext, T>
}
}
const
bool
is_test
=
ctx
.
Attr
<
bool
>
(
"is_test"
);
const
bool
is_test
=
ctx
.
Attr
<
bool
>
(
"is_test"
);
PADDLE_ENFORCE_EQ
(
use_global_stats
=
is_test
||
use_global_stats
;
is_test
,
false
,
platform
::
errors
::
InvalidArgument
(
"`is_test = True` CANNOT be used in train program. If "
"you want to use global status in pre_train model, "
"please set `use_global_stats = True`"
));
const
auto
&
x_dims
=
x
->
dims
();
const
auto
&
x_dims
=
x
->
dims
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录