Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3307a4dd
提交
3307a4dd
authored
2月 16, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added testcase that triggers local_greedy_optimizer bug. Misc improvements to debugmode
上级
1c859635
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
57 行增加
和
1 行删除
+57
-1
debugmode.py
theano/sandbox/debugmode.py
+34
-0
test_opt.py
theano/tensor/tests/test_opt.py
+23
-1
没有找到文件。
theano/sandbox/debugmode.py
浏览文件 @
3307a4dd
...
...
@@ -11,6 +11,7 @@ broken.
"""
import
time
,
copy
,
sys
from
StringIO
import
StringIO
from
..
import
gof
...
...
@@ -21,6 +22,7 @@ from ..gof.cc import OpWiseCLinker, CLinker
from
..compile.mode
import
Mode
import
numpy
from
..compile.function_module
import
(
convert_function_input
,
FunctionMaker
,
predefined_modes
,
...
...
@@ -31,6 +33,24 @@ from ..compile.function_module import (convert_function_input,
SymbolicOutput
,
Supervisor
)
def
debugprint
(
a
,
prefix
=
''
,
depth
=-
1
,
done
=
None
,
file
=
sys
.
stdout
):
if
depth
==
0
:
return
done
=
set
()
if
done
is
None
else
done
if
hasattr
(
a
,
'op'
):
print
>>
file
,
prefix
,
a
.
op
,
id
(
a
)
if
id
(
a
)
not
in
done
:
done
.
add
(
id
(
a
))
for
i
in
a
.
inputs
:
if
i
.
owner
:
debugprint
(
i
.
owner
,
prefix
+
' '
,
depth
=
depth
-
1
,
done
=
done
,
file
=
file
)
else
:
print
>>
file
,
prefix
+
' '
,
i
,
id
(
i
)
else
:
print
>>
file
,
prefix
+
' '
,
a
,
id
(
a
)
return
file
class
ResultEquivalenceTracker
(
object
):
def
__init__
(
self
):
self
.
env
=
None
...
...
@@ -43,6 +63,7 @@ class ResultEquivalenceTracker(object):
self
.
env
=
env
self
.
all_results_ever
=
[]
self
.
reasons
=
{}
self
.
snapshots
=
{}
def
on_detach
(
self
,
env
):
assert
env
is
self
.
env
...
...
@@ -70,15 +91,22 @@ class ResultEquivalenceTracker(object):
self
.
equiv
[
r
]
=
set
([
r
])
self
.
all_results_ever
.
append
(
r
)
self
.
reasons
.
setdefault
(
r
,
[])
self
.
snapshots
.
setdefault
(
r
,
[])
for
r
in
node
.
inputs
:
self
.
reasons
.
setdefault
(
r
,
[])
self
.
snapshots
.
setdefault
(
r
,
[])
def
on_change_input
(
self
,
env
,
node
,
i
,
r
,
new_r
,
reason
=
None
):
#print 'CHANGE by', reason, 'to use', new_r, type(new_r)
self
.
reasons
.
setdefault
(
new_r
,
[])
self
.
snapshots
.
setdefault
(
new_r
,
[])
if
(
reason
,
r
)
not
in
self
.
reasons
[
new_r
]:
self
.
reasons
[
new_r
]
.
append
((
reason
,
r
))
self
.
snapshots
[
new_r
]
.
append
((
reason
,
debugprint
(
r
.
owner
,
prefix
=
' '
,
depth
=
6
,
file
=
StringIO
())
.
getvalue
(),
debugprint
(
new_r
.
owner
,
prefix
=
' '
,
depth
=
6
,
file
=
StringIO
())
.
getvalue
()))
self
.
reasons
[
r
]
.
append
((
'replaced by'
,
new_r
))
if
r
in
self
.
equiv
:
...
...
@@ -252,6 +280,12 @@ class OptCheckLinker(OpWiseCLinker):
print
" Value Type:"
,
type
(
r_vals
[
r
])
print
" Value: "
,
r_vals
[
r
]
print
" Reason: "
,
[(
str
(
reason
),
id
(
old_r
))
for
reason
,
old_r
in
env
.
equivalence_tracker
.
reasons
[
r
]]
print
" Snapshots:"
for
s
in
env
.
equivalence_tracker
.
snapshots
[
r
]:
print
" BEFORE"
print
s
[
1
]
print
" AFTER"
print
s
[
2
]
print
""
raise
Exception
(
"OptCheckFailure"
)
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
3307a4dd
...
...
@@ -13,6 +13,9 @@ from theano import pprint
import
numpy
#import scalar_opt
from
theano.sandbox.debugmode
import
OptCheck
from
theano
import
function
def
inputs
(
xbc
=
(
0
,
0
),
ybc
=
(
0
,
0
),
zbc
=
(
0
,
0
)):
x
=
Tensor
(
broadcastable
=
xbc
,
dtype
=
'float64'
)(
'x'
)
...
...
@@ -119,7 +122,26 @@ class test_greedy_distribute(unittest.TestCase):
gof
.
TopoOptimizer
(
gof
.
LocalOptGroup
(
local_fill_cut
,
local_fill_lift
),
order
=
'out_to_in'
)
.
optimize
(
g
)
gof
.
TopoOptimizer
(
gof
.
LocalOptGroup
(
local_greedy_distributor
),
order
=
'out_to_in'
)
.
optimize
(
g
)
##print pprint(g.outputs[0])
def
test_kording_bug
(
self
):
x
,
y
=
vectors
(
'xy'
)
eps
=
scalar
(
'eps'
)
s
=
scalar
(
's'
)
#r = theano.tensor.mul(theano.tensor.fill(x, 2.*a), x/a , (y+z) , a)
#r = theano.tensor.mul((x/a+y) , a, z)
r
=
mul
(
s
-
1
,
eps
+
x
/
s
,
eps
+
y
/
s
,
s
)
f
=
function
([
s
,
eps
,
x
,
y
],
r
**
2
,
mode
=
OptCheck
())
r0
=
f
(
4
,
1.e-6
,
[
1.5
,
2
],
[
2.3
,
3.1
])
r1
=
f
(
4
,
1.e-6
,
[
1.5
,
2
],
[
2.3
,
3.1
])
r2
=
f
(
4
,
1.e-6
,
[
1.5
,
2
],
[
2.3
,
3.1
])
class
test_canonize
(
unittest
.
TestCase
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论