Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
11ee6cee
提交
11ee6cee
authored
10月 17, 2011
作者:
David Warde-Farley
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #125 from jaberg/thunk_hook_refactor
Thunk hook refactor
上级
674ee45b
d6edfffd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
41 行增加
和
31 行删除
+41
-31
link.py
theano/gof/link.py
+35
-14
vm.py
theano/gof/vm.py
+6
-17
没有找到文件。
theano/gof/link.py
浏览文件 @
11ee6cee
...
@@ -8,6 +8,33 @@ from copy import copy
...
@@ -8,6 +8,33 @@ from copy import copy
from
theano.gof.python25
import
all
from
theano.gof.python25
import
all
__excepthook
=
sys
.
excepthook
__excepthook
=
sys
.
excepthook
def
log_thunk_trace
(
value
,
f
=
sys
.
stderr
):
"""Log theano's diagnostic stack trace for an exception
raised by raise_with_op.
"""
# in future, consider accepting `write` as arg rather than file
# to support writing to a logger
def
write
(
msg
):
print
>>
f
,
"log_thunk_trace:
%
s"
%
msg
.
strip
()
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
thunk_hook
(
type
,
value
,
trace
):
def
thunk_hook
(
type
,
value
,
trace
):
"""WRITEME
"""WRITEME
This function is meant to replace excepthook and do some
This function is meant to replace excepthook and do some
...
@@ -20,20 +47,7 @@ def thunk_hook(type, value, trace):
...
@@ -20,20 +47,7 @@ def thunk_hook(type, value, trace):
:note: This hook replaced by nosetests, so it does not run in nose tests.
:note: This hook replaced by nosetests, so it does not run in nose tests.
"""
"""
if
hasattr
(
value
,
'__thunk_trace__'
):
log_thunk_trace
(
value
)
trace2
=
value
.
__thunk_trace__
if
trace2
is
None
:
print
>>
sys
.
stderr
,
"Could not find where this Op was defined."
print
>>
sys
.
stderr
,
(
" * You might have instantiated this Op "
"directly instead of using a constructor."
)
print
>>
sys
.
stderr
,
(
" * The Op you constructed might have been"
" optimized. Try turning off optimizations."
)
elif
trace2
:
print
>>
sys
.
stderr
,
"Definition in: "
for
line
in
traceback
.
format_list
(
trace2
):
print
>>
sys
.
stderr
,
line
,
print
>>
sys
.
stderr
,
(
"For the full definition stack trace set"
" the Theano flags traceback.limit to -1"
)
__excepthook
(
type
,
value
,
trace
)
__excepthook
(
type
,
value
,
trace
)
sys
.
excepthook
=
thunk_hook
sys
.
excepthook
=
thunk_hook
...
@@ -85,8 +99,15 @@ def raise_with_op(op, exc_info=None):
...
@@ -85,8 +99,15 @@ def raise_with_op(op, exc_info=None):
exc_value
.
__applynode_index__
=
op
.
env
.
toposort
()
.
index
(
op
)
exc_value
.
__applynode_index__
=
op
.
env
.
toposort
()
.
index
(
op
)
else
:
else
:
exc_value
.
__applynode_index__
=
None
exc_value
.
__applynode_index__
=
None
# nose and unittest catch the exception and do not run th thunk_hook
# so it can be useful to just blurt out errors right here
if
raise_with_op
.
print_thunk_trace
:
log_thunk_trace
(
exc_value
)
raise
exc_type
,
exc_value
,
exc_trace
raise
exc_type
,
exc_value
,
exc_trace
raise_with_op
.
print_thunk_trace
=
False
class
Linker
(
object
):
class
Linker
(
object
):
"""WRITEME"""
"""WRITEME"""
...
...
theano/gof/vm.py
浏览文件 @
11ee6cee
...
@@ -20,24 +20,8 @@ AddConfigVar('profile',
...
@@ -20,24 +20,8 @@ AddConfigVar('profile',
"If VM should collect profile information"
,
"If VM should collect profile information"
,
BoolParam
(
False
))
BoolParam
(
False
))
raise_with_op
=
link
.
raise_with_op
def
raise_with_op
(
op
,
exc_info
=
None
):
"""WRITEME"""
if
exc_info
is
None
:
exc_info
=
sys
.
exc_info
()
exc_type
,
exc_value
,
exc_trace
=
exc_info
if
exc_type
==
KeyboardInterrupt
:
# print a simple traceback from KeyboardInterrupt
raise
exc_type
,
exc_value
,
exc_trace
try
:
trace
=
op
.
tag
.
trace
except
AttributeError
:
trace
=
()
exc_value
.
__thunk_trace__
=
trace
exc_value
.
args
+=
(
op
,
)
if
op
in
op
.
env
.
toposort
():
exc_value
.
args
+=
(
'Sequence id of Apply node='
+
str
(
op
.
env
.
toposort
()
.
index
(
op
)),)
raise
exc_type
,
exc_value
,
exc_trace
class
VM
(
object
):
class
VM
(
object
):
"""
"""
...
@@ -114,6 +98,7 @@ class VM(object):
...
@@ -114,6 +98,7 @@ class VM(object):
self
.
call_times
[
i
]
=
0.0
self
.
call_times
[
i
]
=
0.0
self
.
call_counts
[
i
]
=
0
self
.
call_counts
[
i
]
=
0
class
Loop
(
VM
):
class
Loop
(
VM
):
"""
"""
Unconditional start-to-finish program execution in Python.
Unconditional start-to-finish program execution in Python.
...
@@ -141,6 +126,7 @@ class Loop(VM):
...
@@ -141,6 +126,7 @@ class Loop(VM):
except
:
except
:
raise_with_op
(
node
)
raise_with_op
(
node
)
class
LoopGC
(
VM
):
class
LoopGC
(
VM
):
"""
"""
Unconditional start-to-finish program execution in Python.
Unconditional start-to-finish program execution in Python.
...
@@ -179,6 +165,7 @@ class LoopGC(VM):
...
@@ -179,6 +165,7 @@ class LoopGC(VM):
except
:
except
:
raise_with_op
(
node
)
raise_with_op
(
node
)
class
Stack
(
VM
):
class
Stack
(
VM
):
"""
"""
Finish-to-start evalution order of thunks.
Finish-to-start evalution order of thunks.
...
@@ -385,6 +372,7 @@ class Stack(VM):
...
@@ -385,6 +372,7 @@ class Stack(VM):
if
empty_storage_map
:
if
empty_storage_map
:
storage_map
[
i
][
0
]
=
None
storage_map
[
i
][
0
]
=
None
try
:
try
:
import
lazylinker_c
import
lazylinker_c
class
CVM
(
lazylinker_c
.
CLazyLinker
,
VM
):
class
CVM
(
lazylinker_c
.
CLazyLinker
,
VM
):
...
@@ -394,6 +382,7 @@ try:
...
@@ -394,6 +382,7 @@ try:
except
ImportError
:
except
ImportError
:
pass
pass
class
VM_Linker
(
link
.
LocalLinker
):
class
VM_Linker
(
link
.
LocalLinker
):
"""
"""
Class that satisfies the Linker interface by acting as a VM factory.
Class that satisfies the Linker interface by acting as a VM factory.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论