var_desc.md.txt 1.7 KB
Newer Older
1 2 3
## Background
PaddlePaddle divides the description of neural network computation graph into two stages: compile time and runtime.

4
PaddlePaddle use proto message to describe compile time graph because
5 6 7 8 9 10 11 12 13 14 15 16 17 18

1. Computation graph should be able to be saved to a file.
1. In distributed training, the graph will be serialized and send to multiple workers.

The computation graph is constructed by Data Node and Operation Node. The concept to represent them is in the table below.

| |compile time|runtime|
|---|---|---|
|Data|VarDesc(proto)|Variable(cpp)|
|Operation|OpDesc(proto)|Operator(cpp)|


## Definition of VarDesc

19
A VarDesc should have a name, and value. The are two kinds of variable type in compile time, they are `LoDTensor` and `SelectedRows`. 
20 21 22 23

```proto
message VarDesc {
  required string name = 1;
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 ];
32 33 34
}
```

35
## Definition of TensorDesc
36 37 38 39 40 41 42 43 44 45 46 47

```proto
enum DataType {
  BOOL = 0;
  INT16 = 1;
  INT32 = 2;
  INT64 = 3;
  FP16 = 4;
  FP32 = 5;
  FP64 = 6;
}

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

54
A TensorDesc describes `SelectedRows` and `LoDTensor`. For details of `SelectedRows`, please reference [`SelectedRows`](./selected_rows.md).
55

56
## Definition of LodTensorDesc
57

58 59 60 61 62
```proto
message LoDTensorDesc {
  required TensorDesc tensor = 1;
  optional int lod_level = 2;
}
63 64
```

65
A LoDTensorDesc contains a tensor and a lod_level.
66

67
## Definition of Variable in Python
68

69
For Variable in Python, please reference [`Python API`](./python_api.md).