@@ -16,16 +16,23 @@ The computation graph is constructed by Data Node and Operation Node. The concep
## Definition of VarDesc
A VarDesc should have a name and value, in PaddlePaddle, the value will always be a tensor. Since we use LoDTensor most of the time. We add a LoDTesnorDesc to represent it.
A VarDesc should have a name, and value. The are two kinds of variable type in compile time, they are `LoDTensor` and `SelectedRows`.
```proto
messageVarDesc{
requiredstringname=1;
optionalLoDTensorDesclod_tensor=2;
enumVarType{
LOD_TENSOR=0;
SELECTED_ROWS=1;
}
requiredVarTypetype=2;
optionalLoDTensorDesclod_desc=3;
optionalTensorDescselected_rows_desc=4;
optionalboolpersistable=5[default=false];
}
```
## Definition of LodTensorDesc
## Definition of TensorDesc
```proto
enumDataType{
...
...
@@ -38,87 +45,25 @@ enum DataType {
FP64=6;
}
messageLoDTensorDesc{
messageTensorDesc{
requiredDataTypedata_type=1;
repeatedint32dims=2;// [UNK, 640, 480] is saved as [-1, 640, 480]
optionalint32lod_level=3[default=0];
repeatedint64dims=2;// [UNK, 640, 480] is saved as [-1, 640, 480]
}
```
## Definition of Variable in Python
In Python API, layer will take Variable as Input, and return Variable as Output. There should be a class `Variable` in python to help create and manage Variable.
```python
image=Variable(dims=[-1,640,480])
# fc1 and fc2 are both Variable
fc1=layer.fc(input=image,output_size=10)
fc2=layer.fc(input=fc1,output_size=20)
```
### what should class `Variable` Have
1.`name`.a name of string type is used to mark the value of the Variable.
1.`initializer`. Since our Tensor does not have value. we will always use some Operator to fullfill it when run. So we should have a initialize method to help add the init operator.
1.`operator`. Variable should record which operator produce itself. The reaon is:
- we use pd.eval(targets=[var1, var2]) to run the related ops to get the value of var1 and var2. var.op is used to trace the dependency of the current variable.
In PaddlePaddle, we use Block to describe Computation Graph, so in the code we will use Block but not Graph.
```python
importVarDesc
importLoDTensorDesc
importframework
defAddInitialOperator(variable,initializer):
# add an initialize Operator to block to init this Variable