Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
9c6a0203
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
9c6a0203
编写于
12月 27, 2018
作者:
Z
Zeng Jinle
提交者:
GitHub
12月 27, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15073 from sneaxiy/add_scope_pool
Add scope_pool
上级
656c672c
10a6bc96
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
125 addition
and
15 deletion
+125
-15
paddle/contrib/float16/float16_transpiler.py
paddle/contrib/float16/float16_transpiler.py
+1
-1
paddle/fluid/API.spec
paddle/fluid/API.spec
+1
-5
paddle/fluid/framework/CMakeLists.txt
paddle/fluid/framework/CMakeLists.txt
+1
-0
paddle/fluid/framework/scope_pool.cc
paddle/fluid/framework/scope_pool.cc
+54
-0
paddle/fluid/framework/scope_pool.h
paddle/fluid/framework/scope_pool.h
+46
-0
paddle/fluid/pybind/CMakeLists.txt
paddle/fluid/pybind/CMakeLists.txt
+1
-1
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+15
-2
python/paddle/fluid/__init__.py
python/paddle/fluid/__init__.py
+1
-1
python/paddle/fluid/executor.py
python/paddle/fluid/executor.py
+1
-1
python/paddle/fluid/tests/unittests/test_py_func_op.py
python/paddle/fluid/tests/unittests/test_py_func_op.py
+3
-3
python/paddle/fluid/transpiler/inference_transpiler.py
python/paddle/fluid/transpiler/inference_transpiler.py
+1
-1
未找到文件。
paddle/contrib/float16/float16_transpiler.py
浏览文件 @
9c6a0203
...
...
@@ -60,7 +60,7 @@ class Float16Transpiler:
raise
TypeError
(
"place should be as CPUPlace/CUDAPlace type"
)
if
scope
is
None
:
scope
=
global_scope
()
if
not
isinstance
(
scope
,
core
.
Scope
):
if
not
isinstance
(
scope
,
core
.
_
Scope
):
raise
TypeError
(
"scope should be as Scope type or None"
)
self
.
scope
=
scope
...
...
paddle/fluid/API.spec
浏览文件 @
9c6a0203
...
...
@@ -464,11 +464,7 @@ paddle.fluid.unique_name.switch ArgSpec(args=['new_generator'], varargs=None, ke
paddle.fluid.unique_name.guard ArgSpec(args=[], varargs='args', keywords='kwds', defaults=None)
paddle.fluid.recordio_writer.convert_reader_to_recordio_file ArgSpec(args=['filename', 'reader_creator', 'feeder', 'compressor', 'max_num_records', 'feed_order'], varargs=None, keywords=None, defaults=(Compressor.Snappy, 1000, None))
paddle.fluid.recordio_writer.convert_reader_to_recordio_files ArgSpec(args=['filename', 'batch_per_file', 'reader_creator', 'feeder', 'compressor', 'max_num_records', 'feed_order'], varargs=None, keywords=None, defaults=(Compressor.Snappy, 1000, None))
paddle.fluid.Scope.__init__ __init__(self: paddle.fluid.core.Scope) -> None
paddle.fluid.Scope.drop_kids drop_kids(self: paddle.fluid.core.Scope) -> None
paddle.fluid.Scope.find_var find_var(self: paddle.fluid.core.Scope, arg0: unicode) -> paddle.fluid.core.Variable
paddle.fluid.Scope.new_scope new_scope(self: paddle.fluid.core.Scope) -> paddle.fluid.core.Scope
paddle.fluid.Scope.var var(self: paddle.fluid.core.Scope, arg0: unicode) -> paddle.fluid.core.Variable
paddle.fluid.Scope Scope() -> paddle.fluid.core._Scope
paddle.reader.map_readers ArgSpec(args=['func'], varargs='readers', keywords=None, defaults=None)
paddle.reader.buffered ArgSpec(args=['reader', 'size'], varargs=None, keywords=None, defaults=None)
paddle.reader.compose ArgSpec(args=[], varargs='readers', keywords='kwargs', defaults=None)
...
...
paddle/fluid/framework/CMakeLists.txt
浏览文件 @
9c6a0203
...
...
@@ -84,6 +84,7 @@ cc_library(threadpool SRCS threadpool.cc DEPS enforce)
cc_test
(
threadpool_test SRCS threadpool_test.cc DEPS threadpool
)
cc_library
(
scope SRCS scope.cc DEPS glog threadpool
)
cc_library
(
scope_pool SRCS scope_pool.cc DEPS scope
)
cc_test
(
scope_test SRCS scope_test.cc DEPS scope
)
cc_library
(
data_device_transform SRCS data_device_transform.cc DEPS tensor
)
...
...
paddle/fluid/framework/scope_pool.cc
0 → 100644
浏览文件 @
9c6a0203
// Copyright (c) 2018 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/fluid/framework/scope_pool.h"
#include "paddle/fluid/framework/threadpool.h"
namespace
paddle
{
namespace
framework
{
ScopePool
&
ScopePool
::
Instance
()
{
// NOLINT
static
ScopePool
pool
;
return
pool
;
}
void
ScopePool
::
DeleteScope
(
Scope
*
scope
)
{
delete
scope
;
}
void
ScopePool
::
Insert
(
std
::
unique_ptr
<
Scope
>
&&
s
)
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
mtx_
);
scopes_
.
insert
(
s
.
release
());
}
void
ScopePool
::
Remove
(
Scope
*
s
)
{
size_t
has_scope
;
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
mtx_
);
has_scope
=
scopes_
.
erase
(
s
);
}
PADDLE_ENFORCE
(
has_scope
>
0
,
"Delete non-existing global scope"
);
DeleteScope
(
s
);
}
ScopePool
::~
ScopePool
()
{
Clear
();
}
void
ScopePool
::
Clear
()
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
mtx_
);
for
(
auto
*
s
:
scopes_
)
{
DeleteScope
(
s
);
}
scopes_
.
clear
();
}
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/scope_pool.h
0 → 100644
浏览文件 @
9c6a0203
// Copyright (c) 2018 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.
#pragma once
#include <mutex> // NOLINT
#include <unordered_set>
#include "paddle/fluid/framework/scope.h"
namespace
paddle
{
namespace
framework
{
class
ScopePool
{
public:
static
ScopePool
&
Instance
();
// NOLINT
void
Insert
(
std
::
unique_ptr
<
Scope
>
&&
s
);
void
Remove
(
Scope
*
s
);
void
Clear
();
~
ScopePool
();
private:
ScopePool
()
=
default
;
static
void
DeleteScope
(
Scope
*
scope
);
std
::
unordered_set
<
Scope
*>
scopes_
;
std
::
mutex
mtx_
;
};
}
// namespace framework
}
// namespace paddle
paddle/fluid/pybind/CMakeLists.txt
浏览文件 @
9c6a0203
set
(
PYBIND_DEPS pybind python proto_desc memory executor async_executor prune feed_fetch_method pass_builder parallel_executor profiler layer
)
set
(
PYBIND_DEPS pybind python proto_desc memory executor async_executor prune feed_fetch_method pass_builder parallel_executor profiler layer
scope_pool
)
if
(
WITH_PYTHON
)
list
(
APPEND PYBIND_DEPS py_func_op
)
endif
()
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
9c6a0203
...
...
@@ -32,6 +32,7 @@ limitations under the License. */
#include "paddle/fluid/framework/parallel_executor.h"
#include "paddle/fluid/framework/prune.h"
#include "paddle/fluid/framework/reader.h"
#include "paddle/fluid/framework/scope_pool.h"
#include "paddle/fluid/framework/selected_rows.h"
#include "paddle/fluid/framework/version.h"
#include "paddle/fluid/imperative/layer.h"
...
...
@@ -117,6 +118,9 @@ PYBIND11_MODULE(core, m) {
return
paddle
::
operators
::
AppendPythonCallableObjectAndReturnId
(
py_obj
);
});
m
.
add_object
(
"_cleanup"
,
py
::
capsule
([]()
{
ScopePool
::
Instance
().
Clear
();
}));
py
::
class_
<
imperative
::
VarBase
,
PyVarBase
>
(
m
,
"VarBase"
,
R"DOC()DOC"
)
.
def
(
py
::
init
<>
())
.
def
(
"_run_backward"
,
...
...
@@ -454,7 +458,7 @@ All parameter, weight, gradient are variables in Paddle.
},
py
::
return_value_policy
::
copy
);
py
::
class_
<
Scope
>
(
m
,
"Scope"
,
R"DOC(
py
::
class_
<
Scope
>
(
m
,
"
_
Scope"
,
R"DOC(
Scope is an association of a name to Variable. All variables belong to Scope.
Variables in a parent scope can be retrieved from local scope.
...
...
@@ -474,17 +478,26 @@ All parameter, weight, gradient are variables in Paddle.
param.set(param_array, place)
)DOC"
)
.
def
(
"_remove_from_pool"
,
[](
Scope
&
self
)
{
ScopePool
::
Instance
().
Remove
(
&
self
);
})
.
def
(
"var"
,
[](
Scope
&
self
,
const
std
::
string
&
name
)
->
Variable
*
{
return
self
.
Var
(
name
);
},
py
::
return_value_policy
::
reference
)
.
def
(
"find_var"
,
&
Scope
::
FindVar
,
py
::
return_value_policy
::
reference
)
.
def
(
py
::
init
<>
())
.
def
(
"new_scope"
,
[](
Scope
&
self
)
->
Scope
*
{
return
&
self
.
NewScope
();
},
py
::
return_value_policy
::
reference
)
.
def
(
"drop_kids"
,
&
Scope
::
DropKids
);
m
.
def
(
"Scope"
,
[]()
->
Scope
*
{
auto
*
s
=
new
Scope
();
ScopePool
::
Instance
().
Insert
(
std
::
unique_ptr
<
Scope
>
(
s
));
return
s
;
},
py
::
return_value_policy
::
reference
);
//! @note: Be careful! PyBind will return std::string as an unicode, not
//! Python str. If you want a str object, you should cast them in Python.
m
.
def
(
"get_all_op_protos"
,
[]()
->
std
::
vector
<
py
::
bytes
>
{
...
...
python/paddle/fluid/__init__.py
浏览文件 @
9c6a0203
...
...
@@ -46,7 +46,7 @@ from . import transpiler
from
.
import
distribute_lookup_table
from
.param_attr
import
ParamAttr
,
WeightNormParamAttr
from
.data_feeder
import
DataFeeder
from
.core
import
LoDTensor
,
LoDTensorArray
,
CPUPlace
,
CUDAPlace
,
CUDAPinnedPlace
,
Scope
from
.core
import
LoDTensor
,
LoDTensorArray
,
CPUPlace
,
CUDAPlace
,
CUDAPinnedPlace
,
Scope
,
_Scope
from
.transpiler
import
DistributeTranspiler
,
\
memory_optimize
,
release_memory
,
DistributeTranspilerConfig
from
.lod_tensor
import
create_lod_tensor
,
create_random_int_lodtensor
...
...
python/paddle/fluid/executor.py
浏览文件 @
9c6a0203
...
...
@@ -191,7 +191,7 @@ def _fetch_var(name, scope=None, return_numpy=True):
assert
isinstance
(
name
,
str
)
if
scope
is
None
:
scope
=
global_scope
()
assert
isinstance
(
scope
,
core
.
Scope
)
assert
isinstance
(
scope
,
core
.
_
Scope
)
var
=
scope
.
find_var
(
name
)
assert
var
is
not
None
,
(
...
...
python/paddle/fluid/tests/unittests/test_py_func_op.py
浏览文件 @
9c6a0203
...
...
@@ -26,7 +26,7 @@ os.environ['CPU_NUM'] = str(dev_cnt)
def
dummy_func_with_no_input
():
return
float
(
1.0
)
return
np
.
array
([
0
],
dtype
=
'float32'
)
def
dummy_func_with_no_output
(
x
):
...
...
@@ -105,7 +105,7 @@ def simple_fc_net(img, label, use_py_func_op):
name
=
'test_tmp_var'
,
dtype
=
'float32'
,
shape
=
[
1
])
fluid
.
layers
.
py_func
(
func
=
dummy_func_with_no_input
,
x
=
None
,
out
=
dummy_var
)
loss
+=
dummy_var
fluid
.
layers
.
py_func
(
func
=
dummy_func_with_no_output
,
x
=
loss
,
out
=
None
)
loss
=
fluid
.
layers
.
mean
(
loss
)
...
...
@@ -174,7 +174,7 @@ class TestPyFuncOpUseExecutor(unittest.TestCase):
self
.
assertAlmostEqual
(
max_diff
,
0
,
delta
=
1e-3
)
class
TestPyFuncOpUseParallelExecutor
(
unittest
.
TestCase
):
class
TestPyFuncOpUseParallelExecutor
(
TestPyFuncOpUseExecutor
):
def
setUp
(
self
):
self
.
use_parallel_executor
=
True
...
...
python/paddle/fluid/transpiler/inference_transpiler.py
浏览文件 @
9c6a0203
...
...
@@ -57,7 +57,7 @@ class InferenceTranspiler(object):
raise
TypeError
(
"place should be as CPUPlace/CUDAPlace type"
)
if
scope
is
None
:
scope
=
global_scope
()
if
not
isinstance
(
scope
,
core
.
Scope
):
if
not
isinstance
(
scope
,
core
.
_
Scope
):
raise
TypeError
(
"scope should be as Scope type or None"
)
use_mkldnn
=
bool
(
os
.
getenv
(
"FLAGS_use_mkldnn"
,
False
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录