Skip to content

Commit d1479d9

Browse files
abhinavarorawangkuiyi
authored andcommitted
Fixing errors in the refactorization doc (#4680)
1 parent c193f82 commit d1479d9

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

doc/design/refactorization.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ The goals of refactoring include:
1717

1818
1. A graph is composed of *variables* and *operators*.
1919

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:
2121

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
2323
1. It can be sent to clients for mobile or enterprise deployment.
2424

25-
1. The Python program does the following steps
25+
1. The Python program does two things
2626

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
2828
1. the C++ library `libpaddle.so` for local execution,
2929
1. the master process of a distributed training job for training, or
3030
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.
3232

3333
## Description and Realization of Computation Graph
3434

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.
3636

3737
At runtime, the C++ program realizes the graph and runs it.
3838

@@ -42,22 +42,22 @@ At runtime, the C++ program realizes the graph and runs it.
4242
|Operation|[OpDesc](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/framework.proto#L35)|[Operator](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/operator.h#L64)|
4343
|Block|BlockDesc|Block|
4444

45-
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 `}`).
4646

4747
## Compilation and Execution
4848

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:
5050

5151
1. Create `VarDesc` to represent local/intermediate variables,
5252
1. Create operators and set attributes,
5353
1. Validate attribute values,
5454
1. Infer the type and the shape of variables,
5555
1. Plan memory-reuse for variables,
5656
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.
5959

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:
6161

6262
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,
6363
1. realize local variables defined in the BlockDesc message in the new scope,
@@ -107,8 +107,8 @@ Compile Time -> IR -> Runtime
107107
![class_diagram](http://api.paddlepaddle.org/graphviz?dot=https://gist.githubusercontent.com/reyoung/53df507f6749762675dff3e7ce53372f/raw/dd598e8f1976f5759f58af5e5ef94738a6b2e661/op.dot)
108108
109109
* `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.
112112
* Use `Run` to compute the `output` variables from the `input` variables.
113113
114114
---
@@ -139,7 +139,7 @@ Compile Time -> IR -> Runtime
139139
* Limit the number of `tensor.device(dev) = ` in your code.
140140
* `thrust::transform` and `std::transform`.
141141
* `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`.
143143
* Hand-writing `GPUKernel` and `CPU` code
144144
* 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.)
145145
---
@@ -185,10 +185,10 @@ Make sure the registration process is executed and linked.
185185
1. Write an Op class and its gradient Op class, if required.
186186
2. Write an Op maker class. In the constructor of this class, describe the inputs, outputs and attributes of the operator.
187187
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`
189189
2. Using the completed `proto` and `checker`, it will add a new key-value pair to the `OpInfoMap`
190190

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.
192192

193193
---
194194
# Backward Module (1/2)
@@ -199,13 +199,14 @@ Make sure the registration process is executed and linked.
199199
---
200200
# Backward Module (2/2)
201201
### 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
204204
- **Corner cases in construction**
205205
- Shared Variables => insert an `Add` operator to combine gradients
206206
- No Gradient => insert a `fill_zero_grad` operator
207207
- Recursive NetOp => call `Backward` recursively
208208
- RNN Op => recursively call `Backward` on stepnet
209+
- RNN Op => recursively call `Backward` on stepnet
209210

210211

211212
---
@@ -215,10 +216,10 @@ Make sure the registration process is executed and linked.
215216
* Only dims and data pointers are stored in `Tensor`.
216217
* All operations on `Tensor` are written in `Operator` or global functions.
217218
* Variable length Tensor design [LoDTensor](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/lod_tensor.md)
218-
* `Variable` instances are the inputs and the outputs of an operator. Not just `Tensor`.
219+
* `Variable` instances are the inputs and the outputs of an operator, not just `Tensor`.
219220
* `step_scopes` in RNN is a variable and not a tensor.
220-
* `Scope` is where variables are stores.
221-
* map<string `variable_name`, Variable>
221+
* `Scope` is where variables are stored.
222+
* map<string `var name`, Variable>
222223
* `Scope` has a hierarchical structure. The local scope can get variables from its parent scope.
223224

224225
---
@@ -246,7 +247,7 @@ Make sure the registration process is executed and linked.
246247
---
247248
# Control the migration quality
248249
- Compare the performance of migrated models with old ones.
249-
- Follow the google C++ style
250+
- Follow the google C++ style guide.
250251
- Build the automatic workflow of generating Python/C++ documentations.
251252
- The documentation of layers and ops should be written inside the code.
252253
- Take the documentation quality into account when submitting pull requests.

0 commit comments

Comments
 (0)