Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
61491ce2
P
Paddle
项目概览
机器未来
/
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看板
提交
61491ce2
编写于
12月 26, 2018
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean
test=develop
上级
ce7e503c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
24 addition
and
71 deletion
+24
-71
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+7
-7
paddle/fluid/framework/operator.h
paddle/fluid/framework/operator.h
+6
-4
paddle/fluid/imperative/layer.cc
paddle/fluid/imperative/layer.cc
+5
-27
paddle/fluid/imperative/tracer.h
paddle/fluid/imperative/tracer.h
+3
-26
paddle/fluid/operators/fill_constant_op.cc
paddle/fluid/operators/fill_constant_op.cc
+2
-2
paddle/fluid/pybind/imperative.cc
paddle/fluid/pybind/imperative.cc
+1
-3
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+0
-2
未找到文件。
paddle/fluid/framework/operator.cc
浏览文件 @
61491ce2
...
...
@@ -182,7 +182,7 @@ void OperatorBase::Run(const Scope& scope, const platform::Place& place) {
void
OperatorBase
::
Run
(
const
RuntimeContext
&
ctx
,
const
platform
::
Place
&
place
)
{
RunImpl
(
ctx
,
place
);
RunImpl
Prepared
(
ctx
,
place
);
}
bool
OperatorBase
::
HasInputs
(
const
std
::
string
&
name
)
const
{
...
...
@@ -959,9 +959,9 @@ void OperatorWithKernel::RunImpl(const Scope& scope,
}
}
void
OperatorWithKernel
::
RunImpl
(
const
RuntimeContext
&
ctx
,
const
platform
::
Place
&
place
)
const
{
Scope
scope
;
void
OperatorWithKernel
::
RunImpl
Prepared
(
const
RuntimeContext
&
ctx
,
const
platform
::
Place
&
place
)
const
{
Scope
dummy_
scope
;
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
auto
*
dev_ctx
=
pool
.
Get
(
place
);
...
...
@@ -976,7 +976,7 @@ void OperatorWithKernel::RunImpl(const RuntimeContext& ctx,
OpKernelMap
&
kernels
=
kernels_iter
->
second
;
auto
expected_kernel_key
=
this
->
GetExpectedKernelType
(
ExecutionContext
(
*
this
,
scope
,
*
dev_ctx
,
ctx
));
ExecutionContext
(
*
this
,
dummy_
scope
,
*
dev_ctx
,
ctx
));
VLOG
(
3
)
<<
"expected_kernel_key:"
<<
expected_kernel_key
;
auto
kernel_iter
=
kernels
.
find
(
expected_kernel_key
);
...
...
@@ -999,9 +999,9 @@ void OperatorWithKernel::RunImpl(const RuntimeContext& ctx,
dev_ctx
=
pool
.
Get
(
expected_kernel_key
.
place_
);
}
RuntimeInferShapeContext
infer_shape_ctx
(
*
this
,
scope
,
ctx
);
RuntimeInferShapeContext
infer_shape_ctx
(
*
this
,
dummy_
scope
,
ctx
);
this
->
InferShape
(
&
infer_shape_ctx
);
kernel_iter
->
second
(
ExecutionContext
(
*
this
,
scope
,
*
dev_ctx
,
ctx
));
kernel_iter
->
second
(
ExecutionContext
(
*
this
,
dummy_
scope
,
*
dev_ctx
,
ctx
));
}
void
OperatorWithKernel
::
TransferInplaceVarsBack
(
...
...
paddle/fluid/framework/operator.h
浏览文件 @
61491ce2
...
...
@@ -173,8 +173,10 @@ class OperatorBase {
virtual
void
RunImpl
(
const
Scope
&
scope
,
const
platform
::
Place
&
place
)
const
=
0
;
virtual
void
RunImpl
(
const
RuntimeContext
&
ctx
,
const
platform
::
Place
&
place
)
const
{}
virtual
void
RunImplPrepared
(
const
RuntimeContext
&
ctx
,
const
platform
::
Place
&
place
)
const
{
PADDLE_THROW
(
"%s doesn't support RunPreparedImpl"
,
Type
());
}
};
class
ExecutionContext
{
...
...
@@ -466,8 +468,8 @@ class OperatorWithKernel : public OperatorBase {
// same.
proto
::
VarType
::
Type
IndicateDataType
(
const
ExecutionContext
&
ctx
)
const
;
void
RunImpl
(
const
Scope
&
scope
,
const
platform
::
Place
&
place
)
const
final
;
void
RunImpl
(
const
RuntimeContext
&
ctx
,
const
platform
::
Place
&
place
)
const
final
;
void
RunImpl
Prepared
(
const
RuntimeContext
&
ctx
,
const
platform
::
Place
&
place
)
const
final
;
/**
* Transfer data from scope to a transfered scope. If there is no data need to
...
...
paddle/fluid/imperative/layer.cc
浏览文件 @
61491ce2
...
...
@@ -31,11 +31,6 @@ using framework::Variable;
void
AddTo
(
Variable
*
src
,
Variable
*
dst
)
{
framework
::
LoDTensor
*
dst_tensor
=
dst
->
GetMutable
<
framework
::
LoDTensor
>
();
framework
::
LoDTensor
*
src_tensor
=
src
->
GetMutable
<
framework
::
LoDTensor
>
();
VLOG
(
3
)
<<
"apply var grad "
<<
src_tensor
->
data
<
float
>
()[
0
]
<<
" "
<<
src_tensor
->
data
<
float
>
()[
1
]
<<
" "
<<
src_tensor
->
data
<
float
>
()[
2
];
PADDLE_ENFORCE
(
dst_tensor
->
numel
()
==
src_tensor
->
numel
(),
"%lld vs %lld"
,
dst_tensor
->
numel
(),
src_tensor
->
numel
());
float
*
dst_data
=
dst_tensor
->
mutable_data
<
float
>
(
platform
::
CPUPlace
());
...
...
@@ -43,10 +38,6 @@ void AddTo(Variable* src, Variable* dst) {
for
(
size_t
i
=
0
;
i
<
src_tensor
->
numel
();
++
i
)
{
dst_data
[
i
]
+=
src_data
[
i
];
}
VLOG
(
3
)
<<
"apply var dst grad "
<<
dst_tensor
->
data
<
float
>
()[
0
]
<<
" "
<<
dst_tensor
->
data
<
float
>
()[
1
]
<<
" "
<<
dst_tensor
->
data
<
float
>
()[
2
];
}
class
Autograd
{
...
...
@@ -55,16 +46,10 @@ class Autograd {
void
RunBackward
(
VarBase
*
var
)
{
PADDLE_ENFORCE
(
var
->
pre_op_
->
op_desc_
);
// TODO(panyx0718): Only create for vars that "require_grad"
LOG
(
ERROR
)
<<
reinterpret_cast
<
void
*>
(
var
->
grads_
)
<<
" vs "
<<
reinterpret_cast
<
void
*>
(
var
->
pre_op_
->
output_vars_
[
var
->
pre_op_out_name_
]
[
var
->
pre_op_out_idx_
]
->
grads_
);
var
->
pre_op_
->
output_vars_
[
var
->
pre_op_out_name_
][
var
->
pre_op_out_idx_
]
->
grads_
->
GetMutable
<
framework
::
LoDTensor
>
()
->
ShareDataWith
(
var
->
grads_
->
Get
<
framework
::
LoDTensor
>
());
PADDLE_ENFORCE
(
var
->
grads_
==
var
->
pre_op_
->
output_vars_
[
var
->
pre_op_out_name_
][
var
->
pre_op_out_idx_
]
->
grads_
);
std
::
deque
<
OpBase
*>
ready
;
ready
.
push_back
(
var
->
pre_op_
);
...
...
@@ -76,7 +61,6 @@ class Autograd {
ready
.
pop_front
();
std
::
map
<
std
::
string
,
std
::
vector
<
VarBase
*>>
input_grads
=
ready_op
->
ApplyGrad
();
VLOG
(
3
)
<<
"after apply grad"
;
for
(
auto
it
:
input_grads
)
{
const
std
::
vector
<
VarBase
*>&
ingrads
=
it
.
second
;
...
...
@@ -160,17 +144,12 @@ std::map<std::string, std::vector<VarBase*>> OpBase::ApplyGrad() {
for
(
size_t
i
=
0
;
i
<
it
.
second
.
size
();
++
i
)
{
outputs
.
push_back
(
new
framework
::
Variable
());
outputs
.
back
()
->
GetMutable
<
framework
::
LoDTensor
>
();
/*
auto& accum_grad_t = it.second[i]->Get<framework::LoDTensor>();
Variable* grad_var = outputs.back();
float* data = grad_var->GetMutable<framework::LoDTensor>()
->mutable_data<float>(accum_grad_t.dims(), platform::CPUPlace());
std::fill(data, data + accum_grad_t.numel(), 0.0);*/
}
}
framework
::
RuntimeContext
ctx
(
grad_input_vars_
,
grad_outputs
);
// No need to do static infer shape here.
// grad_op_desc_->InferShape(*block_);
grad_op_desc_
->
InferVarType
(
block_
);
...
...
@@ -184,7 +163,6 @@ std::map<std::string, std::vector<VarBase*>> OpBase::ApplyGrad() {
for
(
size_t
i
=
0
;
i
<
outputs
.
size
();
++
i
)
{
framework
::
Variable
*
orig_grad
=
origin_outputs
[
i
];
AddTo
(
outputs
[
i
],
orig_grad
);
VLOG
(
3
)
<<
"done add to "
<<
grad_op_desc_
->
Outputs
().
at
(
it
.
first
)[
i
];
}
}
return
input_vars_
;
...
...
paddle/fluid/imperative/tracer.h
浏览文件 @
61491ce2
...
...
@@ -20,7 +20,6 @@
#include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/imperative/engine.h"
#include "paddle/fluid/imperative/layer.h"
...
...
@@ -53,19 +52,14 @@ class Tracer {
public:
explicit
Tracer
(
framework
::
BlockDesc
*
root_block
,
framework
::
BlockDesc
*
startup_block
)
:
root_block_
(
root_block
),
startup_block_
(
startup_block
)
{
root_scope_
=
new
framework
::
Scope
();
scopes_
[
root_block_
]
=
root_scope_
;
scopes_
[
startup_block_
]
=
root_scope_
;
}
:
root_block_
(
root_block
),
startup_block_
(
startup_block
)
{}
virtual
~
Tracer
()
{
delete
root_scope_
;
}
virtual
~
Tracer
()
{}
void
Trace
(
OpBase
*
op
,
const
std
::
map
<
std
::
string
,
std
::
vector
<
VarBase
*>>&
inputs
,
const
std
::
map
<
std
::
string
,
std
::
vector
<
VarBase
*>>&
outputs
,
framework
::
BlockDesc
*
block
)
{
// framework::Scope* scope = GetScope(block);
std
::
map
<
std
::
string
,
VarBase
*>
vars
;
framework
::
OpDesc
*
op_desc
=
op
->
op_desc_
;
...
...
@@ -94,8 +88,7 @@ class Tracer {
(
*
op
->
pre_ops_
)[
it
.
first
].
push_back
(
nullptr
);
}
VLOG
(
3
)
<<
"input vname "
<<
inp
->
var_desc_
->
Name
()
<<
" "
<<
inp
->
var_
->
Get
<
framework
::
LoDTensor
>
().
dims
().
size
()
<<
reinterpret_cast
<
void
*>
(
inp
->
var_
);
<<
inp
->
var_
->
IsInitialized
();
}
}
...
...
@@ -119,8 +112,6 @@ class Tracer {
out
->
pre_op_out_idx_
=
i
;
VLOG
(
3
)
<<
"output vname "
<<
out
->
var_desc_
->
Name
()
<<
" "
<<
out
->
var_
->
Get
<
framework
::
LoDTensor
>
().
dims
().
size
()
<<
" "
<<
reinterpret_cast
<
void
*>
(
out
->
var_
)
<<
" "
<<
out
->
var_
->
IsInitialized
();
}
}
...
...
@@ -167,7 +158,6 @@ class Tracer {
if
(
!
var
->
grads_
->
IsInitialized
())
{
InitVar
(
var
->
var_
,
var
->
grads_
);
}
LOG
(
ERROR
)
<<
grad_outvar
<<
" map to "
<<
var
->
var_desc_
->
Name
();
grad_out_vars
.
push_back
(
var
->
grads_
);
}
}
...
...
@@ -175,22 +165,9 @@ class Tracer {
op
->
block_
=
block
;
}
framework
::
Scope
*
GetScope
(
framework
::
BlockDesc
*
block
)
{
if
(
scopes_
.
find
(
block
)
!=
scopes_
.
end
())
{
return
scopes_
.
at
(
block
);
}
framework
::
BlockDesc
*
parent_block
=
block
->
ParentBlock
();
PADDLE_ENFORCE
(
scopes_
.
find
(
parent_block
)
!=
scopes_
.
end
());
framework
::
Scope
*
scope
=
&
scopes_
[
parent_block
]
->
NewScope
();
scopes_
[
block
]
=
scope
;
return
scope
;
}
private:
std
::
map
<
framework
::
BlockDesc
*
,
framework
::
Scope
*>
scopes_
;
framework
::
BlockDesc
*
root_block_
;
framework
::
BlockDesc
*
startup_block_
;
framework
::
Scope
*
root_scope_
;
};
}
// namespace imperative
...
...
paddle/fluid/operators/fill_constant_op.cc
浏览文件 @
61491ce2
...
...
@@ -69,8 +69,8 @@ class FillConstantOp : public framework::OperatorBase {
math
::
set_constant
(
dev_ctx
,
tensor
,
value
);
}
void
RunImpl
(
const
framework
::
RuntimeContext
&
ctx
,
const
platform
::
Place
&
dev_place
)
const
override
{
void
RunImpl
Prepared
(
const
framework
::
RuntimeContext
&
ctx
,
const
platform
::
Place
&
dev_place
)
const
override
{
auto
data_type
=
static_cast
<
framework
::
proto
::
VarType
::
Type
>
(
Attr
<
int
>
(
"dtype"
));
auto
value
=
Attr
<
float
>
(
"value"
);
...
...
paddle/fluid/pybind/imperative.cc
浏览文件 @
61491ce2
...
...
@@ -28,9 +28,7 @@ void BindTracer(pybind11::module *m) {
framework
::
BlockDesc
*
startup_block
)
{
new
(
&
self
)
imperative
::
Tracer
(
root_block
,
startup_block
);
})
.
def
(
"trace"
,
&
imperative
::
Tracer
::
Trace
)
.
def
(
"get_scope"
,
&
imperative
::
Tracer
::
GetScope
,
pybind11
::
return_value_policy
::
reference
);
.
def
(
"trace"
,
&
imperative
::
Tracer
::
Trace
);
}
}
// namespace pybind
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
61491ce2
...
...
@@ -20,7 +20,6 @@ from __future__ import print_function
import
numpy
as
np
import
six
import
os
import
sys
import
inspect
from
..layer_helper
import
LayerHelper
from
..initializer
import
Normal
,
Constant
...
...
@@ -9683,7 +9682,6 @@ class FC(layers.PyLayer):
shape
=
param_shape
,
dtype
=
self
.
_dtype
,
is_bias
=
False
)
sys
.
stderr
.
write
(
'created w: %s
\n
'
%
self
.
_w
.
name
)
def
forward
(
self
,
inputs
):
tmp
=
self
.
_helper
.
create_variable_for_type_inference
(
self
.
_dtype
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录