@@ -82,7 +82,7 @@ After creating a C++ `OpDesc`, `Operator` in Python can only reads the attribute
...
@@ -82,7 +82,7 @@ After creating a C++ `OpDesc`, `Operator` in Python can only reads the attribute
### Variable
### Variable
Operators' intputs, outputs and parameters are all variables. In our design, a variable has four key attributes: its name(`name`), the block it belongs to(`block`), a pointer pointed to its C++ Protobuf object(`cpp_var_desc_ptr`), and the operator it is created by(`op`). All of these attributes are initialized in constructor, except the `op`. The `op` will keep being `None` till the variable is taken as an operator's output.
Operators' inputs, outputs, and parameters are all variables. In our design, a variable has four key attributes: its name(`name`), the block it belongs to(`block`), a pointer pointed to its C++ Protobuf object(`cpp_var_desc_ptr`), and the operator it is created by(`op`). All of these attributes are initialized in the constructor, except the `op`. The `op` will keep being `None` till the variable is taken as an operator's output.
```python
```python
classVariable(object):
classVariable(object):
...
@@ -100,15 +100,13 @@ class Variable(object):
...
@@ -100,15 +100,13 @@ class Variable(object):
return[Noneifelem<0elseelemforelemincpp_shape]
return[Noneifelem<0elseelemforelemincpp_shape]
```
```
Protobuf object should be created in C++ not Python because it is needed by infershape, and infershape is implementated by C++ code. The C++ Protobuf object is accessible for Python through the `cpp_var_desc_ptr` pointer.
The Protobuf object should be created in C++ not Python because it is needed by infershape, and infershape is implemented by C++ code. The C++ Protobuf object is accessible for Python through the `cpp_var_desc_ptr`, just like how `shape()` function does.
The user is allowed to build an variable without specifying its name. If so, it is going to be assigned with an automatically generated unique name.
The user is allowed to build a variable without specifying its name. If so, it is going to be assigned with an automatically generated unique name.
The parameter is a kind of special variable. They need to be initialized at the very beginning and updated after each batch training. So if a variable is a parameter, our compiler will add an initializer op and an optimizer op for it during the building process of computation graph. Apart from these, there is no more difference between variable and parameter. In other words, 'parameter' is only a label attached to variables, to tell the compiler these ones require additional processing.
<!-- 参数 is a special Variable -->
```python
```python
classParameter(Variable):
classParameter(Variable):
...
@@ -116,6 +114,9 @@ class Parameter(Variable):
...
@@ -116,6 +114,9 @@ class Parameter(Variable):
pass
pass
```
```
The class `Parameter` is derived from class `Variable`. In addition to variables have, parameters are able to hold their initializing and updating information. A parameter's `self.op` will always be `None` because it can never be an operator's output.