Theano provides a function to print a graph before and after compilation:
Theano provides two functions to print a graph to the terminal before or after
compilation. It can print graph that only have one output. If you have multiple
output, call once for each output. Their is another one that create a png image
of the function. It support multiple output.
1) The first is ``theano.pp``. It hide some Op added by the compiler as the
*DimShuffle Op used for the broadcast.
>>> x = T.dscalar('x')
>>> y = x**2
...
...
@@ -55,13 +61,63 @@ Theano provides a function to print a graph before and after compilation:
>>> pp(f.maker.env.outputs[0])
'(2.0 * x)'
The parameter in T.dscalar('x') in the first line is the name of this variable(in the graph, not in python). This name is reused when printing the graph. Otherwise the variable x is printed as its type as: <TensorType(float64, scalar)>. That is not the most comprehensible. The string 'x' can be any string, but to make the code more comprehensible, try to pass the same name or derivative of the name in python.
The parameter in T.dscalar('x') in the first line is the name of this variable
in the graph. This name is used when printing the graph to make it more readable.
If no name is provided the variable x is printed as its type as. In this example
<TensorType(float64, scalar)>.
The name parameter can be any string. Their is absolutly no restriction.
This mean you can have many variable with the same name.
To make the code more comprehensible, try to give the name parameter the same name as what you use in the code.
2)The second fonction to print a graph is `theano.printing.debugprint`(Variable, depth=-1)
:param fct: the theano fct returned by theano.function.
:param outfile: the output file where to put the graph.
In the graph, box are an Apply Node(the execution of an op) and elipse are variable.
If variable have name they are used as the text(if multiple var have the same name, they will be merged in the graph). Otherwise, if a constant, we print the value and finaly we print the type + an uniq number to don't have multiple var merged.
In the graph, box are an Apply Node(the execution of an op) and ellipse are variable.
If variable have name they are used as the text(if multiple var have the same name, they will be merged in the graph).
Otherwise, if the variable is constant, we print the value and finaly we print the type + an uniq number to don't have multiple var merged.
We print the op of the apply in the Apply box with a number that represent the toposort order of application of those Apply.
green ellipse are input to the graph and blue ellipse are output of the graph.
@@ -3209,8 +3209,8 @@ class AdvancedIncSubtensor(Op):
broadcastable=x.type.broadcastable)])
raiseNotImplementedError('Advanced indexing increment of x (of dimension %i) by y (of dimension %i) with these argument dimensions (%s) not supported yet'\