4 This package implements a new module nn.DAG which inherits from
5 nn.Container and allows to combine modules in an arbitrary graph
10 A typical use would be:
15 a = nn.Linear(100, 10)
22 model:connect(b, nn.Linear(10, 15), nn.ReLU(), d)
25 model:connect(c, nn.Mul(-1), e)
28 model:setOutput({ d, e })
30 input = torch.Tensor(30, 100):uniform()
31 output = model:updateOutput(input)
35 which would encode the following graph
37 +- Linear(10, 10) -> ReLU ---> d -->
40 --> a --> b -----------> c --------------+
45 and run a forward pass with a random batch of 30 samples.
47 Note that DAG:connect allows to add a bunch of edges at once. This is
48 particularly useful to add anonymous modules which have a single
49 predecessor and successor.
53 If a node has a single predecessor, its output is taken as-is. If it
54 has multiple predecessors, all the outputs are collected into a table,
55 and the table is used as input. The indexes of the outputs in that
56 table reflects the order in which the predecessors appeared in the
57 DAG:connect() commands.
59 The input to the DAG (respectively the produced output) is a nested
60 table of inputs reflecting the structure of the nested table of
61 modules provided to DAG:setInput (respectively DAG:setOutput)
63 So for instance, in the example above, the model expects a tensor as
64 input, since it is the input to the module a, and its output will is a
65 table composed of two tensors, corresponding to the outputs of d and e
72 Create a new empty DAG, which inherits from nn.Container.
74 ##nn.DAG:connect([module1 [, module2 [, ...]]])##
76 Add new nodes corresponding to the modules passed as arguments if they
77 are not already existing. Add edges between every two nodes
78 corresponding to a pair of successive modules in the arguments.
80 ##nn.DAG:setInput(i)##
82 Defines the content and structure of the input. The argument should be
83 either a module, or a (nested) table of module. The input to the DAG
84 should be a (nested) table of inputs with the corresponding structure.
86 ##nn.DAG:setOutput(o)##
88 Similar to DAG:setInput().
92 Prints the list of nodes.
94 ##nn.DAG:saveDot(filename)##
96 Save a dot file to be used by the Graphviz set of tools for graph
97 visualization. This dot file can than be used for instance to produce
101 dot graph.dot -T pdf -o graph.pdf
104 ##nn.DAG:updateOutput(input)##
106 See the torch documentation.
108 ##nn.DAG:updateGradInput(input, gradOutput)##
110 See the torch documentation.
112 ##nn.DAG:accGradParameters(input, gradOutput, scale)##
114 See the torch documentation.
116 *Francois Fleuret, Jan 13th, 2017*