You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
3.3 KiB
66 lines
3.3 KiB
8 years ago
|
## Operator's Parameter Name Convention
|
||
8 years ago
|
|
||
8 years ago
|
To make the operator document itself more clear, we recommend operator names obey the listing conventions.
|
||
8 years ago
|
|
||
8 years ago
|
### OpProtoMaker names
|
||
8 years ago
|
|
||
7 years ago
|
When defining an operator in Paddle, a corresponding [OpProtoMaker](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/operator.h#L170) (TODO: OpProtoMaker Doc)need to be defined. All the Input/Output and Attributes will write into the [OpProto](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/framework.proto#L61) , and will be used in client language to create operator.
|
||
8 years ago
|
|
||
8 years ago
|
- Input/Output.
|
||
7 years ago
|
- Input/Output names follow the **CamelCase**. e.g. `X`, `Y`, `Matrix`, `LastAxisInMatrix`. Input/Output much more like Variables, we prefer to meaningful English words.
|
||
8 years ago
|
- If an operator's Input/Output are tensors in math, not match to any meaningful words, input name should starts from `X`. e.g. `X`, `Y`, and output name should starts from `Out`. e.g. `Out`. This rule intends making operators which have few inputs/outputs unified.
|
||
8 years ago
|
|
||
8 years ago
|
- Attribute.
|
||
7 years ago
|
- Attribute name follows the **snake_case**. e.g. `x`, `y`, `axis`, `rowwise_matrix`. Also, attribute name prefers to meaningful English words.
|
||
8 years ago
|
|
||
|
- Comments.
|
||
8 years ago
|
- Input/Output/Attr comment follow the format of **(type,default value) usage**, corresponding to which type it can be and how it will be used in the operator. e.g. Attribute in Accumulator`"gamma" `,`(float, default 1.0) Accumulation multiplier`.
|
||
7 years ago
|
- Operator comment format of` R"DOC(your comment here)DOC"`. You should explain the input/output of the operator first. If there is math calculation in this operator, you should write the equation in the comment. e.g. `Out = X + Y`.
|
||
8 years ago
|
|
||
|
- Order.
|
||
|
- Follow the order of Input/Output, then Attribute, then Comments. See the example in best practice.
|
||
8 years ago
|
|
||
|
### Best Practice
|
||
8 years ago
|
|
||
8 years ago
|
Here we give some examples to show how these rules will be used.
|
||
|
|
||
7 years ago
|
- The operator has one input, one output. e.g.`relu`, inputs: `X`, outputs: `Out`.
|
||
8 years ago
|
|
||
|
- The operator has two input, one output. e.g. `rowwise_add`, inputs : `X`, `Y`, outputs : `Out`.
|
||
|
|
||
|
- The operator contains attribute. e.g. `cosine`, inputs : `X`, `axis`, outputs : `Out`.
|
||
|
|
||
8 years ago
|
We give a full example of Accumulator Operator.
|
||
8 years ago
|
|
||
|
```c++
|
||
|
class AccumulateOpMaker : public framework::OpProtoAndCheckerMaker {
|
||
|
public:
|
||
7 years ago
|
AccumulateOpMaker(OpProto *proto,
|
||
|
OpAttrChecker *op_checker)
|
||
8 years ago
|
: OpProtoAndCheckerMaker(proto, op_checker) {
|
||
7 years ago
|
AddInput("X", "(Tensor) The input tensor that has to be accumulated to the output tensor.
|
||
|
If the output size is not the same as input size,
|
||
8 years ago
|
the output tensor is first reshaped and initialized to zero, and only then, accumulation is done.");
|
||
8 years ago
|
AddOutput("Out", "(Tensor) Accumulated output tensor");
|
||
8 years ago
|
AddAttr<float>("gamma", "(float, default 1.0) Accumulation multiplier").SetDefault(1.0f);
|
||
8 years ago
|
AddComment(R"DOC(
|
||
7 years ago
|
Accumulate Operator.
|
||
|
|
||
|
This operator accumulates the input tensor to the output tensor. If the
|
||
8 years ago
|
output tensor already has the right size, we add to it; otherwise, we first
|
||
|
initialize the output tensor to all zeros, and then do accumulation. Any
|
||
|
further calls to the operator, given that no one else fiddles with the output
|
||
|
in the interim, will do simple accumulations.
|
||
7 years ago
|
|
||
|
Accumulation is done as follows:
|
||
8 years ago
|
|
||
|
Out = 1*X + gamma*Out
|
||
|
|
||
8 years ago
|
where X is the input tensor, Out is the output tensor and gamma is the multiplier
|
||
8 years ago
|
argument.
|
||
7 years ago
|
|
||
8 years ago
|
)DOC");
|
||
|
}
|
||
|
};
|
||
|
```
|