3 This package provides a function that generates a dot file from the
10 ### agtree2dot.save_dot(variable, variable_labels, result_file) ###
12 Saves into `result_file` a dot file corresponding to the auto-grad 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.
16 A typical use would be:
22 from torch.nn import functional as fn
23 from torch import Tensor
24 from torch.autograd import Variable
25 from torch.nn import Module
30 def __init__(self, input_dim, hidden_dim, output_dim):
31 super(MLP, self).__init__()
32 self.fc1 = nn.Linear(input_dim, hidden_dim)
33 self.fc2 = nn.Linear(hidden_dim, output_dim)
42 input = Variable(Tensor(100, 10).normal_())
43 target = Variable(Tensor(100).normal_())
45 criterion = nn.MSELoss()
46 loss = criterion(output, target)
48 agtree2dot.save_dot(loss,
49 { input: 'input', target: 'target', loss: 'loss' },
50 open('./mlp.dot', 'w'))
53 which would generate a file mlp.dot, which can then be translated to pdf with
56 dot mlp.dot -Lg -T pdf -o mlp.pdf
59 to produce [mlp.pdf](https://fleuret.org/git-extract/agtree2dot/mlp.pdf).