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/refactorization.md
+23-22Lines changed: 23 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,22 +17,22 @@ The goals of refactoring include:
17
17
18
18
1. A graph is composed of *variables* and *operators*.
19
19
20
-
1. The description of graphs must be capable of being serialized/deserialized, so that:
20
+
1. The description of graphs must be serializable/deserializable, so that:
21
21
22
-
1. It can to be sent to the cloud for distributed execution, and
22
+
1. It can be sent to the cloud for distributed execution, and
23
23
1. It can be sent to clients for mobile or enterprise deployment.
24
24
25
-
1. The Python program does the following steps
25
+
1. The Python program does two things
26
26
27
-
1.*compilation*: run a Python program to generate a protobuf message representation of the graph and send it to
27
+
1.*Compilation* runs a Python program to generate a protobuf message representation of the graph and send it to
28
28
1. the C++ library `libpaddle.so` for local execution,
29
29
1. the master process of a distributed training job for training, or
30
30
1. the server process of a Kubernetes serving job for distributed serving.
31
-
1.*execution*: execute the graph by constructing instances of class [`Variable`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/variable.h#L24) and [`OperatorBase`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/operator.h#L70), according to the protobuf message.
31
+
1.*Execution* executes the graph by constructing instances of class [`Variable`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/variable.h#L24) and [`OperatorBase`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/operator.h#L70), according to the protobuf message.
32
32
33
33
## Description and Realization of Computation Graph
34
34
35
-
At compile time, the Python program generates a protobuf message representation of the graph, or the description of the graph.
35
+
At compile time, the Python program generates a protobuf message representation of the graph, or a description of the graph.
36
36
37
37
At runtime, the C++ program realizes the graph and runs it.
38
38
@@ -42,22 +42,22 @@ At runtime, the C++ program realizes the graph and runs it.
The word *graph* is interchangeable with *block* in this document. A graph represents computation steps and local variables similar to a C++/Java program block, or a pair of parentheses(`{` and `}`).
45
+
The word *graph* is interchangeable with *block* in this document. A graph consists of computation steps and local variables similar to a C++/Java program block, or a pair of parentheses(`{` and `}`).
46
46
47
47
## Compilation and Execution
48
48
49
-
1. Run an application Python program to describe the graph. In particular, the Python application program does the following:
49
+
1. Run a Python program to describe the graph. In particular, the Python application program does the following:
50
50
51
51
1. Create `VarDesc` to represent local/intermediate variables,
52
52
1. Create operators and set attributes,
53
53
1. Validate attribute values,
54
54
1. Infer the type and the shape of variables,
55
55
1. Plan memory-reuse for variables,
56
56
1. Generate the backward graph
57
-
1.Optimize the computation graph.
58
-
1.Potentially, split the graph for distributed training.
57
+
1.Add optimization operators to the computation graph.
58
+
1.Optionally, split the graph for distributed training.
59
59
60
-
1. The invocation of `train` or [`infer`](https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/v2/inference.py#L108) methods in the application Python program does the following:
60
+
1. The invocation of `train` or [`infer`](https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/v2/inference.py#L108) methods in the Python program does the following:
61
61
62
62
1. Create a new Scope instance in the [scope hierarchy](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/scope.md) for each run of a block,
63
63
1. realize local variables defined in the BlockDesc message in the new scope,
* `Operator` is the fundamental building block of the user interface.
110
-
* Operator stores input/output variable names, and attributes.
111
-
* The `InferShape` interface is used to infer the shape of the output variable shapes based on the shapes of the input variables.
110
+
* Operator stores input/output variable names and attributes.
111
+
* The `InferShape` interface is used to infer the shape of the output variables based on the shapes of the input variables.
112
112
* Use `Run` to compute the `output` variables from the `input` variables.
113
113
114
114
---
@@ -139,7 +139,7 @@ Compile Time -> IR -> Runtime
139
139
* Limit the number of `tensor.device(dev) = ` in your code.
140
140
* `thrust::transform` and `std::transform`.
141
141
* `thrust` has the same API as C++ standard library. Using `transform`, one can quickly implement customized element-wise kernels.
142
-
* `thrust` also has more complex APIs, like `scan`, `reduce`, `reduce_by_key`.
142
+
* `thrust`, in addition, supports more complex APIs, like `scan`, `reduce`, `reduce_by_key`.
143
143
* Hand-writing `GPUKernel` and `CPU` code
144
144
* Do not write in header (`.h`) files. CPU Kernel should be in cpp source (`.cc`) and GPU kernels should be in cuda (`.cu`) files. (GCC cannot compile GPU code.)
145
145
---
@@ -185,10 +185,10 @@ Make sure the registration process is executed and linked.
185
185
1. Write an Op class and its gradient Op class, if required.
186
186
2. Write an Op maker class. In the constructor of this class, describe the inputs, outputs and attributes of the operator.
187
187
3. Invoke the macro `REGISTER_OP`. This macro will
188
-
1. Call maker class to complete the `proto` and the `checker`
188
+
1. Call maker class to complete `proto` and `checker`
189
189
2. Using the completed `proto` and `checker`, it will add a new key-value pair to the `OpInfoMap`
190
190
191
-
4. Invoke the `USE` macro in which the Op is used, to make sure that it is linked.
191
+
4. Invoke the `USE` macro in which the Op is used to make sure that it is linked.
192
192
193
193
---
194
194
# Backward Module (1/2)
@@ -199,13 +199,14 @@ Make sure the registration process is executed and linked.
199
199
---
200
200
# Backward Module (2/2)
201
201
### Build Backward Network
202
-
-**Input**: graph of forward operators
203
-
-**Output**: graph of backward operators
202
+
-**Input**: a graph of forward operators
203
+
-**Output**: a graph of backward operators
204
204
-**Corner cases in construction**
205
205
- Shared Variables => insert an `Add` operator to combine gradients
206
206
- No Gradient => insert a `fill_zero_grad` operator
207
207
- Recursive NetOp => call `Backward` recursively
208
208
- RNN Op => recursively call `Backward` on stepnet
209
+
- RNN Op => recursively call `Backward` on stepnet
209
210
210
211
211
212
---
@@ -215,10 +216,10 @@ Make sure the registration process is executed and linked.
215
216
* Only dims and data pointers are stored in `Tensor`.
216
217
* All operations on `Tensor` are written in `Operator` or global functions.
0 commit comments