3 This package provides a function that generates a
4 [dot file](https://en.wikipedia.org/wiki/DOT_(graph_description_language))
5 from a [pytorch](http://pytorch.org) autograd graph.
11 ### agtree2dot.save_dot(variable, variable_labels, result_file) ###
13 Saves into `result_file` a dot file corresponding to the autograd graph for `variable`, which can be either a single `Variable` or a set of `Variable`s. The dictionary `variable_labels` associates strings to some variables, which will be used in the resulting graph.
17 A typical use would be:
23 from torch.nn import functional as fn
24 from torch import Tensor
25 from torch.autograd import Variable
26 from torch.nn import Module
31 def __init__(self, input_dim, hidden_dim, output_dim):
32 super(MLP, self).__init__()
33 self.fc1 = nn.Linear(input_dim, hidden_dim)
34 self.fc2 = nn.Linear(hidden_dim, output_dim)
43 input = Variable(Tensor(100, 10).normal_())
44 target = Variable(Tensor(100).normal_())
46 criterion = nn.MSELoss()
47 loss = criterion(output, target)
49 agtree2dot.save_dot(loss,
50 { input: 'input', target: 'target', loss: 'loss' },
51 open('./mlp.dot', 'w'))
54 which would generate a file mlp.dot, which can then be translated to
55 pdf using the [Graphviz tools](http://www.graphviz.org/)
58 dot mlp.dot -Lg -T pdf -o mlp.pdf
61 to produce [mlp.pdf.](https://fleuret.org/git-extract/agtree2dot/mlp.pdf)