Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
71f727da
提交
71f727da
authored
12月 18, 2020
作者:
Michael Osthege
提交者:
Brandon T. Willard
12月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generalize excepthook registration
上级
5bb459cf
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
99 行增加
和
70 行删除
+99
-70
__init__.py
theano/link/__init__.py
+3
-5
debugging.py
theano/link/debugging.py
+52
-65
utils.py
theano/utils.py
+44
-0
没有找到文件。
theano/link/__init__.py
浏览文件 @
71f727da
import
sys
from
theano.link.basic
import
(
from
theano.link.basic
import
(
Container
,
Container
,
Linker
,
Linker
,
LocalLinker
,
LocalLinker
,
...
@@ -11,7 +9,7 @@ from theano.link.basic import (
...
@@ -11,7 +9,7 @@ from theano.link.basic import (
map_storage
,
map_storage
,
streamline
,
streamline
,
)
)
from
theano.link.debugging
import
raise_with_op
,
set
_excepthook
from
theano.link.debugging
import
raise_with_op
,
register_thunk_trace
_excepthook
set_excepthook
(
handler
=
sys
.
stdout
)
register_thunk_trace_excepthook
(
)
theano/link/debugging.py
浏览文件 @
71f727da
...
@@ -6,74 +6,10 @@ from operator import itemgetter
...
@@ -6,74 +6,10 @@ from operator import itemgetter
import
numpy
as
np
import
numpy
as
np
from
theano
import
config
from
theano
import
config
,
utils
from
theano.gof.fg
import
FunctionGraph
from
theano.gof.fg
import
FunctionGraph
def
__log_thunk_trace
(
value
,
handler
):
"""
Log Theano's diagnostic stack trace for an exception
raised by raise_with_op.
"""
def
write
(
msg
):
print
(
f
"log_thunk_trace: {msg.strip()}"
,
file
=
handler
)
if
hasattr
(
value
,
"__thunk_trace__"
):
trace2
=
value
.
__thunk_trace__
write
(
"There was a problem executing an Op."
)
if
trace2
is
None
:
write
(
"Could not find where this Op was defined."
)
write
(
" * You might have instantiated this Op "
"directly instead of using a constructor."
)
write
(
" * The Op you constructed might have been"
" optimized. Try turning off optimizations."
)
elif
trace2
:
write
(
"Definition in: "
)
for
line
in
traceback
.
format_list
(
trace2
):
write
(
line
)
write
(
"For the full definition stack trace set"
" the Theano flags traceback__limit to -1"
)
def
set_excepthook
(
handler
:
io
.
TextIOWrapper
):
def
thunk_hook
(
type
,
value
,
trace
):
"""
This function is meant to replace excepthook and do some
special work if the exception value has a __thunk_trace__
field.
In that case, it retrieves the field, which should
contain a trace as returned by L{traceback.extract_stack},
and prints it out on L{stderr}.
The normal excepthook is then called.
Parameters:
----------
type
Exception class
value
Exception instance
trace
Traceback object
Notes
-----
This hook replaced in testing, so it does not run.
"""
__log_thunk_trace
(
value
,
handler
=
handler
)
sys
.
__excepthook__
(
type
,
value
,
trace
)
sys
.
excepthook
=
thunk_hook
def
raise_with_op
(
def
raise_with_op
(
fgraph
:
FunctionGraph
,
node
,
thunk
=
None
,
exc_info
=
None
,
storage_map
=
None
fgraph
:
FunctionGraph
,
node
,
thunk
=
None
,
exc_info
=
None
,
storage_map
=
None
):
):
...
@@ -334,3 +270,54 @@ def raise_with_op(
...
@@ -334,3 +270,54 @@ def raise_with_op(
# Some exception need extra parameter in inputs. So forget the
# Some exception need extra parameter in inputs. So forget the
# extra long error message in that case.
# extra long error message in that case.
raise
exc_value
.
with_traceback
(
exc_trace
)
raise
exc_value
.
with_traceback
(
exc_trace
)
def
__log_thunk_trace
(
value
,
handler
:
io
.
TextIOWrapper
):
"""
Log Theano's diagnostic stack trace for an exception.
Uses custom attributes that are added to trace objects by raise_with_op.
"""
def
write
(
msg
):
print
(
f
"log_thunk_trace: {msg.strip()}"
,
file
=
handler
)
if
hasattr
(
value
,
"__thunk_trace__"
):
trace2
=
value
.
__thunk_trace__
write
(
"There was a problem executing an Op."
)
if
trace2
is
None
:
write
(
"Could not find where this Op was defined."
)
write
(
" * You might have instantiated this Op "
"directly instead of using a constructor."
)
write
(
" * The Op you constructed might have been"
" optimized. Try turning off optimizations."
)
elif
trace2
:
write
(
"Definition in: "
)
for
line
in
traceback
.
format_list
(
trace2
):
write
(
line
)
write
(
"For the full definition stack trace set"
" the Theano flags traceback__limit to -1"
)
def
register_thunk_trace_excepthook
(
handler
:
io
.
TextIOWrapper
=
sys
.
stdout
):
"""Adds the __log_thunk_trace except hook to the collection in theano.utils.
Parameters
----------
handler : TextIOWrapper
Target for printing the output.
"""
def
wrapper
(
type
,
value
,
trace
):
__log_thunk_trace
(
value
,
handler
)
utils
.
add_excepthook
(
wrapper
)
register_thunk_trace_excepthook
()
theano/utils.py
浏览文件 @
71f727da
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
import
inspect
import
inspect
import
os
import
os
import
subprocess
import
subprocess
import
sys
import
traceback
import
traceback
import
warnings
import
warnings
from
collections
import
OrderedDict
from
collections
import
OrderedDict
...
@@ -23,6 +24,49 @@ __all__ = [
...
@@ -23,6 +24,49 @@ __all__ = [
]
]
__excepthooks
=
[]
def
__call_excepthooks
(
type
,
value
,
trace
):
"""
This function is meant to replace excepthook and do some
special work if the exception value has a __thunk_trace__
field.
In that case, it retrieves the field, which should
contain a trace as returned by L{traceback.extract_stack},
and prints it out on L{stderr}.
The normal excepthook is then called.
Parameters:
----------
type
Exception class
value
Exception instance
trace
Traceback object
Notes
-----
This hook replaced in testing, so it does not run.
"""
for
hook
in
__excepthooks
:
hook
(
type
,
value
,
trace
)
sys
.
__excepthook__
(
type
,
value
,
trace
)
def
add_excepthook
(
hook
):
"""Adds an excepthook to a list of excepthooks that are called
when an unhandled exception happens.
See https://docs.python.org/3/library/sys.html#sys.excepthook for signature info.
"""
__excepthooks
.
append
(
hook
)
sys
.
excepthook
=
__call_excepthooks
def
exc_message
(
e
):
def
exc_message
(
e
):
"""
"""
In python 3.x, when an exception is reraised it saves original
In python 3.x, when an exception is reraised it saves original
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论