提交 2d8b62e1 authored 作者: Pierre Luc Carrier's avatar Pierre Luc Carrier

Add test case for Pascal's fix

上级 1a6b4072
...@@ -9,6 +9,7 @@ import cPickle ...@@ -9,6 +9,7 @@ import cPickle
import numpy import numpy
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from nose.tools import assert_raises
from numpy.testing import dec from numpy.testing import dec
import theano import theano
...@@ -3022,6 +3023,42 @@ class T_Scan(unittest.TestCase): ...@@ -3022,6 +3023,42 @@ class T_Scan(unittest.TestCase):
assert out[4] == 19 assert out[4] == 19
# 19.0 # 19.0
def test_crash_nonseq_grad(self):
# Test case was originally reported by Bitton Tenessi. It crashed
# during the grad operation and this tests validates that it now
# raises a NullTypeGradError instead because the gradient relies on
# the intermediary states of the random number generators used in the
# test. The test case was modified from the original for simplicity
rand_stream = tensor.shared_randomstreams.RandomStreams()
inp = tensor.matrix()
norm_inp = inp / tensor.sum(inp, axis=0)
def unit_dropout(out_idx):
def stochastic_pooling(in_idx):
# sample the input matrix for each column according to the
# column values
n = tensor.ones((inp.shape[1],))
pvals = norm_inp.T
pool_idx = rand_stream.multinomial(n=n, pvals=pvals)
pooled_row = inp.T[tensor.nonzero(pool_idx)]
return pooled_row.flatten()
pooled, updates_inner = theano.scan(fn=stochastic_pooling,
sequences=tensor.arange(inp.shape[0]))
# randomly dropout units with 50% probability
rand_nums = rand_stream.binomial(size=pooled.shape)
mask = tensor.nonzero(rand_nums)
masked = tensor.set_subtensor(pooled[mask], 0)
return tensor.max(masked, axis=0), updates_inner
out, updates_outer = theano.scan(unit_dropout,
sequences=[tensor.arange(inp.shape[0])])
assert_raises(theano.gradient.NullTypeGradError,
tensor.grad, out.sum(), inp)
def test_bugFunctioProvidesIntermediateNodesAsInputs(self): def test_bugFunctioProvidesIntermediateNodesAsInputs(self):
# This is a bug recently reported by Ilya # This is a bug recently reported by Ilya
# made it CPU friendly # made it CPU friendly
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论