提交 2ce65dc3 authored 作者: Frederic Bastien's avatar Frederic Bastien

Crash fix in GpuIncSubtensor andd make *subtensor* tests use the GPU mode more frequently.

上级 63ef2ead
...@@ -232,7 +232,7 @@ class GpuIncSubtensor(IncSubtensor): ...@@ -232,7 +232,7 @@ class GpuIncSubtensor(IncSubtensor):
if not self.set_instead_of_inc: if not self.set_instead_of_inc:
# sub_x += y # sub_x += y
iadd = get_iadd(node.inputs[0], node.inputs[1]) iadd = get_iadd(node.inputs[0], node.inputs[1])
iadd(sub_x, y, broadcast=False) iadd(sub_x, y)
else: else:
# sub_x[...] = y # sub_x[...] = y
x.__setitem__(cdata, y) x.__setitem__(cdata, y)
......
...@@ -524,10 +524,11 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -524,10 +524,11 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
gn = theano.grad(t.sum(), n) gn = theano.grad(t.sum(), n)
g = self.function([], gn, op=self.adv_incsub1) g = self.function([], gn, op=self.adv_incsub1)
utt.verify_grad(lambda m: m[[1, 3]], utt.verify_grad(lambda m: m[[1, 3]],
[np.random.rand(5, 5).astype(self.dtype)]) [np.random.rand(5, 5).astype(self.dtype)],
mode=self.mode)
g() g()
utt.verify_grad(lambda m: m[idx], utt.verify_grad(lambda m: m[idx],
[data]) [data], mode=self.mode)
def test_noncontiguous_idx(self): def test_noncontiguous_idx(self):
data = rand(4, 2, 3) data = rand(4, 2, 3)
...@@ -597,17 +598,20 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -597,17 +598,20 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
self.assertTrue(np.allclose(g_00, 2)) self.assertTrue(np.allclose(g_00, 2))
utt.verify_grad(lambda m: m[[1, 3]], utt.verify_grad(lambda m: m[[1, 3]],
[np.random.rand(5, 5).astype(self.dtype)]) [np.random.rand(5, 5).astype(self.dtype)],
mode=self.mode)
def fun(x, y): def fun(x, y):
return advanced_inc_subtensor1(x, y, [1, 3]) return advanced_inc_subtensor1(x, y, [1, 3])
utt.verify_grad(fun, [np.random.rand(5, 5).astype(self.dtype), utt.verify_grad(fun, [np.random.rand(5, 5).astype(self.dtype),
np.random.rand(2, 5).astype(self.dtype)]) np.random.rand(2, 5).astype(self.dtype)],
mode=self.mode)
def fun(x, y): def fun(x, y):
return advanced_set_subtensor1(x, y, [1, 3]) return advanced_set_subtensor1(x, y, [1, 3])
utt.verify_grad(fun, [np.random.rand(5, 5).astype(self.dtype), utt.verify_grad(fun, [np.random.rand(5, 5).astype(self.dtype),
np.random.rand(2, 5).astype(self.dtype)]) np.random.rand(2, 5).astype(self.dtype)],
mode=self.mode)
# test set_subtensor broadcast # test set_subtensor broadcast
self.dtype = 'float32' self.dtype = 'float32'
...@@ -872,12 +876,12 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -872,12 +876,12 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
def fct(t): def fct(t):
return theano.tensor.sum(t[idx_]) return theano.tensor.sum(t[idx_])
utt.verify_grad(fct, [data]) utt.verify_grad(fct, [data], mode=self.mode)
# Test the grad of the grad (e.i. AdvancedIncSubtensor1.grad) # Test the grad of the grad (e.i. AdvancedIncSubtensor1.grad)
def fct2(t): def fct2(t):
return theano.tensor.grad(theano.tensor.sum(t[idx_]), t) return theano.tensor.grad(theano.tensor.sum(t[idx_]), t)
utt.verify_grad(fct2, [data]) utt.verify_grad(fct2, [data], mode=self.mode)
# Test shape of AdvancedIncSubtensor1 and AdvancedSubtensor1 # Test shape of AdvancedIncSubtensor1 and AdvancedSubtensor1
if not self.fast_compile: if not self.fast_compile:
...@@ -958,7 +962,8 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -958,7 +962,8 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
# vector # vector
utt.verify_grad( utt.verify_grad(
inc_slice(slice(2, 4, None)), inc_slice(slice(2, 4, None)),
(np.asarray([0, 1, 2, 3, 4, 5.]), np.asarray([9, 9.]),)) (np.asarray([0, 1, 2, 3, 4, 5.]), np.asarray([9, 9.]),),
mode=self.mode)
# matrix # matrix
utt.verify_grad( utt.verify_grad(
...@@ -1640,17 +1645,20 @@ class TestAdvancedSubtensor(unittest.TestCase): ...@@ -1640,17 +1645,20 @@ class TestAdvancedSubtensor(unittest.TestCase):
self.assertTrue(isinstance(t.owner.op, tensor.AdvancedSubtensor)) self.assertTrue(isinstance(t.owner.op, tensor.AdvancedSubtensor))
utt.verify_grad(lambda m: m[[1, 3], [2, 4]], utt.verify_grad(lambda m: m[[1, 3], [2, 4]],
[np.random.rand(5, 5).astype(self.dtype)]) [np.random.rand(5, 5).astype(self.dtype)],
mode=self.mode)
def fun(x, y): def fun(x, y):
return advanced_inc_subtensor(x, y, [1, 3], [2, 4]) return advanced_inc_subtensor(x, y, [1, 3], [2, 4])
utt.verify_grad(fun, [np.random.rand(5, 5).astype(self.dtype), utt.verify_grad(fun, [np.random.rand(5, 5).astype(self.dtype),
np.random.rand(2).astype(self.dtype)]) np.random.rand(2).astype(self.dtype)],
mode=self.mode)
def fun(x, y): def fun(x, y):
return advanced_set_subtensor(x, y, [1, 3], [2, 4]) return advanced_set_subtensor(x, y, [1, 3], [2, 4])
utt.verify_grad(fun, [np.random.rand(5, 5).astype(self.dtype), utt.verify_grad(fun, [np.random.rand(5, 5).astype(self.dtype),
np.random.rand(2).astype(self.dtype)]) np.random.rand(2).astype(self.dtype)],
mode=self.mode)
class TestInferShape(utt.InferShapeTester): class TestInferShape(utt.InferShapeTester):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论