Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
a21f4e38
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a21f4e38
编写于
1月 21, 2019
作者:
M
minqiyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish code
test=develop
上级
8ce198b2
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
10 addition
and
31 deletion
+10
-31
paddle/fluid/imperative/layer.cc
paddle/fluid/imperative/layer.cc
+0
-10
paddle/fluid/imperative/tracer.cc
paddle/fluid/imperative/tracer.cc
+0
-4
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+0
-1
python/paddle/fluid/imperative/nn.py
python/paddle/fluid/imperative/nn.py
+5
-3
python/paddle/fluid/layer_helper.py
python/paddle/fluid/layer_helper.py
+5
-7
python/paddle/fluid/tests/unittests/test_imperative_resnet.py
...on/paddle/fluid/tests/unittests/test_imperative_resnet.py
+0
-6
未找到文件。
paddle/fluid/imperative/layer.cc
浏览文件 @
a21f4e38
...
@@ -199,13 +199,6 @@ framework::LoDTensor& VarBase::GradValue() {
...
@@ -199,13 +199,6 @@ framework::LoDTensor& VarBase::GradValue() {
}
}
std
::
map
<
std
::
string
,
std
::
vector
<
VarBase
*>>
OpBase
::
ApplyGrad
()
{
std
::
map
<
std
::
string
,
std
::
vector
<
VarBase
*>>
OpBase
::
ApplyGrad
()
{
VLOG
(
3
)
<<
"ApplyGrad to Op: "
<<
op_desc_
->
Type
();
for
(
auto
it
:
input_vars_
)
{
for
(
VarBase
*
var
:
it
.
second
)
{
VLOG
(
3
)
<<
"Op Input: "
<<
it
.
first
<<
" : "
<<
var
->
var_desc_
->
Name
();
}
}
if
(
!
grad_op_desc_
&&
backward_id_
<=
0
)
{
if
(
!
grad_op_desc_
&&
backward_id_
<=
0
)
{
LOG
(
WARNING
)
<<
"op with no grad: "
<<
op_desc_
->
Type
();
LOG
(
WARNING
)
<<
"op with no grad: "
<<
op_desc_
->
Type
();
return
{};
return
{};
...
@@ -256,9 +249,6 @@ std::map<std::string, std::vector<VarBase*>> OpBase::ApplyGrad() {
...
@@ -256,9 +249,6 @@ std::map<std::string, std::vector<VarBase*>> OpBase::ApplyGrad() {
for
(
size_t
i
=
0
;
i
<
outputs
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
outputs
.
size
();
++
i
)
{
framework
::
Variable
*
grad
=
outputs
[
i
];
framework
::
Variable
*
grad
=
outputs
[
i
];
framework
::
Variable
*
orig_grad
=
origin_outputs
[
i
];
framework
::
Variable
*
orig_grad
=
origin_outputs
[
i
];
LOG
(
ERROR
)
<<
"Add grad of "
<<
it
.
first
<<
" "
<<
i
<<
" "
<<
orig_grad
->
GetMutable
<
framework
::
LoDTensor
>
()
->
mutable_data
(
expected_place_
);
AddGradTo
(
grad
,
orig_grad
,
expected_place_
);
AddGradTo
(
grad
,
orig_grad
,
expected_place_
);
delete
grad
;
delete
grad
;
}
}
...
...
paddle/fluid/imperative/tracer.cc
浏览文件 @
a21f4e38
...
@@ -159,7 +159,6 @@ void Tracer::Trace(OpBase* op, const VarBasePtrMap& inputs,
...
@@ -159,7 +159,6 @@ void Tracer::Trace(OpBase* op, const VarBasePtrMap& inputs,
}
else
{
}
else
{
VarBase
*
var
=
vars
[
var_it
->
second
];
VarBase
*
var
=
vars
[
var_it
->
second
];
if
(
!
var
->
grads_
->
var_
->
IsInitialized
())
{
if
(
!
var
->
grads_
->
var_
->
IsInitialized
())
{
LOG
(
ERROR
)
<<
"Init grad input "
<<
it
.
first
<<
" "
<<
grad_invar
;
InitVar
(
var
->
var_
,
var
->
grads_
->
var_
,
InitVar
(
var
->
var_
,
var
->
grads_
->
var_
,
prepared_op
.
GetDeviceContext
());
prepared_op
.
GetDeviceContext
());
}
}
...
@@ -181,9 +180,6 @@ void Tracer::Trace(OpBase* op, const VarBasePtrMap& inputs,
...
@@ -181,9 +180,6 @@ void Tracer::Trace(OpBase* op, const VarBasePtrMap& inputs,
VarBase
*
var
=
vars
[
var_it
->
second
];
VarBase
*
var
=
vars
[
var_it
->
second
];
if
(
!
var
->
grads_
->
var_
->
IsInitialized
())
{
if
(
!
var
->
grads_
->
var_
->
IsInitialized
())
{
InitVar
(
var
->
var_
,
var
->
grads_
->
var_
,
prepared_op
.
GetDeviceContext
());
InitVar
(
var
->
var_
,
var
->
grads_
->
var_
,
prepared_op
.
GetDeviceContext
());
LOG
(
ERROR
)
<<
"Init grad output "
<<
it
.
first
<<
" "
<<
grad_outvar
<<
var
->
grads_
->
var_
->
GetMutable
<
framework
::
LoDTensor
>
()
->
mutable_data
(
platform
::
CPUPlace
());
}
}
grad_out_vars
.
push_back
(
var
->
grads_
->
var_
);
grad_out_vars
.
push_back
(
var
->
grads_
->
var_
);
}
}
...
...
python/paddle/fluid/framework.py
浏览文件 @
a21f4e38
...
@@ -386,7 +386,6 @@ class Variable(object):
...
@@ -386,7 +386,6 @@ class Variable(object):
def
_numpy
(
self
):
def
_numpy
(
self
):
tensor
=
self
.
_ivar
.
_cpu_tensor
()
tensor
=
self
.
_ivar
.
_cpu_tensor
()
print
(
'shapex'
,
self
.
name
,
tensor
.
shape
())
return
np
.
array
(
tensor
)
return
np
.
array
(
tensor
)
def
_backward
(
self
):
def
_backward
(
self
):
...
...
python/paddle/fluid/imperative/nn.py
浏览文件 @
a21f4e38
...
@@ -144,7 +144,7 @@ class Conv2D(layers.Layer):
...
@@ -144,7 +144,7 @@ class Conv2D(layers.Layer):
attrs
=
{
'axis'
:
1
})
attrs
=
{
'axis'
:
1
})
# Currently, we don't support inplace in imperative mode
# Currently, we don't support inplace in imperative mode
return
self
.
_helper
.
append_activation
(
pre_act
)
return
self
.
_helper
.
append_activation
(
pre_act
,
force_no_inplace
=
True
)
class
Pool2D
(
layers
.
Layer
):
class
Pool2D
(
layers
.
Layer
):
...
@@ -286,7 +286,8 @@ class FC(layers.Layer):
...
@@ -286,7 +286,8 @@ class FC(layers.Layer):
else
:
else
:
pre_activation
=
pre_bias
pre_activation
=
pre_bias
# Currently, we don't support inplace in imperative mode
# Currently, we don't support inplace in imperative mode
return
self
.
_helper
.
append_activation
(
pre_activation
)
return
self
.
_helper
.
append_activation
(
pre_activation
,
force_no_inplace
=
True
)
class
BatchNorm
(
layers
.
Layer
):
class
BatchNorm
(
layers
.
Layer
):
...
@@ -418,4 +419,5 @@ class BatchNorm(layers.Layer):
...
@@ -418,4 +419,5 @@ class BatchNorm(layers.Layer):
})
})
# Currently, we don't support inplace in imperative mode
# Currently, we don't support inplace in imperative mode
return
self
.
_helper
.
append_activation
(
batch_norm_out
)
return
self
.
_helper
.
append_activation
(
batch_norm_out
,
force_no_inplace
=
True
)
python/paddle/fluid/layer_helper.py
浏览文件 @
a21f4e38
...
@@ -419,7 +419,7 @@ class LayerHelper(object):
...
@@ -419,7 +419,7 @@ class LayerHelper(object):
attrs
=
{
'axis'
:
dim_start
})
attrs
=
{
'axis'
:
dim_start
})
return
tmp
return
tmp
def
append_activation
(
self
,
input_var
):
def
append_activation
(
self
,
input_var
,
force_no_inplace
=
False
):
act
=
self
.
kwargs
.
get
(
'act'
,
None
)
act
=
self
.
kwargs
.
get
(
'act'
,
None
)
if
act
is
None
:
if
act
is
None
:
return
input_var
return
input_var
...
@@ -436,11 +436,9 @@ class LayerHelper(object):
...
@@ -436,11 +436,9 @@ class LayerHelper(object):
tmp
=
input_var
tmp
=
input_var
# NOTE(dzhwinter): some activation support inplace compution.
# NOTE(dzhwinter): some activation support inplace compution.
# NOTE(minqiyang): currently, we don't support inplace in imperative mode
# NOTE(minqiyang): currently, we don't support inplace in imperative mode
# if core.IsInplace(act_type) and no_inplace:
if
not
force_no_inplace
and
core
.
IsInplace
(
act_type
):
# print("inplace", act_type)
tmp
=
input_var
# tmp = input_var
else
:
# else:
print
(
"not inplace"
,
act_type
)
tmp
=
self
.
create_variable_for_type_inference
(
dtype
=
input_var
.
dtype
)
tmp
=
self
.
create_variable_for_type_inference
(
dtype
=
input_var
.
dtype
)
self
.
append_op
(
self
.
append_op
(
type
=
act_type
,
type
=
act_type
,
...
...
python/paddle/fluid/tests/unittests/test_imperative_resnet.py
浏览文件 @
a21f4e38
...
@@ -228,7 +228,6 @@ class TestImperativeResnet(unittest.TestCase):
...
@@ -228,7 +228,6 @@ class TestImperativeResnet(unittest.TestCase):
dy_x_data
=
np
.
array
(
dy_x_data
=
np
.
array
(
[
x
[
0
].
reshape
(
3
,
224
,
224
)
for
x
in
data
]).
astype
(
'float32'
)
[
x
[
0
].
reshape
(
3
,
224
,
224
)
for
x
in
data
]).
astype
(
'float32'
)
print
(
'dy input shape'
,
dy_x_data
.
shape
)
y_data
=
np
.
array
([
x
[
1
]
for
x
in
data
]).
astype
(
'int64'
).
reshape
(
y_data
=
np
.
array
([
x
[
1
]
for
x
in
data
]).
astype
(
'int64'
).
reshape
(
batch_size
,
1
)
batch_size
,
1
)
...
@@ -240,8 +239,6 @@ class TestImperativeResnet(unittest.TestCase):
...
@@ -240,8 +239,6 @@ class TestImperativeResnet(unittest.TestCase):
loss
=
fluid
.
layers
.
cross_entropy
(
input
=
out
,
label
=
label
)
loss
=
fluid
.
layers
.
cross_entropy
(
input
=
out
,
label
=
label
)
avg_loss
=
fluid
.
layers
.
mean
(
x
=
loss
)
avg_loss
=
fluid
.
layers
.
mean
(
x
=
loss
)
print
(
'shapex '
,
avg_loss
.
shape
)
dy_out
=
avg_loss
.
_numpy
()
dy_out
=
avg_loss
.
_numpy
()
if
batch_id
==
0
:
if
batch_id
==
0
:
...
@@ -291,9 +288,6 @@ class TestImperativeResnet(unittest.TestCase):
...
@@ -291,9 +288,6 @@ class TestImperativeResnet(unittest.TestCase):
avg_loss
=
fluid
.
layers
.
mean
(
x
=
loss
)
avg_loss
=
fluid
.
layers
.
mean
(
x
=
loss
)
optimizer
.
minimize
(
avg_loss
)
optimizer
.
minimize
(
avg_loss
)
print
(
'avg_loss shape'
,
avg_loss
.
shape
)
print
(
fluid
.
default_main_program
())
# initialize params and fetch them
# initialize params and fetch them
static_param_init_value
=
{}
static_param_init_value
=
{}
static_param_name_list
=
[]
static_param_name_list
=
[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录