Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
51bb1168
提交
51bb1168
authored
2月 25, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
s/OptCheck/DebugMode
上级
5f8a6a62
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
18 行增加
和
25 行删除
+18
-25
debugmode.py
theano/sandbox/debugmode.py
+12
-19
test_debugmode.py
theano/sandbox/test_debugmode.py
+4
-4
test_opt.py
theano/tensor/tests/test_opt.py
+2
-2
没有找到文件。
theano/sandbox/debugmode.py
浏览文件 @
51bb1168
""" Provides `
OptCheck
`
""" Provides `
DebugMode
`
"""
"""
...
@@ -25,17 +25,10 @@ from ..compile.function_module import (convert_function_input,
...
@@ -25,17 +25,10 @@ from ..compile.function_module import (convert_function_input,
SymbolicOutput
,
SymbolicOutput
,
Supervisor
)
Supervisor
)
def
values_eq_enough_warn
(
a
,
b
,
r
):
class
DebugModeError
(
Exception
):
# TODO: use the result variables r to retrieve a Type, and then use the Type's value_cmp
# function: see ticket on value_cmp
print
>>
sys
.
stderr
,
'WARNING: OptCheck comparison of'
,
type
(
new_r_val
),
'NotImplementedError'
return
True
class
OptCheckError
(
Exception
):
pass
pass
class
BadClinkerOutput
(
OptCheck
Error
):
class
BadClinkerOutput
(
DebugMode
Error
):
"""Exception: a c implementation and python implementation don't agree"""
"""Exception: a c implementation and python implementation don't agree"""
r
=
None
r
=
None
...
@@ -54,7 +47,7 @@ class BadClinkerOutput(OptCheckError):
...
@@ -54,7 +47,7 @@ class BadClinkerOutput(OptCheckError):
self
.
a
=
a
self
.
a
=
a
self
.
b
=
b
self
.
b
=
b
class
BadOptimization
(
OptCheck
Error
):
class
BadOptimization
(
DebugMode
Error
):
"""Exception: some result and its substitute take different runtime values."""
"""Exception: some result and its substitute take different runtime values."""
new_r
=
None
new_r
=
None
...
@@ -272,7 +265,7 @@ def optcheck_env(input_specs, output_specs, accept_inplace = False):
...
@@ -272,7 +265,7 @@ def optcheck_env(input_specs, output_specs, accept_inplace = False):
return
env
,
map
(
SymbolicOutput
,
updates
),
equivalence_tracker
return
env
,
map
(
SymbolicOutput
,
updates
),
equivalence_tracker
class
OptCheck
Linker
(
gof
.
link
.
LocalLinker
):
class
DebugMode
Linker
(
gof
.
link
.
LocalLinker
):
def
__init__
(
self
,
maker
):
def
__init__
(
self
,
maker
):
super
(
gof
.
LocalLinker
,
self
)
.
__init__
()
super
(
gof
.
LocalLinker
,
self
)
.
__init__
()
self
.
env
=
None
self
.
env
=
None
...
@@ -280,7 +273,7 @@ class OptCheckLinker(gof.link.LocalLinker):
...
@@ -280,7 +273,7 @@ class OptCheckLinker(gof.link.LocalLinker):
def
accept
(
self
,
env
,
no_recycling
=
[]):
def
accept
(
self
,
env
,
no_recycling
=
[]):
if
self
.
env
is
not
None
and
self
.
env
is
not
env
:
if
self
.
env
is
not
None
and
self
.
env
is
not
env
:
assert
type
(
self
)
is
OptCheck
Linker
assert
type
(
self
)
is
DebugMode
Linker
return
type
(
self
)(
self
.
env
,
self
.
maker
)
.
accept
(
env
,
no_recycling
)
return
type
(
self
)(
self
.
env
,
self
.
maker
)
.
accept
(
env
,
no_recycling
)
self
.
env
=
env
self
.
env
=
env
self
.
no_recycling
=
no_recycling
self
.
no_recycling
=
no_recycling
...
@@ -449,7 +442,7 @@ class OptCheckLinker(gof.link.LocalLinker):
...
@@ -449,7 +442,7 @@ class OptCheckLinker(gof.link.LocalLinker):
thunks_py
,
order
thunks_py
,
order
NODEFAULT
=
[
'NODEFAULT'
]
NODEFAULT
=
[
'NODEFAULT'
]
class
OptCheck
FunctionMaker
(
FunctionMaker
):
#inheritance buys a few helper functions
class
DebugMode
FunctionMaker
(
FunctionMaker
):
#inheritance buys a few helper functions
verbose
=
0
verbose
=
0
"""Verbosity level of compile-time and run-time checks. (Default 0: silent)"""
"""Verbosity level of compile-time and run-time checks. (Default 0: silent)"""
...
@@ -516,7 +509,7 @@ class OptCheckFunctionMaker(FunctionMaker): #inheritance buys a few helper funct
...
@@ -516,7 +509,7 @@ class OptCheckFunctionMaker(FunctionMaker): #inheritance buys a few helper funct
self
.
env
=
env
self
.
env
=
env
#equivalence_tracker.printstuff()
#equivalence_tracker.printstuff()
linker
=
OptCheck
Linker
(
self
)
linker
=
DebugMode
Linker
(
self
)
#the 'no_borrow' outputs are the ones for which that we can't return the internal storage pointer.
#the 'no_borrow' outputs are the ones for which that we can't return the internal storage pointer.
...
@@ -629,7 +622,7 @@ class OptCheckFunctionMaker(FunctionMaker): #inheritance buys a few helper funct
...
@@ -629,7 +622,7 @@ class OptCheckFunctionMaker(FunctionMaker): #inheritance buys a few helper funct
fn
=
self
.
function_builder
(
_fn
,
_i
,
_o
,
self
.
indices
,
self
.
outputs
,
defaults
,
self
.
unpack_single
,
self
)
fn
=
self
.
function_builder
(
_fn
,
_i
,
_o
,
self
.
indices
,
self
.
outputs
,
defaults
,
self
.
unpack_single
,
self
)
return
fn
return
fn
class
OptCheck
(
Mode
):
class
DebugMode
(
Mode
):
"""Evaluation Mode that detects optimization errors.
"""Evaluation Mode that detects optimization errors.
A basic premise of how theano works is that every node that is replaced during optimization should compute the same thing as its replacement.
A basic premise of how theano works is that every node that is replaced during optimization should compute the same thing as its replacement.
...
@@ -645,14 +638,14 @@ class OptCheck(Mode):
...
@@ -645,14 +638,14 @@ class OptCheck(Mode):
# function_module.function
# function_module.function
def
function_maker
(
self
,
i
,
o
,
m
,
*
args
,
**
kwargs
):
def
function_maker
(
self
,
i
,
o
,
m
,
*
args
,
**
kwargs
):
assert
m
is
self
assert
m
is
self
return
OptCheck
FunctionMaker
(
i
,
o
,
self
.
optimizer
,
self
,
*
args
,
**
kwargs
)
return
DebugMode
FunctionMaker
(
i
,
o
,
self
.
optimizer
,
self
,
*
args
,
**
kwargs
)
def
__init__
(
self
,
def
__init__
(
self
,
optimizer
=
'fast_run'
,
optimizer
=
'fast_run'
,
stability_patience
=
10
,
stability_patience
=
10
,
check_c_code
=
True
):
check_c_code
=
True
):
super
(
OptCheck
,
self
)
.
__init__
(
super
(
DebugMode
,
self
)
.
__init__
(
optimizer
=
optimizer
,
optimizer
=
optimizer
,
linker
=
OptCheck
Linker
)
linker
=
DebugMode
Linker
)
self
.
stability_patience
=
stability_patience
self
.
stability_patience
=
stability_patience
self
.
check_c_code
=
check_c_code
self
.
check_c_code
=
check_c_code
...
...
theano/sandbox/test_debugmode.py
浏览文件 @
51bb1168
...
@@ -10,7 +10,7 @@ import theano.compile
...
@@ -10,7 +10,7 @@ import theano.compile
def
test0
():
def
test0
():
x
=
theano
.
tensor
.
dvector
()
x
=
theano
.
tensor
.
dvector
()
f
=
theano
.
function
([
x
],
(
2.
*
x
+
7
)
/
2.
,
mode
=
debugmode
.
OptCheck
())
f
=
theano
.
function
([
x
],
(
2.
*
x
+
7
)
/
2.
,
mode
=
debugmode
.
DebugMode
())
print
f
([
1
,
2
])
print
f
([
1
,
2
])
class
BROKEN_ON_PURPOSE_StructuredDotCSC
(
gof
.
Op
):
class
BROKEN_ON_PURPOSE_StructuredDotCSC
(
gof
.
Op
):
...
@@ -161,10 +161,10 @@ def test_badclinkeroutput():
...
@@ -161,10 +161,10 @@ def test_badclinkeroutput():
f_good
=
theano
.
function
([
vals
,
inds
,
ptrs
,
nrows
,
b
],
f_good
=
theano
.
function
([
vals
,
inds
,
ptrs
,
nrows
,
b
],
theano
.
sparse
.
StructuredDotCSC
()(
vals
,
inds
,
ptrs
,
nrows
,
b
),
theano
.
sparse
.
StructuredDotCSC
()(
vals
,
inds
,
ptrs
,
nrows
,
b
),
mode
=
debugmode
.
OptCheck
(
check_c_code
=
True
))
mode
=
debugmode
.
DebugMode
(
check_c_code
=
True
))
f_inconsistent
=
theano
.
function
([
vals
,
inds
,
ptrs
,
nrows
,
b
],
f_inconsistent
=
theano
.
function
([
vals
,
inds
,
ptrs
,
nrows
,
b
],
inconsistent
(
vals
,
inds
,
ptrs
,
nrows
,
b
),
inconsistent
(
vals
,
inds
,
ptrs
,
nrows
,
b
),
mode
=
debugmode
.
OptCheck
(
check_c_code
=
True
))
mode
=
debugmode
.
DebugMode
(
check_c_code
=
True
))
#this should evaluate with no error
#this should evaluate with no error
rval_good
=
f_good
([
1.0
,
2.0
,
3.0
],
rval_good
=
f_good
([
1.0
,
2.0
,
3.0
],
...
@@ -205,7 +205,7 @@ def test_badoptimization():
...
@@ -205,7 +205,7 @@ def test_badoptimization():
f
=
theano
.
function
([
vals
,
inds
,
ptrs
,
nrows
,
b
],
f
=
theano
.
function
([
vals
,
inds
,
ptrs
,
nrows
,
b
],
theano
.
sparse
.
sd_csc
(
vals
,
inds
,
ptrs
,
nrows
,
b
),
theano
.
sparse
.
sd_csc
(
vals
,
inds
,
ptrs
,
nrows
,
b
),
mode
=
debugmode
.
OptCheck
(
optimizer
=
opt
,
check_c_code
=
True
))
mode
=
debugmode
.
DebugMode
(
optimizer
=
opt
,
check_c_code
=
True
))
try
:
try
:
rval
=
f
([
1.0
,
2.0
,
3.0
],
rval
=
f
([
1.0
,
2.0
,
3.0
],
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
51bb1168
...
@@ -13,7 +13,7 @@ from theano import pprint
...
@@ -13,7 +13,7 @@ from theano import pprint
import
numpy
import
numpy
#import scalar_opt
#import scalar_opt
from
theano.sandbox.debugmode
import
OptCheck
from
theano.sandbox.debugmode
import
DebugMode
from
theano
import
function
from
theano
import
function
...
@@ -136,7 +136,7 @@ class test_greedy_distribute(unittest.TestCase):
...
@@ -136,7 +136,7 @@ class test_greedy_distribute(unittest.TestCase):
,
eps
+
y
/
s
,
eps
+
y
/
s
,
s
)
,
s
)
f
=
function
([
s
,
eps
,
x
,
y
],
r
**
2
,
mode
=
OptCheck
())
f
=
function
([
s
,
eps
,
x
,
y
],
r
**
2
,
mode
=
DebugMode
())
r0
=
f
(
4
,
1.e-6
,
[
1.5
,
2
],
[
2.3
,
3.1
])
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
])
r1
=
f
(
4
,
1.e-6
,
[
1.5
,
2
],
[
2.3
,
3.1
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论