You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a DL system, we can compose one or more fine grained operators into a coarse grained one. For example, the FC layer can be composed of a multiplication operator and an add operator.
Here is a question -- what is the difference between layer and operator.
In general, operators are those very fine grained operations, e.g., mul and add. In the implementation, we can write them as C++ functions:
template <typename T> T add(T x, T y) { return x + y; }
template <typename T> T mul(T x, T y) { return x * y; }
Then we can wrap them into operators which are C++ classes and can be created from Python bindings by name. A C macro can do this. For example, the following macro invocation
We need to support such composition in Python as well. To do so, we need a higher level Python wrapping of operator creation than paddle.cpp.create_operator. This higher level operator API should be compatible with the layer API.
Let's explain using an example. Suppose that we are going to compose the FC using mul and add in Python, we'd like to have Python functions mul and add defined in module operator:
deflayer.fc(X):
W=Var()
b=Var()
returnoperator.add(operator.mul(X, W), b)
We'd like to have Python bindings to operators in package paddle.operator, and Python compositions of operators in package paddle.layer. This is how we differentiate layer and operators in PaddlePaddle.
The text was updated successfully, but these errors were encountered:
In a DL system, we can compose one or more fine grained operators into a coarse grained one. For example, the FC layer can be composed of a multiplication operator and an add operator.
Here is a question -- what is the difference between layer and operator.
In general, operators are those very fine grained operations, e.g., mul and add. In the implementation, we can write them as C++ functions:
Then we can wrap them into operators which are C++ classes and can be created from Python bindings by name. A C macro can do this. For example, the following macro invocation
generates
so that in Python we can create operator mul by:
Also, at the same time, we can compose a coarse level C++ operator class by composing functions
mul
andadd
:We need to support such composition in Python as well. To do so, we need a higher level Python wrapping of operator creation than
paddle.cpp.create_operator
. This higher level operator API should be compatible with the layer API.Let's explain using an example. Suppose that we are going to compose the FC using mul and add in Python, we'd like to have Python functions
mul
andadd
defined in moduleoperator
:so that we can define
We'd like to have Python bindings to operators in package
paddle.operator
, and Python compositions of operators in packagepaddle.layer
. This is how we differentiate layer and operators in PaddlePaddle.The text was updated successfully, but these errors were encountered: