提交 2b3904a6 编写于 作者: Y Yi Wang

Explain auto code generation

上级 305aebc0
...@@ -42,7 +42,7 @@ class FCOp : public OperatorBase { ...@@ -42,7 +42,7 @@ class FCOp : public OperatorBase {
void Run(...) { void Run(...) {
add(mul(Input<T>("X"), Input<T>("W")), Input<T>("b"); add(mul(Input<T>("X"), Input<T>("W")), Input<T>("b");
} }
};d };
REGISTER_OP(FCOp, "fc"); REGISTER_OP(FCOp, "fc");
``` ```
...@@ -52,17 +52,17 @@ Let's explain using an example. Suppose that we are going to compose the FC usi ...@@ -52,17 +52,17 @@ Let's explain using an example. Suppose that we are going to compose the FC usi
```python ```python
def operator.mul(X1, X2): def operator.mul(X1, X2):
O = Var O = Var()
paddle.cpp.create_operator("mul", input={X1, Y1], output=O) paddle.cpp.create_operator("mul", input={X1, Y1], output=O)
return O return O
def operator.add(X1, X2): def operator.add(X1, X2):
O = Var O = Var()
paddle.cpp.create_operator("add", input={X1, X2], output=O) paddle.cpp.create_operator("add", input={X1, X2], output=O)
return O return O
``` ```
so that we can define Above code snippets are automatically generated. Given them, users can define
```python ```python
def layer.fc(X): def layer.fc(X):
...@@ -71,6 +71,19 @@ def layer.fc(X): ...@@ -71,6 +71,19 @@ def layer.fc(X):
return operator.add(operator.mul(X, W), b) return operator.add(operator.mul(X, W), b)
``` ```
If we don't have `operator.mul` and `operator.add`, the definiton of `layer.fc` would be complicated:
```python
def layer.fc(X):
W = Var()
b = Var()
O1 = Var()
paddle.cpp.create_operator("mul", input=[X, W], output=O1)
O2 = Var()
paddle.cpp.create_operator("add", input=[O1, b], output=O2)
return O2
```
We'd like to have Python bindings to operators in package `paddle.operator`, and Python compositions of operators in package `paddle.layer`. So we have the following concepts in above illustrative example: We'd like to have Python bindings to operators in package `paddle.operator`, and Python compositions of operators in package `paddle.layer`. So we have the following concepts in above illustrative example:
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册