Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
66b29241
提交
66b29241
authored
7月 11, 2015
作者:
Iulian Vlad Serban
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed stack trace copying for several local optimizations according to Pascal's advice.
上级
21d70281
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
37 行增加
和
32 行删除
+37
-32
opt.py
theano/tensor/opt.py
+37
-32
没有找到文件。
theano/tensor/opt.py
浏览文件 @
66b29241
...
...
@@ -62,22 +62,23 @@ theano.configparser.AddConfigVar('on_shape_error',
# Utilities
def
copy_stack_trace
(
from_var
,
to_var
):
"""
Copies the stack trace from one or more tensor variables to
one or more tensor variables.
Copies the stack trace from one or more tensor variables to
one or more tensor variables.
:param from_var: tensor variable or list of tensor variables to
:param from_var: tensor variable or list of tensor variables to
copy stack traces from.
:param to_var: tensor variable or list of tensor variables to
:param to_var: tensor variable or list of tensor variables to
copy stack traces to.
.. note:: The stacktrace is assumed to be of the form of a list of lists
of tuples. Each tuple contains the filename, line number, function name
and so on. Each list of tuples contains the truples belonging to a
.. note:: The stacktrace is assumed to be of the form of a list of lists
of tuples. Each tuple contains the filename, line number, function name
and so on. Each list of tuples contains the truples belonging to a
particular variable.
"""
# Store stack traces from from_var
tr
=
[]
if
type
(
from_var
)
is
list
:
...
...
@@ -547,6 +548,7 @@ def local_dimshuffle_lift(node):
copy_stack_trace
(
node
.
outputs
[
0
],
ret
)
return
[
ret
]
@register_canonicalize
@gof.local_optimizer
([
T
.
DimShuffle
])
def
local_lift_transpose_through_dot
(
node
):
...
...
@@ -572,12 +574,11 @@ def local_lift_transpose_through_dot(node):
# Output is dot product of transposed inputs in reverse order
ret
=
[
T
.
dot
(
y
.
T
,
x
.
T
)]
# Copy over stack trace to output from
x and y to outpu
t
copy_stack_trace
(
[
x
,
y
],
ret
)
# Copy over stack trace to output from
result of dot-produc
t
copy_stack_trace
(
node
.
inputs
[
0
],
ret
)
return
ret
@gof.local_optimizer
([
DimShuffle
])
def
dimshuffle_as_view
(
node
):
op
=
node
.
op
...
...
@@ -1422,11 +1423,10 @@ def local_shape_to_shape_i(node):
ret
=
shape_feature
.
make_vector_shape
(
node
.
inputs
[
0
])
# We need to copy over stack trace from input to output
copy_stack_trace
(
node
.
in
puts
[
0
],
ret
)
copy_stack_trace
(
node
.
out
puts
[
0
],
ret
)
return
[
ret
]
# TODO: Not sure what type of node we are expecting here
@register_specialize
@register_canonicalize
...
...
@@ -1441,7 +1441,7 @@ def local_track_shape_i(node):
# fgraph as we don't change it in the shapefeature internal
# structure.
assert
isinstance
(
node
.
op
,
Shape_i
)
replacement
=
shape_feature
.
scheduled
[
node
]
replacement
=
shape_feature
.
scheduled
[
node
]
return
[
shape_feature
.
shape_of
[
replacement
][
node
.
op
.
i
]]
...
...
@@ -1500,9 +1500,8 @@ def local_subtensor_make_vector(node):
values
=
list
(
map
(
int
,
list
(
idx
.
value
)))
ret
=
[
make_vector
(
*
[
x
.
owner
.
inputs
[
v
]
for
v
in
values
])]
# Copy over stack traces from each index to every element of new list?
# If yes, then same should be done for const_slice just below...
copy_stack_trace
([
x
.
owner
.
inputs
[
v
]
for
v
in
values
],
ret
)
# Copy over stack trace from previous output to new output
copy_stack_trace
(
node
.
outputs
[
0
],
ret
)
return
ret
else
:
raise
TypeError
(
'case not expected'
)
...
...
@@ -1540,21 +1539,21 @@ def local_useless_elemwise(node):
if
node
.
inputs
[
0
]
==
node
.
inputs
[
1
]:
# it is the same var in the graph. That will always be true
ret
=
[
T
.
fill
(
node
.
inputs
[
0
],
T
.
constant
(
1.0
,
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
))]
T
.
constant
(
1.0
,
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
))]
# Copy stack trace from input to constant output
copy_stack_trace
(
node
.
in
puts
[
0
],
ret
)
copy_stack_trace
(
node
.
out
puts
[
0
],
ret
)
return
ret
elif
node
.
op
.
scalar_op
==
theano
.
scalar
.
neq
and
len
(
node
.
inputs
)
==
2
:
if
node
.
inputs
[
0
]
==
node
.
inputs
[
1
]:
# it is the same var in the graph. That will always be false
ret
=
[
T
.
fill
(
node
.
inputs
[
0
],
T
.
constant
(
0.0
,
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
))]
T
.
constant
(
0.0
,
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
))]
# Copy stack trace from input to constant output
copy_stack_trace
(
node
.
in
puts
[
0
],
ret
)
copy_stack_trace
(
node
.
out
puts
[
0
],
ret
)
return
ret
elif
node
.
op
.
scalar_op
==
theano
.
scalar
.
mul
and
len
(
node
.
inputs
)
==
1
:
...
...
@@ -1580,6 +1579,7 @@ def local_alloc_unary(node):
x
=
a
.
owner
.
inputs
[
0
]
shp
=
a
.
owner
.
inputs
[
1
:]
v
=
node
.
op
(
x
)
copy_stack_trace
(
node
.
outputs
[
0
],
v
)
ret
=
T
.
alloc
(
T
.
cast
(
v
,
node
.
outputs
[
0
]
.
dtype
),
*
shp
)
# Is it really necessary to copy over stack trace here?
...
...
@@ -1643,7 +1643,7 @@ def local_func_inv(node):
for
inv_pair
in
inv_pairs
:
if
is_inverse_pair
(
node_op
,
prev_op
,
inv_pair
):
# We don't need to copy stack trace, because the optimization
# We don't need to copy stack trace, because the optimization
# is trivial and maintains the earlier stack trace
return
x
.
owner
.
inputs
...
...
@@ -1770,8 +1770,11 @@ def local_remove_useless_assert(node):
# We don't need to copy over any stack traces here
return
[
node
.
inputs
[
0
]]
if
len
(
cond
)
!=
len
(
node
.
inputs
)
-
1
:
# We don't need to copy over any stack traces here
return
[
assert_
(
node
.
inputs
[
0
],
*
cond
)]
ret
=
assert_
(
node
.
inputs
[
0
],
*
cond
)
# We copy over stack trace from the output of the original assert
copy_stack_trace
(
node
.
outputs
[
0
],
ret
)
return
[
ret
]
@gof.local_optimizer
([
Assert
])
...
...
@@ -1920,17 +1923,19 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
# We need to keep the dimshuffle. It could swap axes or
# add dimensions anywhere.
# Do we need to copy stack trace from alloc_input to new element here?
new_i
.
append
(
i
.
owner
.
op
(
alloc_input
))
r_i
=
i
.
owner
.
op
(
alloc_input
)
# Copy stack trace from i to new_i
copy_stack_trace
(
i
,
r_i
)
new_i
.
append
(
r_i
)
else
:
new_i
.
append
(
i
)
new_i
[
assert_op_idx
]
=
assert_op
ret
=
node
.
op
(
*
new_i
,
return_list
=
True
)
# Copy over stack trace from inputs to outputs.
# Maybe we want to do this elementwise to keep the trace cleaner,
# but that's not really clear.
copy_stack_trace
(
new_i
,
ret
)
# Copy over stack trace from previous outputs to new outputs.
copy_stack_trace
(
node
.
outputs
,
ret
)
return
ret
return
local_elemwise_alloc
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论