Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e74a919e
提交
e74a919e
authored
1月 25, 2017
作者:
Benjamin Scellier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
file theano/compile/debugmode.py
上级
6d7d97f0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
30 行删除
+30
-30
debugmode.py
theano/compile/debugmode.py
+30
-30
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
e74a919e
...
@@ -14,7 +14,7 @@ import six.moves.copyreg as copyreg
...
@@ -14,7 +14,7 @@ import six.moves.copyreg as copyreg
from
itertools
import
chain
,
product
as
itertools_product
from
itertools
import
chain
,
product
as
itertools_product
from
theano.compat
import
izip
from
theano.compat
import
izip
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano
import
gof
,
config
from
theano
import
gof
,
config
...
@@ -270,15 +270,15 @@ class BadOptimization(DebugModeError):
...
@@ -270,15 +270,15 @@ class BadOptimization(DebugModeError):
print
(
" New Value: "
,
str
(
self
.
new_r_val
),
file
=
sio
)
print
(
" New Value: "
,
str
(
self
.
new_r_val
),
file
=
sio
)
try
:
try
:
ov
=
n
umpy
.
asarray
(
self
.
old_r_val
)
ov
=
n
p
.
asarray
(
self
.
old_r_val
)
nv
=
n
umpy
.
asarray
(
self
.
new_r_val
)
nv
=
n
p
.
asarray
(
self
.
new_r_val
)
ssio
=
StringIO
()
ssio
=
StringIO
()
abs_diff
=
n
umpy
.
absolute
(
nv
-
ov
)
abs_diff
=
n
p
.
absolute
(
nv
-
ov
)
print
(
" Max Abs Diff: "
,
n
umpy
.
max
(
abs_diff
),
file
=
ssio
)
print
(
" Max Abs Diff: "
,
n
p
.
max
(
abs_diff
),
file
=
ssio
)
print
(
" Mean Abs Diff: "
,
n
umpy
.
mean
(
abs_diff
),
file
=
ssio
)
print
(
" Mean Abs Diff: "
,
n
p
.
mean
(
abs_diff
),
file
=
ssio
)
print
(
" Median Abs Diff: "
,
n
umpy
.
median
(
abs_diff
),
file
=
ssio
)
print
(
" Median Abs Diff: "
,
n
p
.
median
(
abs_diff
),
file
=
ssio
)
print
(
" Std Abs Diff: "
,
n
umpy
.
std
(
abs_diff
),
file
=
ssio
)
print
(
" Std Abs Diff: "
,
n
p
.
std
(
abs_diff
),
file
=
ssio
)
arg_max_val
=
n
umpy
.
argmax
(
abs_diff
)
arg_max_val
=
n
p
.
argmax
(
abs_diff
)
values_at_max
=
(
nv
.
flatten
()[
arg_max_val
],
values_at_max
=
(
nv
.
flatten
()[
arg_max_val
],
ov
.
flatten
()[
arg_max_val
])
ov
.
flatten
()[
arg_max_val
])
print
(
" Value at Max Diff: "
,
values_at_max
,
file
=
ssio
)
print
(
" Value at Max Diff: "
,
values_at_max
,
file
=
ssio
)
...
@@ -286,13 +286,13 @@ class BadOptimization(DebugModeError):
...
@@ -286,13 +286,13 @@ class BadOptimization(DebugModeError):
# N.B. the maximum(..., 1e-8) protects against div by 0 when
# N.B. the maximum(..., 1e-8) protects against div by 0 when
# nv == ov == 0
# nv == ov == 0
reldiff
=
(
abs_diff
/
reldiff
=
(
abs_diff
/
n
umpy
.
maaximum
(
numpy
.
absolute
(
nv
)
+
numpy
.
absolute
(
ov
),
n
p
.
maximum
(
np
.
absolute
(
nv
)
+
np
.
absolute
(
ov
),
1e-8
))
1e-8
))
print
(
" Max Rel Diff: "
,
n
umpy
.
max
(
reldiff
),
file
=
ssio
)
print
(
" Max Rel Diff: "
,
n
p
.
max
(
reldiff
),
file
=
ssio
)
print
(
" Mean Rel Diff: "
,
n
umpy
.
mean
(
reldiff
),
file
=
ssio
)
print
(
" Mean Rel Diff: "
,
n
p
.
mean
(
reldiff
),
file
=
ssio
)
print
(
" Median Rel Diff: "
,
n
umpy
.
median
(
reldiff
),
file
=
ssio
)
print
(
" Median Rel Diff: "
,
n
p
.
median
(
reldiff
),
file
=
ssio
)
print
(
" Std Rel Diff: "
,
n
umpy
.
std
(
reldiff
),
file
=
ssio
)
print
(
" Std Rel Diff: "
,
n
p
.
std
(
reldiff
),
file
=
ssio
)
arg_max_val
=
n
umpy
.
argmax
(
reldiff
)
arg_max_val
=
n
p
.
argmax
(
reldiff
)
values_at_max
=
(
nv
.
flatten
()[
arg_max_val
],
values_at_max
=
(
nv
.
flatten
()[
arg_max_val
],
ov
.
flatten
()[
arg_max_val
])
ov
.
flatten
()[
arg_max_val
])
print
(
" Value at Max Diff: "
,
values_at_max
,
file
=
ssio
)
print
(
" Value at Max Diff: "
,
values_at_max
,
file
=
ssio
)
...
@@ -342,8 +342,8 @@ class BadDestroyMap(DebugModeError):
...
@@ -342,8 +342,8 @@ class BadDestroyMap(DebugModeError):
print
(
" repr (old val):"
,
repr
(
self
.
old_val
),
file
=
sio
)
print
(
" repr (old val):"
,
repr
(
self
.
old_val
),
file
=
sio
)
print
(
" repr (new val):"
,
repr
(
self
.
new_val
),
file
=
sio
)
print
(
" repr (new val):"
,
repr
(
self
.
new_val
),
file
=
sio
)
try
:
try
:
npy_old_val
=
n
umpy
.
asarray
(
self
.
old_val
)
npy_old_val
=
n
p
.
asarray
(
self
.
old_val
)
npy_new_val
=
n
umpy
.
asarray
(
self
.
new_val
)
npy_new_val
=
n
p
.
asarray
(
self
.
new_val
)
print
(
" value dtype (new <space> old):"
,
npy_new_val
.
dtype
,
print
(
" value dtype (new <space> old):"
,
npy_new_val
.
dtype
,
npy_old_val
.
dtype
,
file
=
sio
)
npy_old_val
.
dtype
,
file
=
sio
)
print
(
" value shape (new <space> old):"
,
npy_new_val
.
shape
,
print
(
" value shape (new <space> old):"
,
npy_new_val
.
shape
,
...
@@ -356,13 +356,13 @@ class BadDestroyMap(DebugModeError):
...
@@ -356,13 +356,13 @@ class BadDestroyMap(DebugModeError):
print
(
" value min (new-old):"
,
delta
.
min
(),
file
=
sio
)
print
(
" value min (new-old):"
,
delta
.
min
(),
file
=
sio
)
print
(
" value max (new-old):"
,
delta
.
max
(),
file
=
sio
)
print
(
" value max (new-old):"
,
delta
.
max
(),
file
=
sio
)
print
(
" value argmin (new-old):"
,
print
(
" value argmin (new-old):"
,
n
umpy
.
unravel_index
(
delta
.
argmin
(),
npy_new_val
.
shape
),
n
p
.
unravel_index
(
delta
.
argmin
(),
npy_new_val
.
shape
),
file
=
sio
)
file
=
sio
)
print
(
" value argmax (new-old):"
,
print
(
" value argmax (new-old):"
,
n
umpy
.
unravel_index
(
delta
.
argmax
(),
npy_new_val
.
shape
),
n
p
.
unravel_index
(
delta
.
argmax
(),
npy_new_val
.
shape
),
file
=
sio
)
file
=
sio
)
print
(
" location of first 10 mismatches:"
,
print
(
" location of first 10 mismatches:"
,
n
umpy
.
transpose
(
numpy
.
nonzero
(
delta
))[:
10
],
file
=
sio
)
n
p
.
transpose
(
np
.
nonzero
(
delta
))[:
10
],
file
=
sio
)
print
(
""
,
file
=
sio
)
print
(
""
,
file
=
sio
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"(Numpy-hints failed with:
%
s)"
%
str
(
e
),
file
=
sio
)
print
(
"(Numpy-hints failed with:
%
s)"
%
str
(
e
),
file
=
sio
)
...
@@ -453,7 +453,7 @@ class InvalidValueError(DebugModeError):
...
@@ -453,7 +453,7 @@ class InvalidValueError(DebugModeError):
v_dtype
=
v
.
dtype
v_dtype
=
v
.
dtype
v_min
=
v
.
min
()
v_min
=
v
.
min
()
v_max
=
v
.
max
()
v_max
=
v
.
max
()
v_isfinite
=
n
umpy
.
all
(
numpy
.
isfinite
(
v
))
v_isfinite
=
n
p
.
all
(
np
.
isfinite
(
v
))
except
Exception
:
except
Exception
:
pass
pass
client_node
=
self
.
client_node
client_node
=
self
.
client_node
...
@@ -1025,7 +1025,7 @@ def _lessbroken_deepcopy(a):
...
@@ -1025,7 +1025,7 @@ def _lessbroken_deepcopy(a):
# this exists because copy.deepcopy on numpy arrays is broken
# this exists because copy.deepcopy on numpy arrays is broken
# This logic is also in link.py
# This logic is also in link.py
from
theano.gof.type
import
_cdata_type
from
theano.gof.type
import
_cdata_type
if
type
(
a
)
in
(
n
umpy
.
ndarray
,
numpy
.
memmap
):
if
type
(
a
)
in
(
n
p
.
ndarray
,
np
.
memmap
):
rval
=
a
.
copy
()
rval
=
a
.
copy
()
elif
type
(
a
)
is
_cdata_type
:
elif
type
(
a
)
is
_cdata_type
:
# This is not copyable (and should be used for constant data).
# This is not copyable (and should be used for constant data).
...
@@ -1034,7 +1034,7 @@ def _lessbroken_deepcopy(a):
...
@@ -1034,7 +1034,7 @@ def _lessbroken_deepcopy(a):
rval
=
copy
.
deepcopy
(
a
)
rval
=
copy
.
deepcopy
(
a
)
assert
type
(
rval
)
==
type
(
a
),
(
type
(
rval
),
type
(
a
))
assert
type
(
rval
)
==
type
(
a
),
(
type
(
rval
),
type
(
a
))
if
isinstance
(
rval
,
n
umpy
.
ndarray
):
if
isinstance
(
rval
,
n
p
.
ndarray
):
assert
rval
.
dtype
==
a
.
dtype
assert
rval
.
dtype
==
a
.
dtype
return
rval
return
rval
...
@@ -1241,7 +1241,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
...
@@ -1241,7 +1241,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
# There is no risk to overwrite inputs, since r does not work
# There is no risk to overwrite inputs, since r does not work
# inplace.
# inplace.
if
isinstance
(
r
.
type
,
(
TensorType
,
CudaNdarrayType
)):
if
isinstance
(
r
.
type
,
(
TensorType
,
CudaNdarrayType
)):
reuse_outputs
[
r
][
...
]
=
n
umpy
.
asarray
(
reuse_outputs
[
r
][
...
]
=
n
p
.
asarray
(
def_val
)
.
astype
(
r
.
type
.
dtype
)
def_val
)
.
astype
(
r
.
type
.
dtype
)
if
reuse_outputs
:
if
reuse_outputs
:
...
@@ -1259,7 +1259,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
...
@@ -1259,7 +1259,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
new_buf
=
r
.
type
.
value_zeros
(
r_vals
[
r
]
.
shape
)
new_buf
=
r
.
type
.
value_zeros
(
r_vals
[
r
]
.
shape
)
# CudaNdarray don't have flags field
# CudaNdarray don't have flags field
# assert new_buf.flags["C_CONTIGUOUS"]
# assert new_buf.flags["C_CONTIGUOUS"]
new_buf
[
...
]
=
n
umpy
.
asarray
(
def_val
)
.
astype
(
r
.
type
.
dtype
)
new_buf
[
...
]
=
n
p
.
asarray
(
def_val
)
.
astype
(
r
.
type
.
dtype
)
c_cont_outputs
[
r
]
=
new_buf
c_cont_outputs
[
r
]
=
new_buf
...
@@ -1273,7 +1273,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
...
@@ -1273,7 +1273,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
f_cont_outputs
=
{}
f_cont_outputs
=
{}
for
r
in
considered_outputs
:
for
r
in
considered_outputs
:
if
isinstance
(
r
.
type
,
(
TensorType
,
CudaNdarrayType
)):
if
isinstance
(
r
.
type
,
(
TensorType
,
CudaNdarrayType
)):
new_buf
=
n
umpy
.
zeros
(
new_buf
=
n
p
.
zeros
(
shape
=
r_vals
[
r
]
.
shape
,
shape
=
r_vals
[
r
]
.
shape
,
dtype
=
r_vals
[
r
]
.
dtype
,
dtype
=
r_vals
[
r
]
.
dtype
,
order
=
'F'
)
order
=
'F'
)
...
@@ -1331,7 +1331,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
...
@@ -1331,7 +1331,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
else
:
else
:
buf_shape
.
append
(
s
*
2
)
buf_shape
.
append
(
s
*
2
)
new_buf
=
r
.
type
.
value_zeros
(
buf_shape
)
new_buf
=
r
.
type
.
value_zeros
(
buf_shape
)
new_buf
[
...
]
=
n
umpy
.
asarray
(
def_val
)
.
astype
(
r
.
type
.
dtype
)
new_buf
[
...
]
=
n
p
.
asarray
(
def_val
)
.
astype
(
r
.
type
.
dtype
)
init_strided
[
r
]
=
new_buf
init_strided
[
r
]
=
new_buf
# The number of combinations is exponential in the number of
# The number of combinations is exponential in the number of
...
@@ -1377,7 +1377,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
...
@@ -1377,7 +1377,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
r_buf
=
r_buf
[
tuple
(
strides
)][
tuple
(
shapes
)]
r_buf
=
r_buf
[
tuple
(
strides
)][
tuple
(
shapes
)]
assert
r_buf
.
shape
==
r_vals
[
r
]
.
shape
assert
r_buf
.
shape
==
r_vals
[
r
]
.
shape
r_buf
[
...
]
=
n
umpy
.
asarray
(
def_val
)
.
astype
(
r_buf
.
dtype
)
r_buf
[
...
]
=
n
p
.
asarray
(
def_val
)
.
astype
(
r_buf
.
dtype
)
strided
[
r
]
=
r_buf
strided
[
r
]
=
r_buf
if
strided
:
if
strided
:
...
@@ -1405,7 +1405,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
...
@@ -1405,7 +1405,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
for
s
,
sd
in
zip
(
r_vals
[
r
]
.
shape
,
for
s
,
sd
in
zip
(
r_vals
[
r
]
.
shape
,
r_shape_diff
)]
r_shape_diff
)]
new_buf
=
r
.
type
.
value_zeros
(
out_shape
)
new_buf
=
r
.
type
.
value_zeros
(
out_shape
)
new_buf
[
...
]
=
n
umpy
.
asarray
(
new_buf
[
...
]
=
n
p
.
asarray
(
def_val
)
.
astype
(
r
.
type
.
dtype
)
def_val
)
.
astype
(
r
.
type
.
dtype
)
wrong_size
[
r
]
=
new_buf
wrong_size
[
r
]
=
new_buf
...
@@ -2261,7 +2261,7 @@ class _Linker(gof.link.LocalLinker):
...
@@ -2261,7 +2261,7 @@ class _Linker(gof.link.LocalLinker):
# HACK TO LOOK LIKE A REAL DESTRUCTIVE ACTION
# HACK TO LOOK LIKE A REAL DESTRUCTIVE ACTION
# TOOK PLACE
# TOOK PLACE
if
((
type
(
dr_vals
[
r
][
0
])
in
if
((
type
(
dr_vals
[
r
][
0
])
in
(
n
umpy
.
ndarray
,
numpy
.
memmap
))
and
(
n
p
.
ndarray
,
np
.
memmap
))
and
(
dr_vals
[
r
][
0
]
.
dtype
==
(
dr_vals
[
r
][
0
]
.
dtype
==
storage_map
[
r
][
0
]
.
dtype
)
and
storage_map
[
r
][
0
]
.
dtype
)
and
(
dr_vals
[
r
][
0
]
.
shape
==
(
dr_vals
[
r
][
0
]
.
shape
==
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论