提交 efd4d4b9 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Merge pull request #3908 from vmichals/abstract_conv_keep_stacktrace

keep stacktrace in abstract_conv optimizations
...@@ -36,4 +36,4 @@ distribute-*.tar.gz ...@@ -36,4 +36,4 @@ distribute-*.tar.gz
Theano.suo Theano.suo
.ipynb_checkpoints .ipynb_checkpoints
.pydevproject .pydevproject
.ropeproject
...@@ -93,11 +93,13 @@ class TestConv2d(unittest.TestCase): ...@@ -93,11 +93,13 @@ class TestConv2d(unittest.TestCase):
assert any([isinstance(n.op, target_op) for n assert any([isinstance(n.op, target_op) for n
in f.maker.fgraph.toposort()]) in f.maker.fgraph.toposort()])
self.assertTrue(hasattr(f.maker.fgraph.outputs[0].tag, 'trace'))
res_ref = numpy.array(f_ref()) res_ref = numpy.array(f_ref())
res = numpy.array(f()) res = numpy.array(f())
utt.assert_allclose(res_ref, res) utt.assert_allclose(res_ref, res)
if verify_grad: if verify_grad:
utt.verify_grad(conv.AbstractConv2d(border_mode="valid", imshp=imshp, kshp=kshp, utt.verify_grad(conv.AbstractConv2d(border_mode="valid",
imshp=imshp, kshp=kshp,
subsample=subsample), subsample=subsample),
[inputs_val, filters_val], [inputs_val, filters_val],
mode=mode) mode=mode)
...@@ -136,6 +138,7 @@ class TestConv2d(unittest.TestCase): ...@@ -136,6 +138,7 @@ class TestConv2d(unittest.TestCase):
subsample=subsample, subsample=subsample,
conv_mode=conv_mode) conv_mode=conv_mode)
f = theano.function([], c, mode) f = theano.function([], c, mode)
self.assertTrue(hasattr(f.maker.fgraph.outputs[0].tag, 'trace'))
f_ref = theano.function([], c_ref, mode) f_ref = theano.function([], c_ref, mode)
if target_op is not None: if target_op is not None:
...@@ -186,6 +189,7 @@ class TestConv2d(unittest.TestCase): ...@@ -186,6 +189,7 @@ class TestConv2d(unittest.TestCase):
border_mode=border_mode, subsample=subsample, border_mode=border_mode, subsample=subsample,
conv_mode=conv_mode) conv_mode=conv_mode)
f = theano.function([], c, mode) f = theano.function([], c, mode)
self.assertTrue(hasattr(f.maker.fgraph.outputs[0].tag, 'trace'))
f_ref = theano.function([], c_ref, mode) f_ref = theano.function([], c_ref, mode)
if target_op is not None: if target_op is not None:
......
...@@ -17,7 +17,8 @@ from theano.tensor.nnet.abstract_conv import (AbstractConv2d, ...@@ -17,7 +17,8 @@ from theano.tensor.nnet.abstract_conv import (AbstractConv2d,
AbstractConv2d_gradWeights, AbstractConv2d_gradWeights,
AbstractConv2d_gradInputs) AbstractConv2d_gradInputs)
from theano.tensor.nnet.abstract_conv import get_conv_output_shape from theano.tensor.nnet.abstract_conv import get_conv_output_shape
from theano.tensor.opt import register_specialize_device from theano.tensor.opt import (copy_stack_trace,
register_specialize_device)
from theano.tensor import TensorType from theano.tensor import TensorType
# Cpu implementation # Cpu implementation
...@@ -75,6 +76,7 @@ def local_abstractconv_gemm(node): ...@@ -75,6 +76,7 @@ def local_abstractconv_gemm(node):
kern = kern[:, :, ::-1, ::-1] kern = kern[:, :, ::-1, ::-1]
rval = CorrMM(border_mode=node.op.border_mode, rval = CorrMM(border_mode=node.op.border_mode,
subsample=node.op.subsample)(img, kern) subsample=node.op.subsample)(img, kern)
copy_stack_trace(node.outputs[0], rval)
return [rval] return [rval]
...@@ -92,10 +94,13 @@ def local_abstractconv_gradweight_gemm(node): ...@@ -92,10 +94,13 @@ def local_abstractconv_gradweight_gemm(node):
rval = CorrMM_gradWeights(border_mode=node.op.border_mode, rval = CorrMM_gradWeights(border_mode=node.op.border_mode,
subsample=node.op.subsample)(img, topgrad, shape) subsample=node.op.subsample)(img, topgrad, shape)
copy_stack_trace(node.outputs[0], rval)
# need to flip the kernel if necessary # need to flip the kernel if necessary
if node.op.filter_flip: if node.op.filter_flip:
rval = rval[:, :, ::-1, ::-1] rval = rval[:, :, ::-1, ::-1]
rval = theano.tensor.patternbroadcast(rval, node.outputs[0].broadcastable) rval = theano.tensor.patternbroadcast(rval, node.outputs[0].broadcastable)
copy_stack_trace(node.outputs[0], rval)
return [rval] return [rval]
...@@ -117,6 +122,7 @@ def local_abstractconv_gradinputs_gemm(node): ...@@ -117,6 +122,7 @@ def local_abstractconv_gradinputs_gemm(node):
rval = CorrMM_gradInputs(border_mode=node.op.border_mode, rval = CorrMM_gradInputs(border_mode=node.op.border_mode,
subsample=node.op.subsample)(kern, topgrad, subsample=node.op.subsample)(kern, topgrad,
shape) shape)
copy_stack_trace(node.outputs[0], rval)
return [rval] return [rval]
...@@ -141,6 +147,8 @@ def local_conv2d_cpu(node): ...@@ -141,6 +147,8 @@ def local_conv2d_cpu(node):
node.op.imshp, node.op.kshp, node.op.imshp, node.op.kshp,
border_mode=node.op.border_mode, border_mode=node.op.border_mode,
subsample=node.op.subsample) subsample=node.op.subsample)
copy_stack_trace(node.outputs[0], rval)
return [rval] return [rval]
...@@ -175,12 +183,14 @@ def local_conv2d_gradweight_cpu(node): ...@@ -175,12 +183,14 @@ def local_conv2d_gradweight_cpu(node):
shape[0], shape[1], 1, shape[0], shape[1], 1,
shuffled_img.shape[4]), shuffled_img.shape[4]),
dCdH=shuffled_topgrad) dCdH=shuffled_topgrad)
copy_stack_trace(node.outputs[0], rval)
rval = theano.tensor.addbroadcast(rval, 3) rval = theano.tensor.addbroadcast(rval, 3)
rval = rval.dimshuffle(0, 4, 1, 2) rval = rval.dimshuffle(0, 4, 1, 2)
rval = rval[:, :, ::-1, ::-1] rval = rval[:, :, ::-1, ::-1]
rval = theano.tensor.patternbroadcast(rval, rval = theano.tensor.patternbroadcast(rval,
node.outputs[0].broadcastable) node.outputs[0].broadcastable)
copy_stack_trace(node.outputs[0], rval)
return [rval] return [rval]
dx, dy = node.op.subsample dx, dy = node.op.subsample
...@@ -246,11 +256,15 @@ def local_conv2d_gradweight_cpu(node): ...@@ -246,11 +256,15 @@ def local_conv2d_gradweight_cpu(node):
kshp_logical_top_aligned=kshp_logical_top_aligned, kshp_logical_top_aligned=kshp_logical_top_aligned,
direction_hint='bprop weights') direction_hint='bprop weights')
res = dw(img, filters) res = dw(img, filters)
copy_stack_trace(node.outputs[0], res)
if node.op.border_mode == 'valid': if node.op.border_mode == 'valid':
res = res.dimshuffle((1, 0, 2, 3)) res = res.dimshuffle((1, 0, 2, 3))
res = res[:, :, ::-1, ::-1] res = res[:, :, ::-1, ::-1]
res = theano.tensor.patternbroadcast(res, node.outputs[0].broadcastable) res = theano.tensor.patternbroadcast(res, node.outputs[0].broadcastable)
copy_stack_trace(node.outputs[0], res)
return [res] return [res]
...@@ -280,10 +294,13 @@ def local_conv2d_gradinputs_cpu(node): ...@@ -280,10 +294,13 @@ def local_conv2d_gradinputs_cpu(node):
d=(node.op.subsample[0], node.op.subsample[1], 1), d=(node.op.subsample[0], node.op.subsample[1], 1),
H=shuffled_topgrad, H=shuffled_topgrad,
RShape=(shape[0], shape[1], 1)) RShape=(shape[0], shape[1], 1))
copy_stack_trace(node.outputs[0], rval)
rval = theano.tensor.addbroadcast(rval, 3) rval = theano.tensor.addbroadcast(rval, 3)
rval = rval.dimshuffle(0, 4, 1, 2) rval = rval.dimshuffle(0, 4, 1, 2)
rval = theano.tensor.patternbroadcast(rval, rval = theano.tensor.patternbroadcast(rval,
node.outputs[0].broadcastable) node.outputs[0].broadcastable)
copy_stack_trace(node.outputs[0], rval)
return [rval] return [rval]
# Conv2d Implementation # Conv2d Implementation
...@@ -332,7 +349,9 @@ def local_conv2d_gradinputs_cpu(node): ...@@ -332,7 +349,9 @@ def local_conv2d_gradinputs_cpu(node):
version=-1, version=-1,
direction_hint='bprop inputs') direction_hint='bprop inputs')
din = din(topgrad, filters) din = din(topgrad, filters)
copy_stack_trace(node.outputs[0], din)
din = theano.tensor.patternbroadcast(din, node.outputs[0].broadcastable) din = theano.tensor.patternbroadcast(din, node.outputs[0].broadcastable)
copy_stack_trace(node.outputs[0], din)
return [din] return [din]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论