From 2b3904a6a8c568f8bf20155f8f87a33c9f4e67b9 Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Sat, 2 Sep 2017 17:34:10 -0700 Subject: [PATCH] Explain auto code generation --- doc/design/functions_operators_layers.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/design/functions_operators_layers.md b/doc/design/functions_operators_layers.md index e4f8d303e..7a2e8fd0a 100644 --- a/doc/design/functions_operators_layers.md +++ b/doc/design/functions_operators_layers.md @@ -42,7 +42,7 @@ class FCOp : public OperatorBase { void Run(...) { add(mul(Input("X"), Input("W")), Input("b"); } -};d +}; REGISTER_OP(FCOp, "fc"); ``` @@ -52,17 +52,17 @@ Let's explain using an example. Suppose that we are going to compose the FC usi ```python def operator.mul(X1, X2): - O = Var + O = Var() paddle.cpp.create_operator("mul", input={X1, Y1], output=O) return O def operator.add(X1, X2): - O = Var + O = Var() paddle.cpp.create_operator("add", input={X1, X2], output=O) return O ``` -so that we can define +Above code snippets are automatically generated. Given them, users can define ```python def layer.fc(X): @@ -71,6 +71,19 @@ def layer.fc(X): 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: ``` -- GitLab