giagrad.display#

giagrad.display.draw_dot(root, rankdir='LR', **options)[source]#

Returns autograd computational graph as a pygraphviz.Digraph object.

Every node is either an operator or a tensor, when shape is True data is not displayed, grad can be displayed if it is specified. For backward pass visualization retain_graph must be enabled, otherwise the computational graph will be deleted, see backward().

Parameters:

rankdir (str, default: 'LR') – Direction to draw the graph, see Graphviz rankdir.

Keyword Arguments:
  • shape (bool, default: False) – Display the shape of the tensor and its name.

  • grad (bool, default: False) – Display gradient when shape is False.

Examples

>>> from giagrad.display import draw_dot
>>> a = Tensor([[-1.,-2.],[3.,-4.],[-5.,6.]],
...           requires_grad=True, name='a')
>>> b = a.mean()
>>> b.name = 'b'
>>> a2 = a.exp()
>>> a2.name = "a'"
>>> c = Tensor([[2.,2.],[2.,2.],[3.,3.]],
...           requires_grad=True, name='c')
>>> c = c * a2.log().relu()
>>> c.name = "c'"
>>> d = b * c
>>> d.name = 'd'
>>> e = Tensor([[5.,5.,5.]],
...           requires_grad=True, name='e')
>>> f = e @ d
>>> f.name = 'f'
>>> g = f.sum()
>>> g.name = 'g'
>>> draw_dot(g, rankdir='TB')