You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/design/graph.md
+21-2Lines changed: 21 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Design Doc: Computations as Graphs
1
+
# Design Doc: Computations as a Graph
2
2
3
3
A primary goal of the refactorization of PaddlePaddle is a more flexible representation of deep learning computation, in particular, a graph of operators and variables, instead of sequences of layers as before.
4
4
@@ -8,6 +8,8 @@ This document explains that the construction of a graph as three steps:
8
8
- construct the backward part
9
9
- construct the optimization part
10
10
11
+
## The Construction of a Graph
12
+
11
13
Let us take the problem of image classification as a simple example. The application program that trains the model looks like:
12
14
13
15
```python
@@ -25,7 +27,9 @@ The first four lines of above program build the forward part of the graph.
In particular, the first line `x = layer.data("images")` creates variable x and a Feed operator that copies a column from the minibatch to x. `y = layer.fc(x)` creates not only the FC operator and output variable y, but also two parameters, W and b.
30
+
In particular, the first line `x = layer.data("images")` creates variable x and a Feed operator that copies a column from the minibatch to x. `y = layer.fc(x)` creates not only the FC operator and output variable y, but also two parameters, W and b, and the initialization operators.
31
+
32
+
Initialization operators are kind of "run-once" operators -- the `Run` method increments a class data member counter so to run at most once. By doing so, a parameter wouldn't be initialized repeatedly, say, in every minibatch.
29
33
30
34
In this example, all operators are created as `OpDesc` protobuf messages, and all variables are `VarDesc`. These protobuf messages are saved in a `BlockDesc` protobuf message.
31
35
@@ -49,3 +53,18 @@ According to the chain rule of gradient computation, `ConstructBackwardGraph` wo
49
53
For each parameter, like W and b created by `layer.fc`, marked as double circles in above graphs, `ConstructOptimizationGraph` creates an optimization operator to apply its gradient. Here results in the complete graph:
50
54
51
55

56
+
57
+
## Block and Graph
58
+
59
+
The word block and graph are interchangable in the desgin of PaddlePaddle. A [Block[(https://github.com/PaddlePaddle/Paddle/pull/3708) is a metaphore of the code and local variables in a pair of curly braces in programming languages, where operators are like statements or instructions. A graph of operators and variables is a representation of the block.
60
+
61
+
A Block keeps operators in an array `BlockDesc::ops`
62
+
63
+
```protobuf
64
+
message BlockDesc {
65
+
repeated OpDesc ops = 1;
66
+
repeated VarDesc vars = 2;
67
+
}
68
+
```
69
+
70
+
in the order that there appear in user programs, like the Python program at the beginning of this article. We can imagine that in `ops`, we have some forward operators, followed by some gradient operators, and then some optimization operators.
0 commit comments