-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Skeleton of Python API design #4052
Add Skeleton of Python API design #4052
Conversation
doc/design/python_api.md
Outdated
@@ -0,0 +1,156 @@ | |||
# Design Doc: Python API | |||
|
|||
The top level user API in Python should be as same as API in `paddle.v2` after refactoring Paddle from a layer based framework to an operator based framework. There are many new classes in C++ in [compile time] for describing neural networks, such as `Variable`, `Operator`, `Block`. The issue about current design is how to give a proper way to wrap the C++ API to `paddle.v2` API and writing layers in Python. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
writing -> write
doc/design/python_api.md
Outdated
|
||
## Python Class and compile-time protobuf | ||
|
||
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
every compile-time result -> each compile-time concepts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the result I want to say, not concepts. The result of compile-time is protobuf.
doc/design/python_api.md
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inside a RNN -> inside a RNNOp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
doc/design/python_api.md
Outdated
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users can create local variables for outputs of operators.
what about the inputs of operators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inputs of operators are the other operators' output.
doc/design/python_api.md
Outdated
|
||
### Operator | ||
|
||
Operator class will take inputs, outputs and attributes of the operator into `protobuf` OpDesc and create a C++ `OpDesc` instance. The `infer_shape` perform on C++ objects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take ... into OpDesc
is a little strange
doc/design/python_api.md
Outdated
block = g_block | ||
w = block.create_parameter(...) | ||
b = block.create_parameter(...) | ||
out = stack.create_var() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is stack
for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this is a topy, should be block
… into feature/python_api_design
… feature/python_api_design
doc/design/python_api.md
Outdated
return self.create_var(...) | ||
|
||
def create_parameter(self, ...): | ||
return self.create_global_var(...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does create_parameter
mean create_global_var
?
I guess yes, because:
All parameters should be stored in the global block
What happens if the one block's create_parameter
call creates a parameter that has the same name from another block? Intuitively block A and block B creating the parameter with the same name will not interfere with each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, no.
- All parameters must be created in the global block.
- All parameters are marked as Parameter. The Parameter is a subclass of Variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the user can not create parameter inside a if-else block? (e.g., create a FC layer with parameter W and B).
doc/design/python_api.md
Outdated
|
||
### Variable | ||
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
op
will keep beingNone
till the variable is taken as an operator's output.
Do you mean: "The value of op
is None
unless the variable is an operator's output."?
doc/design/python_api.md
Outdated
|
||
Users are able to create a global variable inside any block since they many create parameters inside a RNN or IfElse. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"current block" is mentioned 3 times in this document, what exactly does it mean. Is it a global variable?
Update Python API Design
No description provided.