提交 3cb955ae authored 作者: Lijun Xue's avatar Lijun Xue

Merge test_reallocation into test_vm

上级 f603ef04
"Test of reduce allocation"
import unittest
import theano
import theano.tensor as T
class Test_reallocation(unittest.TestCase):
"""
Test of Theano reallocation
"""
def test_reallocation(self):
x = T.scalar('x')
y = T.scalar('y')
z = T.tanh(3 * x + y) + T.cosh(x + 5 * y)
m = theano.compile.get_mode(theano.Mode(linker='vm_nogc'))
m = m.excluding('fusion', 'inplace')
f = theano.function([x, y], z, name="test_reduce_memory",
mode=m)
output = f(1, 2)
assert output
storage_map = f.fn.storage_map
def check_storage(storage_map):
from theano.tensor.var import TensorConstant
for i in storage_map.keys():
if not isinstance(i, TensorConstant):
keys_copy = storage_map.keys()[:]
keys_copy.remove(i)
for o in keys_copy:
if (storage_map[i][0] and
storage_map[i][0] == storage_map[o][0]):
return [True, storage_map[o][0]]
return [False, None]
assert check_storage(storage_map)[0]
if __name__ == "__main__":
unittest.main()
...@@ -343,3 +343,32 @@ def test_vm_gc(): ...@@ -343,3 +343,32 @@ def test_vm_gc():
f = theano.function([x], [pp + pp], f = theano.function([x], [pp + pp],
mode=mode) mode=mode)
f([1, 2, 3]) f([1, 2, 3])
def test_reallocation():
x = tensor.scalar('x')
y = tensor.scalar('y')
z = tensor.tanh(3 * x + y) + tensor.cosh(x + 5 * y)
m = theano.compile.get_mode(theano.Mode(linker='vm_nogc'))
m = m.excluding('fusion', 'inplace')
f = theano.function([x, y], z, name="test_reduce_memory",
mode=m)
output = f(1, 2)
assert output
storage_map = f.fn.storage_map
def check_storage(storage_map):
from theano.tensor.var import TensorConstant
for i in storage_map.keys():
if not isinstance(i, TensorConstant):
keys_copy = storage_map.keys()[:]
keys_copy.remove(i)
for o in keys_copy:
if (storage_map[i][0] and
storage_map[i][0] == storage_map[o][0]):
return [True, storage_map[o][0]]
return [False, None]
assert check_storage(storage_map)[0]
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论