Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c737116c
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看板
未验证
提交
c737116c
编写于
8月 21, 2019
作者:
C
chengduo
提交者:
GitHub
8月 21, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Cherry Pick] Add error info during compile (#19300)
* Add call stack info during runtime and compile time test=develop
上级
737f21b8
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
163 addition
and
41 deletion
+163
-41
paddle/fluid/framework/CMakeLists.txt
paddle/fluid/framework/CMakeLists.txt
+3
-1
paddle/fluid/framework/op_call_stack.cc
paddle/fluid/framework/op_call_stack.cc
+47
-0
paddle/fluid/framework/op_call_stack.h
paddle/fluid/framework/op_call_stack.h
+26
-0
paddle/fluid/framework/op_desc.cc
paddle/fluid/framework/op_desc.cc
+29
-20
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+2
-20
python/paddle/fluid/tests/unittests/test_runtime_and_compiletime_exception.py
...tests/unittests/test_runtime_and_compiletime_exception.py
+56
-0
未找到文件。
paddle/fluid/framework/CMakeLists.txt
浏览文件 @
c737116c
...
...
@@ -125,7 +125,7 @@ cc_library(shape_inference SRCS shape_inference.cc DEPS ddim attribute device_co
cc_library
(
transfer_scope_cache SRCS transfer_scope_cache.cc DEPS scope framework_proto device_context
)
cc_library
(
op_kernel_type SRCS op_kernel_type.cc DEPS device_context place
)
cc_library
(
operator SRCS operator.cc DEPS op_info device_context tensor scope glog
shape_inference data_transform lod_tensor profiler transfer_scope_cache op_kernel_type
)
shape_inference data_transform lod_tensor profiler transfer_scope_cache op_kernel_type
op_call_stack
)
cc_test
(
operator_test SRCS operator_test.cc DEPS operator op_registry device_context
)
...
...
@@ -136,6 +136,8 @@ cc_library(proto_desc SRCS var_desc.cc op_desc.cc block_desc.cc program_desc.cc
cc_library
(
op_registry SRCS op_registry.cc DEPS op_proto_maker op_info operator glog proto_desc memory_optimize_helper
)
cc_library
(
op_call_stack SRCS op_call_stack.cc DEPS op_proto_maker enforce
)
nv_test
(
op_registry_test SRCS op_registry_test.cc DEPS op_registry
)
py_proto_compile
(
framework_py_proto SRCS framework.proto data_feed.proto
)
...
...
paddle/fluid/framework/op_call_stack.cc
0 → 100644
浏览文件 @
c737116c
/* Copyright (c) 2019 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/op_call_stack.h"
#include <string>
#include <vector>
#include "paddle/fluid/framework/attribute.h"
#include "paddle/fluid/framework/op_proto_maker.h"
namespace
paddle
{
namespace
framework
{
void
InsertCallStackInfo
(
const
std
::
string
&
type
,
const
AttributeMap
&
attrs
,
platform
::
EnforceNotMet
*
exception
)
{
if
(
attrs
.
count
(
"sub_block"
)
!=
0
)
{
return
;
}
auto
&
callstack
=
boost
::
get
<
std
::
vector
<
std
::
string
>>
(
attrs
.
at
(
OpProtoAndCheckerMaker
::
OpCreationCallstackAttrName
()));
if
(
callstack
.
empty
())
{
return
;
}
std
::
ostringstream
sout
;
sout
<<
"Invoke operator "
<<
type
<<
" error.
\n
"
;
sout
<<
"Python Call stacks:
\n
"
;
for
(
auto
&
line
:
callstack
)
{
sout
<<
line
;
}
sout
<<
"C++ Call stacks:
\n
"
;
sout
<<
exception
->
err_str_
;
exception
->
err_str_
=
sout
.
str
();
}
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/op_call_stack.h
0 → 100644
浏览文件 @
c737116c
/* Copyright (c) 2019 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 <string>
#include "paddle/fluid/framework/type_defs.h"
#include "paddle/fluid/platform/enforce.h"
namespace
paddle
{
namespace
framework
{
void
InsertCallStackInfo
(
const
std
::
string
&
type
,
const
AttributeMap
&
attrs
,
platform
::
EnforceNotMet
*
exception
);
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/op_desc.cc
浏览文件 @
c737116c
...
...
@@ -18,8 +18,10 @@ limitations under the License. */
#include <mutex> // NOLINT
#include <string>
#include <unordered_map>
#include <utility>
#include "glog/logging.h"
#include "paddle/fluid/framework/block_desc.h"
#include "paddle/fluid/framework/op_call_stack.h"
#include "paddle/fluid/framework/op_proto_maker.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/program_desc.h"
...
...
@@ -679,6 +681,7 @@ void OpDesc::CheckAttrs() {
}
void
OpDesc
::
InferShape
(
const
BlockDesc
&
block
)
const
{
try
{
VLOG
(
3
)
<<
"CompileTime infer shape on "
<<
Type
();
InitInferShapeFuncs
();
auto
&
infer_shape
=
OpInfoMap
::
Instance
().
Get
(
this
->
Type
()).
infer_shape_
;
...
...
@@ -699,6 +702,12 @@ void OpDesc::InferShape(const BlockDesc &block) const {
VLOG
(
10
)
<<
sout
.
str
();
}
infer_shape
(
&
ctx
);
}
catch
(
platform
::
EnforceNotMet
exception
)
{
framework
::
InsertCallStackInfo
(
Type
(),
attrs_
,
&
exception
);
throw
std
::
move
(
exception
);
}
catch
(...)
{
std
::
rethrow_exception
(
std
::
current_exception
());
}
}
void
OpDesc
::
InferVarType
(
BlockDesc
*
block
)
const
{
...
...
paddle/fluid/framework/operator.cc
浏览文件 @
c737116c
...
...
@@ -23,6 +23,7 @@ limitations under the License. */
#include "paddle/fluid/framework/data_transform.h"
#include "paddle/fluid/framework/executor.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/op_call_stack.h"
#include "paddle/fluid/framework/op_proto_maker.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/shape_inference.h"
...
...
@@ -183,28 +184,9 @@ void OperatorBase::Run(const Scope& scope, const platform::Place& place) {
}
else
{
RunImpl
(
scope
,
place
);
}
VLOG
(
3
)
<<
place
<<
" "
<<
DebugStringEx
(
&
scope
);
}
catch
(
platform
::
EnforceNotMet
exception
)
{
if
(
Attrs
().
count
(
"sub_block"
)
!=
0
)
{
throw
std
::
move
(
exception
);
}
auto
&
callstack
=
Attr
<
std
::
vector
<
std
::
string
>>
(
OpProtoAndCheckerMaker
::
OpCreationCallstackAttrName
());
if
(
callstack
.
empty
())
{
throw
std
::
move
(
exception
);
}
std
::
ostringstream
sout
;
sout
<<
"Invoke operator "
<<
Type
()
<<
" error.
\n
"
;
sout
<<
"Python Callstacks:
\n
"
;
for
(
auto
&
line
:
callstack
)
{
sout
<<
line
;
}
sout
<<
"C++ Callstacks:
\n
"
;
sout
<<
exception
.
err_str_
;
exception
.
err_str_
=
sout
.
str
();
framework
::
InsertCallStackInfo
(
Type
(),
Attrs
(),
&
exception
);
throw
std
::
move
(
exception
);
}
catch
(...)
{
std
::
rethrow_exception
(
std
::
current_exception
());
...
...
python/paddle/fluid/tests/unittests/test_runtime_and_compiletime_exception.py
0 → 100644
浏览文件 @
c737116c
# Copyright (c) 2019 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.
from
__future__
import
print_function
import
unittest
import
numpy
as
np
from
op_test
import
OpTest
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
class
TestRunTimeException
(
OpTest
):
def
test_run_time_exception
(
self
):
place
=
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
train_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
train_program
,
startup_program
):
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
fluid
.
layers
.
one_hot
(
input
=
label
,
depth
=
100
)
def
_run_program
():
x
=
np
.
random
.
random
(
size
=
(
10
)).
astype
(
'int64'
)
exe
.
run
(
train_program
,
feed
=
{
"label"
:
x
})
self
.
assertRaises
(
core
.
EnforceNotMet
,
_run_program
)
class
TestCompileTimeException
(
OpTest
):
def
test_compile_time_exception
(
self
):
self
.
assertRaises
(
core
.
EnforceNotMet
,
self
.
build_model
)
def
build_model
(
self
):
train_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
train_program
,
startup_program
):
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
,
append_batch_size
=
False
)
fluid
.
layers
.
one_hot
(
input
=
label
,
depth
=
100
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录