Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8674a82c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
8674a82c
编写于
4月 08, 2020
作者:
A
Aurelius84
提交者:
GitHub
4月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Op (Scope) error message enhancement (#23458)
* Op (Scope) error message enhancement test=develop
上级
cdc6d4e2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
7 deletion
+29
-7
paddle/fluid/framework/scope.cc
paddle/fluid/framework/scope.cc
+12
-6
paddle/fluid/framework/scope_pool.cc
paddle/fluid/framework/scope_pool.cc
+6
-1
python/paddle/fluid/tests/unittests/test_scope.py
python/paddle/fluid/tests/unittests/test_scope.py
+11
-0
未找到文件。
paddle/fluid/framework/scope.cc
浏览文件 @
8674a82c
...
...
@@ -125,8 +125,9 @@ std::vector<std::string> Scope::LocalVarNames() const {
void
Scope
::
DeleteScope
(
Scope
*
scope
)
const
{
SCOPE_KIDS_WRITER_LOCK
auto
it
=
std
::
find
(
this
->
kids_
.
begin
(),
this
->
kids_
.
end
(),
scope
);
PADDLE_ENFORCE
(
it
!=
this
->
kids_
.
end
(),
"%p Cannot find %p as kid scope"
,
this
,
scope
);
PADDLE_ENFORCE_NE
(
it
,
this
->
kids_
.
end
(),
platform
::
errors
::
NotFound
(
"%p is not found in %p as kid scope"
,
scope
,
this
));
this
->
kids_
.
erase
(
it
);
// When making memory benchmark on Fluid, we have to delete scope sync.
if
(
FLAGS_benchmark
||
FLAGS_eager_delete_scope
)
{
...
...
@@ -189,11 +190,16 @@ const Scope* Scope::FindScopeInternal(const std::string& name) const {
void
Scope
::
RenameInternal
(
const
std
::
string
&
origin_name
,
const
std
::
string
&
new_name
)
const
{
auto
origin_it
=
vars_
.
find
(
origin_name
);
PADDLE_ENFORCE
(
origin_it
!=
vars_
.
end
(),
"Cannot find original variable with name %s"
,
origin_name
);
PADDLE_ENFORCE_NE
(
origin_it
,
vars_
.
end
(),
platform
::
errors
::
NotFound
(
"Original variable with name %s is not found in the scope."
,
origin_name
));
auto
new_it
=
vars_
.
find
(
new_name
);
PADDLE_ENFORCE
(
new_it
==
vars_
.
end
(),
"The variable with name %s is already in the scope"
,
new_name
);
PADDLE_ENFORCE_EQ
(
new_it
,
vars_
.
end
(),
platform
::
errors
::
AlreadyExists
(
"The variable with name %s already exists in the scope."
,
new_name
));
vars_
[
new_name
].
reset
(
origin_it
->
second
.
release
());
vars_
.
erase
(
origin_it
);
}
...
...
paddle/fluid/framework/scope_pool.cc
浏览文件 @
8674a82c
...
...
@@ -11,6 +11,7 @@
// 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 <memory>
#include "paddle/fluid/framework/scope_pool.h"
#include "paddle/fluid/framework/threadpool.h"
...
...
@@ -36,7 +37,11 @@ void ScopePool::Remove(Scope *s) {
std
::
lock_guard
<
std
::
mutex
>
guard
(
mtx_
);
has_scope
=
scopes_
.
erase
(
s
);
}
PADDLE_ENFORCE
(
has_scope
>
0
,
"Delete non-existing global scope"
);
PADDLE_ENFORCE_GT
(
has_scope
,
0
,
platform
::
errors
::
NotFound
(
"Global scope %p is not found in ScopePool. "
"Deleting a nonexistent scope is not allowed."
,
s
));
DeleteScope
(
s
);
}
...
...
python/paddle/fluid/tests/unittests/test_scope.py
浏览文件 @
8674a82c
...
...
@@ -16,6 +16,7 @@ from __future__ import print_function
import
paddle.fluid.core
import
unittest
import
six
class
TestScope
(
unittest
.
TestCase
):
...
...
@@ -48,6 +49,16 @@ class TestScope(unittest.TestCase):
self
.
assertTrue
(
var
.
is_int
())
self
.
assertEqual
(
10
,
var
.
get_int
())
def
test_scope_pool
(
self
):
paddle_c
=
paddle
.
fluid
.
core
scope
=
paddle_c
.
Scope
()
# Delete the scope.
scope
.
_remove_from_pool
()
with
self
.
assertRaisesRegexp
(
Exception
,
"Deleting a nonexistent scope is not allowed*"
):
# It is not allowed to delete a nonexistent scope.
scope
.
_remove_from_pool
()
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录