提交 640f8956 authored 作者: Li's avatar Li 提交者: Frederic

test case for graph caching

上级 795ded70
......@@ -1068,6 +1068,7 @@ class FunctionMaker(object):
theano.config.compute_test_value = theano.config.compute_test_value_opt
gof.Op.add_stack_trace_on_call = False
start_optimizer = time.time()
import ipdb; ipdb.set_trace()
optimizer_profile = optimizer(fgraph)
end_optimizer = time.time()
opt_time = end_optimizer - start_optimizer
......
......@@ -87,6 +87,11 @@ class FunctionGraph(utils.object2):
#TODO: document what variables are[not] set in the FunctionGraph when a feature
is added via the constructor. How constructed is the FunctionGraph?
Note: the intermediate nodes between 'inputs' and 'outputs' are not explicitely
passed.
:param inputs: inputs nodes of the graph, usually declared by the user
:param outputs: outputs nodes of the graph.
:param clone: If true, we will clone the graph. This is
useful to remove the constant cache problem.
......
......@@ -873,6 +873,7 @@ def is_same_graph(var1, var2, givens=None, debug=False):
# Get result from the merge-based function.
rval1 = is_same_graph_with_merge(var1=var1, var2=var2, givens=givens)
# Get result from the function `equal_computations` from scan_utils.
import ipdb;ipdb.set_trace()
use_equal_computations = True
if givens:
# We need to build the `in_xs` and `in_ys` lists. To do this, we need
......
import unittest
import theano
import theano.tensor as T
from theano.gof.graph import is_same_graph
from theano.scan_module.scan_utils import equal_computations
def graphs_equal(x, y):
# check if two graphs are equal
# x: outputs list of graph A
# y: outputs list of graph B
import ipdb; ipdb.set_trace()
while True:
pass
def test_graph_equivalence():
# Test if equivalent graphs are in fact equivalent
# by using some functions in Theano
# graph g1
g1_a = T.fmatrix('inputs')
g1_b = T.fmatrix('inputs')
g1_y = T.sum(g1_a+g1_b)
g1_yy = T.sum(g1_a + g1_b)
g2_x = T.fmatrix('inputs')
g2_y = g2_x.sum()
g3_a = T.fmatrix('inputs')
g3_b = T.fmatrix('inputs')
g3_y = T.sum(g3_a+g3_b)
assert is_same_graph(g1_y, g2_y) == False
# This does not work.
assert is_same_graph(g1_y, g1_y)
assert is_same_graph(g1_y, g1_yy)
assert is_same_graph(g1_y, g3_y, givens={g1_a: g3_a, g1_b: g3_b})
FunctionGraph([], g1_y)
#assert graphs_equal(g1_y, g3_y) == True
#assert graphs_equal(g1_y, g2_y) == False
def test_graph_optimization_caching():
#
x = T.fmatrix('inputs')
y = x.sum()
f = theano.function(inputs=[x],outputs=y)
if __name__ == '__main__':
#test_graph_optimization_caching()
test_graph_equivalence()
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论