Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fa9a870d
提交
fa9a870d
authored
1月 24, 2017
作者:
Pascal Lamblin
提交者:
GitHub
1月 24, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4659 from julianser/master
Merged previous work implementing stack trace copy over and tests for…
上级
f21bd7d3
e0897668
全部展开
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
114 行增加
和
5 行删除
+114
-5
optimizations.txt
doc/optimizations.txt
+1
-1
fg.py
theano/gof/fg.py
+1
-1
link.py
theano/gof/link.py
+1
-1
opt.py
theano/tensor/opt.py
+0
-0
test_opt.py
theano/tensor/tests/test_opt.py
+111
-2
没有找到文件。
doc/optimizations.txt
浏览文件 @
fa9a870d
...
@@ -91,7 +91,7 @@ Optimization FAST_RUN FAST_COMPILE
...
@@ -91,7 +91,7 @@ Optimization FAST_RUN FAST_COMPILE
* ``f(fill(a,b), c) -> f(b, c)``
* ``f(fill(a,b), c) -> f(b, c)``
* ``f(fill(a, b), fill(c, d), e) -> fill(a, fill(c, f(b, d, e)))``
* ``f(fill(a, b), fill(c, d), e) -> fill(a, fill(c, f(b, d, e)))``
See :func:`opt.local_fill_
cut`, :func:`opt.local_fill_
sink`
See :func:`opt.local_fill_sink`
inc_subtensor serialization
inc_subtensor serialization
Incrementing a small subregion of a large tensor can be done quickly
Incrementing a small subregion of a large tensor can be done quickly
...
...
theano/gof/fg.py
浏览文件 @
fa9a870d
...
@@ -53,7 +53,7 @@ class MissingInputError(Exception):
...
@@ -53,7 +53,7 @@ class MissingInputError(Exception):
# The call to list is needed for Python 3
# The call to list is needed for Python 3
assert
list
(
kwargs
.
keys
())
==
[
"variable"
]
assert
list
(
kwargs
.
keys
())
==
[
"variable"
]
tr
=
getattr
(
list
(
kwargs
.
values
())[
0
]
.
tag
,
'trace'
,
[])
tr
=
getattr
(
list
(
kwargs
.
values
())[
0
]
.
tag
,
'trace'
,
[])
if
type
(
tr
)
is
list
and
len
(
tr
)
>
0
:
if
isinstance
(
tr
,
list
)
and
len
(
tr
)
>
0
:
sio
=
StringIO
()
sio
=
StringIO
()
print
(
"
\n
Backtrace when the variable is created:"
,
file
=
sio
)
print
(
"
\n
Backtrace when the variable is created:"
,
file
=
sio
)
for
subtr
in
list
(
kwargs
.
values
())[
0
]
.
tag
.
trace
:
for
subtr
in
list
(
kwargs
.
values
())[
0
]
.
tag
.
trace
:
...
...
theano/gof/link.py
浏览文件 @
fa9a870d
...
@@ -179,7 +179,7 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
...
@@ -179,7 +179,7 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
# Print node backtraces
# Print node backtraces
tr
=
getattr
(
node
.
outputs
[
0
]
.
tag
,
'trace'
,
[])
tr
=
getattr
(
node
.
outputs
[
0
]
.
tag
,
'trace'
,
[])
if
type
(
tr
)
is
list
and
len
(
tr
)
>
0
:
if
isinstance
(
tr
,
list
)
and
len
(
tr
)
>
0
:
detailed_err_msg
+=
"
\n
Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer):
\n
"
detailed_err_msg
+=
"
\n
Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer):
\n
"
# Print separate message for each element in the list of batcktraces
# Print separate message for each element in the list of batcktraces
...
...
theano/tensor/opt.py
浏览文件 @
fa9a870d
差异被折叠。
点击展开。
theano/tensor/tests/test_opt.py
浏览文件 @
fa9a870d
...
@@ -3451,7 +3451,7 @@ def test_local_subtensor_of_alloc():
...
@@ -3451,7 +3451,7 @@ def test_local_subtensor_of_alloc():
def
test_local_fill_useless
():
def
test_local_fill_useless
():
# Test opt local_fill_
cut
# Test opt local_fill_
useless
x
=
dvector
()
x
=
dvector
()
y
=
dvector
()
y
=
dvector
()
z
=
lvector
()
z
=
lvector
()
...
@@ -3500,6 +3500,67 @@ def test_local_fill_useless():
...
@@ -3500,6 +3500,67 @@ def test_local_fill_useless():
f
(
m_
,
x_
)
f
(
m_
,
x_
)
def
test_local_elemwise_sub_zeros
():
# Test opt local_elemwise_sub_zeros
# We test separately for scalars, vectors and matrices
scalar
=
T
.
scalar
()
vect
=
T
.
vector
()
mat
=
T
.
matrix
()
rng
=
numpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
scalar_val
=
rng
.
rand
(
1
)
.
astype
(
config
.
floatX
)[
0
]
vect_val
=
rng
.
rand
(
5
)
.
astype
(
config
.
floatX
)
mat_val
=
rng
.
rand
(
3
,
2
)
.
astype
(
config
.
floatX
)
mode
=
theano
.
compile
.
get_default_mode
()
\
.
excluding
(
'canonicalize'
,
'uncanonicalize'
,
'ShapeOpt'
,
'local_fill_to_alloc'
,
'local_elemwise_alloc'
)
\
.
including
(
'local_elemwise_sub_zeros'
)
# Test scalar minus scalar
f
=
function
([
scalar
],
scalar
-
scalar
,
mode
=
mode
)
# Check optimized graph is correct
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
,
T
.
Elemwise
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
,
theano
.
scalar
.
Second
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
inputs
[
1
],
T
.
TensorConstant
)
or
\
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
inputs
[
1
],
T
.
TensorConstant
)
utt
.
assert_allclose
(
f
(
scalar_val
),
0.0
)
# Check stack trace is copied over
assert
check_stack_trace
(
f
,
ops_to_check
=
'all'
)
# Test vector minus vector
f
=
function
([
vect
],
vect
-
vect
,
mode
=
mode
)
# Check optimized graph is correct
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
,
T
.
Elemwise
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
,
theano
.
scalar
.
Second
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
inputs
[
1
],
T
.
TensorConstant
)
or
\
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
inputs
[
1
],
T
.
TensorConstant
)
utt
.
assert_allclose
(
f
(
vect_val
),
numpy
.
zeros
(
vect_val
.
shape
))
# Check stack trace is copied over
assert
check_stack_trace
(
f
,
ops_to_check
=
'all'
)
# Test vector minus vector
f
=
function
([
mat
],
mat
-
mat
,
mode
=
mode
)
# Check optimized graph is correct
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
,
T
.
Elemwise
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
,
theano
.
scalar
.
Second
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
inputs
[
1
],
T
.
TensorConstant
)
or
\
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
inputs
[
1
],
T
.
TensorConstant
)
utt
.
assert_allclose
(
f
(
mat_val
),
numpy
.
zeros
(
mat_val
.
shape
))
# Check stack trace is copied over
assert
check_stack_trace
(
f
,
ops_to_check
=
'all'
)
class
Test_local_useless_elemwise_comparison
(
unittest
.
TestCase
):
class
Test_local_useless_elemwise_comparison
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
@@ -3743,6 +3804,17 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
...
@@ -3743,6 +3804,17 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
f
=
theano
.
function
([
x
],
T
.
xor
(
x
,
x
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
xor
(
x
,
x
),
mode
=
mode
)
self
.
assert_eqs_const
(
f
,
0
)
self
.
assert_eqs_const
(
f
,
0
)
def
test_stacktrace
(
self
):
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'local_useless_elemwise_comparison'
)
x
=
T
.
vector
(
'x'
,
dtype
=
config
.
floatX
)
f
=
theano
.
function
([
x
],
T
.
gt
(
x
,
x
),
mode
=
mode
)
self
.
assertTrue
(
check_stack_trace
(
f
,
ops_to_check
=
'last'
))
f
=
theano
.
function
([
x
],
T
.
le
(
x
,
x
),
mode
=
mode
)
self
.
assertTrue
(
check_stack_trace
(
f
,
ops_to_check
=
'last'
))
class
Test_local_canonicalize_alloc
(
unittest
.
TestCase
):
class
Test_local_canonicalize_alloc
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -5604,6 +5676,35 @@ class T_local_sum_prod(unittest.TestCase):
...
@@ -5604,6 +5676,35 @@ class T_local_sum_prod(unittest.TestCase):
finally
:
finally
:
config
.
on_opt_error
=
backup
config
.
on_opt_error
=
backup
def
test_local_sum_prod_mul_by_scalar_stack_trace
(
self
):
# Test that stack trace is copied over correctly for local_sum_prod_mul_by_scalar.
m0
=
theano
.
compile
.
get_default_mode
()
\
.
excluding
(
'inplace_elemwise_opt'
)
\
.
including
(
'canonicalize'
,
'specialize'
)
vect
=
T
.
dvector
()
mat
=
T
.
dmatrix
()
scalar
=
T
.
dscalar
()
f
=
theano
.
function
([
vect
,
scalar
],
T
.
sum
(
vect
*
scalar
),
mode
=
m0
)
assert
check_stack_trace
(
f
,
ops_to_check
=
'all'
)
f
=
theano
.
function
([
vect
],
T
.
sum
(
-
vect
),
mode
=
m0
)
assert
check_stack_trace
(
f
,
ops_to_check
=
[
T
.
Sum
])
f
=
theano
.
function
([
vect
,
scalar
],
T
.
elemwise
.
Prod
()(
vect
*
scalar
),
mode
=
m0
)
assert
check_stack_trace
(
f
,
ops_to_check
=
[
T
.
elemwise
.
Prod
])
f
=
theano
.
function
([
vect
],
T
.
elemwise
.
Prod
()(
-
vect
),
mode
=
m0
)
assert
check_stack_trace
(
f
,
ops_to_check
=
[
T
.
elemwise
.
Prod
])
f
=
theano
.
function
([
mat
,
scalar
],
T
.
sum
(
mat
*
scalar
),
mode
=
m0
)
assert
check_stack_trace
(
f
,
ops_to_check
=
'all'
)
f
=
theano
.
function
([
mat
],
T
.
sum
(
-
mat
),
mode
=
m0
)
assert
check_stack_trace
(
f
,
ops_to_check
=
[
T
.
Sum
])
class
T_local_opt_alloc
(
unittest
.
TestCase
):
class
T_local_opt_alloc
(
unittest
.
TestCase
):
def
test_sum_upcast
(
self
):
def
test_sum_upcast
(
self
):
...
@@ -6287,6 +6388,9 @@ class Test_Reshape(unittest.TestCase):
...
@@ -6287,6 +6388,9 @@ class Test_Reshape(unittest.TestCase):
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
node
.
op
,
self
.
op
)
for
node
in
topo
)
==
1
assert
sum
(
isinstance
(
node
.
op
,
self
.
op
)
for
node
in
topo
)
==
1
# Check stack trace
self
.
assertTrue
(
check_stack_trace
(
f
,
ops_to_check
=
[
self
.
op
]))
class
Test_local_useless_reshape
(
unittest
.
TestCase
):
class
Test_local_useless_reshape
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -6316,6 +6420,9 @@ class Test_local_useless_reshape(unittest.TestCase):
...
@@ -6316,6 +6420,9 @@ class Test_local_useless_reshape(unittest.TestCase):
topo
=
f2
.
maker
.
fgraph
.
toposort
()
topo
=
f2
.
maker
.
fgraph
.
toposort
()
assert
not
any
(
isinstance
(
n
.
op
,
tensor
.
basic
.
Reshape
)
for
n
in
topo
)
assert
not
any
(
isinstance
(
n
.
op
,
tensor
.
basic
.
Reshape
)
for
n
in
topo
)
# We do not need tests checking that stack traces are copied over,
# because local_useless_reshape only removes nodes from the graph
def
test_2
(
self
):
def
test_2
(
self
):
x
=
theano
.
tensor
.
matrix
(
'x'
)
x
=
theano
.
tensor
.
matrix
(
'x'
)
r
=
x
.
reshape
([
Shape_i
(
i
)(
x
)
for
i
in
xrange
(
x
.
ndim
)])
r
=
x
.
reshape
([
Shape_i
(
i
)(
x
)
for
i
in
xrange
(
x
.
ndim
)])
...
@@ -6361,7 +6468,7 @@ class Test_local_reshape_to_dimshuffle(unittest.TestCase):
...
@@ -6361,7 +6468,7 @@ class Test_local_reshape_to_dimshuffle(unittest.TestCase):
"TensorConstant{[5 6]}))]"
)
"TensorConstant{[5 6]}))]"
)
# Check stacktrace was copied over correctly after opt was applied
# Check stacktrace was copied over correctly after opt was applied
check_stack_trace
(
g
,
ops_to_check
=
(
T
.
DimShuffle
,
T
.
Reshape
))
assert
check_stack_trace
(
g
,
ops_to_check
=
(
T
.
DimShuffle
,
T
.
Reshape
))
def
test_local_reshape_lift
():
def
test_local_reshape_lift
():
...
@@ -6375,6 +6482,8 @@ def test_local_reshape_lift():
...
@@ -6375,6 +6482,8 @@ def test_local_reshape_lift():
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
isinstance
(
topo
[
-
2
]
.
op
,
tensor
.
Reshape
)
assert
isinstance
(
topo
[
-
2
]
.
op
,
tensor
.
Reshape
)
assert
isinstance
(
topo
[
-
1
]
.
op
,
tensor
.
Elemwise
)
assert
isinstance
(
topo
[
-
1
]
.
op
,
tensor
.
Elemwise
)
# Check stacktrace was copied over correctly after opt was applied
assert
check_stack_trace
(
f
,
ops_to_check
=
'last'
)
class
Test_lift_transpose_through_dot
(
unittest
.
TestCase
):
class
Test_lift_transpose_through_dot
(
unittest
.
TestCase
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论