Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
420a9b83
提交
420a9b83
authored
6月 13, 2016
作者:
Pascal Lamblin
提交者:
GitHub
6月 13, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4376 from adbrebs/fix_stack_check_nnet
[WIP] Use check_stack_trace helper function in tensor/nnet/tests/
上级
b3f54e3a
8be3b304
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
53 行增加
和
28 行删除
+53
-28
nnet.py
theano/tensor/nnet/nnet.py
+3
-1
sigm.py
theano/tensor/nnet/sigm.py
+9
-2
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+28
-15
test_conv3d2d.py
theano/tensor/nnet/tests/test_conv3d2d.py
+5
-5
test_nnet.py
theano/tensor/nnet/tests/test_nnet.py
+0
-0
test_opt.py
theano/tensor/nnet/tests/test_opt.py
+8
-5
test_sigm.py
theano/tensor/nnet/tests/test_sigm.py
+0
-0
没有找到文件。
theano/tensor/nnet/nnet.py
浏览文件 @
420a9b83
...
...
@@ -905,9 +905,11 @@ def softmax_simplifier(numerators, denominators):
matching_denom
=
denominator
break
if
matching_denom
:
softmax
=
softmax_op
(
x
)
copy_stack_trace
(
numerator
,
softmax
)
numerators
.
remove
(
numerator
)
denominators
.
remove
(
matching_denom
)
numerators
.
append
(
softmax
_op
(
x
)
)
numerators
.
append
(
softmax
)
return
numerators
,
denominators
opt
.
local_mul_canonizer
.
add_simplifier
(
softmax_simplifier
,
'softmax_simplifier'
)
...
...
theano/tensor/nnet/sigm.py
浏览文件 @
420a9b83
...
...
@@ -612,6 +612,7 @@ def local_exp_over_1_plus_exp(node):
else
:
# case: 1/(1+exp(x))
sigmoids
.
append
(
sigmoid
(
-
t
))
copy_stack_trace
(
node
.
outputs
[
0
],
sigmoids
[
-
1
])
if
not
sigmoids
:
# we didn't find any. abort
return
...
...
@@ -625,12 +626,17 @@ def local_exp_over_1_plus_exp(node):
if
num_neg
^
denom_neg
:
new_num
=
-
new_num
copy_stack_trace
(
num
,
new_num
)
if
len
(
denom_rest
)
==
0
:
return
[
new_num
]
elif
len
(
denom_rest
)
==
1
:
return
[
new_num
/
denom_rest
[
0
]
]
out
=
new_num
/
denom_rest
[
0
]
else
:
return
[
new_num
/
tensor
.
mul
(
*
denom_rest
)]
out
=
new_num
/
tensor
.
mul
(
*
denom_rest
)
copy_stack_trace
(
node
.
outputs
[
0
],
out
)
return
[
out
]
def
parse_mul_tree
(
root
):
...
...
@@ -923,6 +929,7 @@ def local_sigm_times_exp(node):
exp(x) * sigm(-x) -> sigm(x)
exp(-x) * sigm(x) -> sigm(-x)
todo: add stack traces to the intermediate variables
"""
# Bail early if it is not a multiplication.
if
node
.
op
!=
tensor
.
mul
:
...
...
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
420a9b83
...
...
@@ -7,6 +7,7 @@ from nose.tools import assert_raises
import
theano
from
theano
import
tensor
from
theano.gof.opt
import
check_stack_trace
from
theano.tests
import
unittest_tools
as
utt
from
theano.tensor.nnet
import
corr
,
abstract_conv
as
conv
from
theano.tensor.nnet.abstract_conv
import
get_conv_output_shape
...
...
@@ -98,7 +99,7 @@ class BaseTestConv2d(unittest.TestCase):
def
run_fwd
(
self
,
inputs_shape
,
filters_shape
,
ref
=
conv_corr
,
subsample
=
(
1
,
1
),
verify_grad
=
True
,
mode
=
None
,
border_mode
=
'valid'
,
filter_flip
=
True
,
provide_shape
=
False
,
target_op
=
None
):
target_op
=
None
,
check_trace
=
False
):
inputs_val
=
numpy
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
filters_val
=
numpy
.
random
.
random
(
filters_shape
)
.
astype
(
'float32'
)
...
...
@@ -133,8 +134,9 @@ class BaseTestConv2d(unittest.TestCase):
if
target_op
is
not
None
:
assert
any
([
isinstance
(
n
.
op
,
target_op
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()])
if
check_trace
:
self
.
assertTrue
(
check_stack_trace
(
f
,
ops_to_check
=
target_op
))
self
.
assertTrue
(
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
))
res_ref
=
numpy
.
array
(
f_ref
())
res
=
numpy
.
array
(
f
())
utt
.
assert_allclose
(
res_ref
,
res
)
...
...
@@ -148,7 +150,7 @@ class BaseTestConv2d(unittest.TestCase):
def
run_gradweight
(
self
,
inputs_shape
,
filters_shape
,
output_shape
,
ref
=
conv_corr_gw
,
subsample
=
(
1
,
1
),
filter_flip
=
True
,
verify_grad
=
True
,
mode
=
None
,
border_mode
=
'valid'
,
provide_shape
=
False
,
target_op
=
None
):
provide_shape
=
False
,
target_op
=
None
,
check_trace
=
False
):
inputs_val
=
numpy
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
output_val
=
numpy
.
random
.
random
(
output_shape
)
.
astype
(
'float32'
)
...
...
@@ -177,12 +179,13 @@ class BaseTestConv2d(unittest.TestCase):
subsample
=
subsample
,
conv_mode
=
conv_mode
)
f
=
theano
.
function
([],
c
,
mode
=
mode
)
self
.
assertTrue
(
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
))
f_ref
=
theano
.
function
([],
c_ref
,
mode
=
'FAST_RUN'
)
if
target_op
is
not
None
:
assert
any
([
isinstance
(
n
.
op
,
target_op
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()])
if
check_trace
:
self
.
assertTrue
(
check_stack_trace
(
f
,
ops_to_check
=
target_op
))
res_ref
=
numpy
.
array
(
f_ref
())
res
=
numpy
.
array
(
f
())
...
...
@@ -201,7 +204,7 @@ class BaseTestConv2d(unittest.TestCase):
def
run_gradinput
(
self
,
inputs_shape
,
filters_shape
,
output_shape
,
ref
=
conv_corr_gi
,
subsample
=
(
1
,
1
),
filter_flip
=
True
,
verify_grad
=
True
,
mode
=
None
,
border_mode
=
'valid'
,
provide_shape
=
False
,
target_op
=
None
):
provide_shape
=
False
,
target_op
=
None
,
check_trace
=
False
):
output_val
=
numpy
.
random
.
random
(
output_shape
)
.
astype
(
'float32'
)
filters_val
=
numpy
.
random
.
random
(
filters_shape
)
.
astype
(
'float32'
)
...
...
@@ -227,12 +230,13 @@ class BaseTestConv2d(unittest.TestCase):
border_mode
=
border_mode
,
subsample
=
subsample
,
conv_mode
=
conv_mode
)
f
=
theano
.
function
([],
c
,
mode
=
mode
)
self
.
assertTrue
(
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
))
f_ref
=
theano
.
function
([],
c_ref
,
mode
=
'FAST_RUN'
)
if
target_op
is
not
None
:
assert
any
([
isinstance
(
n
.
op
,
target_op
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()])
if
check_trace
:
self
.
assertTrue
(
check_stack_trace
(
f
,
ops_to_check
=
target_op
))
res_ref
=
numpy
.
array
(
f_ref
())
res
=
numpy
.
array
(
f
())
...
...
@@ -291,15 +295,18 @@ class TestCorrConv2d(BaseTestConv2d):
raise
SkipTest
(
"Need blas to test conv2d"
)
self
.
run_fwd
(
inputs_shape
=
i
,
filters_shape
=
f
,
subsample
=
s
,
verify_grad
=
True
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
CorrMM
)
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
CorrMM
,
check_trace
=
True
)
self
.
run_gradweight
(
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
True
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
CorrMM_gradWeights
)
filter_flip
=
flip
,
target_op
=
CorrMM_gradWeights
,
check_trace
=
True
)
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
True
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
CorrMM_gradInputs
)
filter_flip
=
flip
,
target_op
=
CorrMM_gradInputs
,
check_trace
=
True
)
class
TestCpuConv2d
(
BaseTestConv2d
):
...
...
@@ -343,7 +350,8 @@ class TestCpuConv2d(BaseTestConv2d):
self
.
run_fwd
(
inputs_shape
=
i
,
filters_shape
=
f
,
subsample
=
s
,
verify_grad
=
(
gradweight_OK
and
gradinput_OK
),
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
ConvOp
)
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
ConvOp
,
check_trace
=
True
)
else
:
self
.
assertRaises
(
AssertionError
,
self
.
run_fwd
,
...
...
@@ -354,7 +362,8 @@ class TestCpuConv2d(BaseTestConv2d):
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
)
filter_flip
=
flip
,
check_trace
=
True
)
if
gradweight_OK
:
if
not
theano
.
config
.
blas
.
ldflags
:
...
...
@@ -364,7 +373,8 @@ class TestCpuConv2d(BaseTestConv2d):
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
(
ConvOp
,
ConvGrad3D
))
target_op
=
(
ConvOp
,
ConvGrad3D
),
check_trace
=
True
)
else
:
self
.
assertRaises
(
AssertionError
,
self
.
run_gradweight
,
...
...
@@ -376,7 +386,8 @@ class TestCpuConv2d(BaseTestConv2d):
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
)
filter_flip
=
flip
,
check_trace
=
True
)
if
gradinput_OK
:
if
not
theano
.
config
.
blas
.
ldflags
:
...
...
@@ -386,7 +397,8 @@ class TestCpuConv2d(BaseTestConv2d):
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
(
ConvOp
,
ConvTransp3D
))
target_op
=
(
ConvOp
,
ConvTransp3D
),
check_trace
=
True
)
else
:
self
.
assertRaises
(
AssertionError
,
self
.
run_gradinput
,
...
...
@@ -398,7 +410,8 @@ class TestCpuConv2d(BaseTestConv2d):
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
)
filter_flip
=
flip
,
check_trace
=
True
)
def
test_constant_shapes
():
...
...
theano/tensor/nnet/tests/test_conv3d2d.py
浏览文件 @
420a9b83
...
...
@@ -10,6 +10,7 @@ except ImportError:
from
six.moves
import
xrange
import
theano
from
theano.gof.opt
import
check_stack_trace
from
theano.tensor.nnet.conv3d2d
import
*
import
theano.tests.unittest_tools
as
utt
...
...
@@ -73,10 +74,11 @@ def pyconv3d(signals, filters):
r_i
+=
o_i
[
Tf2
:
o_i_sh0
-
Tf2
,
Hf2
:
-
Hf2
,
Wf2
:
-
Wf2
]
return
rval
def
check_diagonal_subtensor_view_traces
(
fn
):
for
apply_node
in
fn
.
maker
.
fgraph
.
apply_nodes
:
if
isinstance
(
apply_node
.
op
,
(
DiagonalSubtensor
,
IncDiagonalSubtensor
)):
assert
hasattr
(
apply_node
.
outputs
[
0
]
.
tag
,
'trace'
)
assert
check_stack_trace
(
fn
,
ops_to_check
=
(
DiagonalSubtensor
,
IncDiagonalSubtensor
))
def
test_conv3d
(
mode
=
mode_without_gpu
,
shared
=
theano
.
tensor
.
_shared
):
if
ndimage
is
None
:
...
...
@@ -150,7 +152,6 @@ def test_conv3d(mode=mode_without_gpu, shared=theano.tensor._shared):
newconv3d
=
theano
.
function
([],
[],
updates
=
{
s_output
:
out
},
mode
=
mode
)
check_diagonal_subtensor_view_traces
(
newconv3d
)
t0
=
time
.
time
()
newconv3d
()
...
...
@@ -162,7 +163,6 @@ def test_conv3d(mode=mode_without_gpu, shared=theano.tensor._shared):
(
s_signals
,
gsignals
)],
mode
=
mode
,
name
=
'grad'
)
check_diagonal_subtensor_view_traces
(
gnewconv3d
)
t0
=
time
.
time
()
gnewconv3d
()
...
...
theano/tensor/nnet/tests/test_nnet.py
浏览文件 @
420a9b83
差异被折叠。
点击展开。
theano/tensor/nnet/tests/test_opt.py
浏览文件 @
420a9b83
from
__future__
import
absolute_import
,
print_function
,
division
import
theano
from
theano
import
tensor
from
theano.tensor.nnet.blocksparse
import
sparse_block_dot
from
theano.gof.opt
import
check_stack_trace
from
theano.tensor.nnet.blocksparse
import
(
sparse_block_dot
,
sparse_block_gemv_inplace
,
sparse_block_outer_inplace
,
sparse_block_gemv
,
sparse_block_outer
)
def
test_blocksparse_inplace_gemv_opt
():
...
...
@@ -14,12 +17,13 @@ def test_blocksparse_inplace_gemv_opt():
o
=
sparse_block_dot
(
W
,
h
,
iIdx
,
b
,
oIdx
)
f
=
theano
.
function
([
W
,
h
,
iIdx
,
b
,
oIdx
],
o
)
assert
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
)
if
theano
.
config
.
mode
==
"FAST_COMPILE"
:
assert
not
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
.
inplace
assert
check_stack_trace
(
f
,
ops_to_check
=
[
sparse_block_gemv
])
else
:
assert
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
.
inplace
assert
check_stack_trace
(
f
,
ops_to_check
=
[
sparse_block_gemv_inplace
])
def
test_blocksparse_inplace_outer_opt
():
...
...
@@ -31,13 +35,12 @@ def test_blocksparse_inplace_outer_opt():
o
=
sparse_block_dot
(
W
,
h
,
iIdx
,
b
,
oIdx
)
theano
.
printing
.
debugprint
(
tensor
.
grad
(
o
.
sum
(),
wrt
=
W
))
f
=
theano
.
function
([
W
,
h
,
iIdx
,
b
,
oIdx
],
[
o
,
tensor
.
grad
(
o
.
sum
(),
wrt
=
W
)])
assert
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
)
if
theano
.
config
.
mode
==
"FAST_COMPILE"
:
assert
not
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
.
inplace
assert
check_stack_trace
(
f
,
ops_to_check
=
sparse_block_outer
)
else
:
assert
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
.
inplace
assert
check_stack_trace
(
f
,
ops_to_check
=
sparse_block_outer_inplace
)
theano/tensor/nnet/tests/test_sigm.py
浏览文件 @
420a9b83
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论