var_desc.md 2.1 KB
Newer Older
Q
qiaolongfei 已提交
1
## Background
2
PaddlePaddle divides the description of neural network computation into two stages: compile time and runtime. At compile time, the neural network computation is described as a `ProgramDesc` whereas at runtime an `Executor` interprets the `ProgramDesc` to compute the operations.
Q
qiaolongfei 已提交
3

4
PaddlePaddle use proto message to describe compile time program because
Q
qiaolongfei 已提交
5

6 7
1. The computation program description must be serializable and saved in a file.
1. During distributed training, the sreialized program will be sent to multiple workers. It should also be possible to break the program into different components, each of which can be executed on different workers.
Q
qiaolongfei 已提交
8

9
The computation `Program` consists of nested `Blocks`. Each `Block` will consist of data(i.e. `Variable`)  and  `Operations`. The concept to represent them is in the table below.
Q
qiaolongfei 已提交
10

Q
qiaolongfei 已提交
11 12 13 14
| |compile time|runtime|
|---|---|---|
|Data|VarDesc(proto)|Variable(cpp)|
|Operation|OpDesc(proto)|Operator(cpp)|
Q
qiaolongfei 已提交
15 16


Q
qiaolongfei 已提交
17 18
## Definition of VarDesc

Y
Yu Yang 已提交
19
A VarDesc should have a name, and value. The are two kinds of variable type in compile time, they are `LoDTensor` and `SelectedRows`. 
Q
qiaolongfei 已提交
20 21 22 23

```proto
message VarDesc {
  required string name = 1;
Y
Yu Yang 已提交
24 25 26 27 28 29 30 31
  enum VarType {
    LOD_TENSOR = 0;
    SELECTED_ROWS = 1;
  }
  required VarType type = 2;
  optional LoDTensorDesc lod_desc = 3;
  optional TensorDesc selected_rows_desc = 4;
  optional bool persistable = 5 [ default = false ];
Q
qiaolongfei 已提交
32
}
Q
qiaolongfei 已提交
33
```
Q
qiaolongfei 已提交
34

Y
Yu Yang 已提交
35
## Definition of TensorDesc
Q
qiaolongfei 已提交
36 37

```proto
Q
qiaolongfei 已提交
38 39 40 41 42 43 44 45 46 47
enum DataType {
  BOOL = 0;
  INT16 = 1;
  INT32 = 2;
  INT64 = 3;
  FP16 = 4;
  FP32 = 5;
  FP64 = 6;
}

Y
Yu Yang 已提交
48
message TensorDesc {
Q
qiaolongfei 已提交
49
  required DataType data_type = 1;
Y
Yu Yang 已提交
50
  repeated int64 dims = 2; // [UNK, 640, 480] is saved as [-1, 640, 480]
Q
qiaolongfei 已提交
51 52 53
}
```

Y
Yu Yang 已提交
54
A TensorDesc describes `SelectedRows` and `LoDTensor`. For details of `SelectedRows`, please reference [`SelectedRows`](./selected_rows.md).
Q
qiaolongfei 已提交
55

Y
Yu Yang 已提交
56
## Definition of LodTensorDesc
Q
qiaolongfei 已提交
57

Y
Yu Yang 已提交
58 59 60 61 62
```proto
message LoDTensorDesc {
  required TensorDesc tensor = 1;
  optional int lod_level = 2;
}
Q
qiaolongfei 已提交
63 64
```

Y
Yu Yang 已提交
65
A LoDTensorDesc contains a tensor and a lod_level.
Q
qiaolongfei 已提交
66

Y
Yu Yang 已提交
67
## Definition of Variable in Python
Q
qiaolongfei 已提交
68

Y
Yu Yang 已提交
69
For Variable in Python, please reference [`Python API`](./python_api.md).