@@ -12,7 +12,7 @@ The implementation of the first step is a temporary implementation. We should de
...
@@ -12,7 +12,7 @@ The implementation of the first step is a temporary implementation. We should de
## Python Class and compile-time protobuf
## Python Class and compile-time protobuf
As we design our Python API concepts based on `compile-time`, we try to map our Python classes to every compile-time result, i.e., the protobuf messages. They are:
Since we design our Python API concepts based on `compile-time`, we try to map our Python classes to every compile-time result, i.e., the protobuf messages. They are:
| Python Class | Compile-time protobuf |
| Python Class | Compile-time protobuf |
...
@@ -24,27 +24,43 @@ As we design our Python API concepts based on `compile-time`, we try to map our
...
@@ -24,27 +24,43 @@ As we design our Python API concepts based on `compile-time`, we try to map our
### Block
### Block
<!-- TODO -->
Block is just like programming languages `{}`, which contains many operators and variables. There are two data fields in `Block`. 1) An associate map, whose key is variable name and value is variable itself; 2) A list of operators.
The block is hierarchical because PaddlePaddle supports RNN and IfElse. For example, RNN is like `for-loop` in programming languages. There is new `block` inside a `for-loop`. To represent hierarchies, `Block` stores the `parent Block` inside. If `parent=None`, the `Block` is the outermost block, i.e., the `global` block.
```python
```python
classBlock(objects):
classBlock(objects):
def__init__(self,parent=None):
def__init__(self,parent=None):
self.vars_=map<string,Variable>()
self.vars=map<string,Variable>()
self.ops_=vector<Operator>()
self.ops=vector<Operator>()
ifparentisNone:
self.parent=parent
self.global_vars=map<string,Variable>()
self.parent=None
defcreate_var(self,...):
else:
# create variable in `self.vars`
self.parent=parent
returnVariable(...)
self.global_vars=None
defcreate_global_vars(...):
defcreate_global_var(self,...):
ifself.parentisnotNone:
ifself.parentisnotNone:
returnself.parent.create_global_vars(...)
returnself.parent.create_global_var(...)
else:
else:
returnself.global_vars.new()
returnself.create_var(...)
defcreate_parameter(self,...):
returnself.create_global_var(...)
defappend_operator(self,...):
self.ops.append(...)
defprepend_operator(self,...):
self.ops.prepend(...)
```
```
Users are able to create a global variable inside any block since they many create parameters inside a RNN or IfElseOp. All parameters should be stored in the global block, not the step block in RNN.
Users can create local variables for outputs of operators. Users can also append and prepend an operator in current block. Prepending `random initialize` operator or `load` operator is very useful to initialize parameters before training.