-
Notifications
You must be signed in to change notification settings - Fork 5.8k
OP Input Output Attribute Compatibility Modification(English Version)
OP修改规范:Input/Output/Attribute只能做兼容修改 (中文版)
Specification summary:
- Section 1, Background
- Section 2, Input/Output/Attribute Compatibility Modification
- Section 3, Relevant Instructions of CI
Additional instructions:
During the implementation process, the specifications may find aspects that are not considered by the existing specifications, and need to be supplemented and improved in the implementation process. Please also give positive feedback.
At present, there is a situation that users use the Paddle inference library of new version to load model trained by the old version. In order to ensure that the model can be loaded successfully, developers must ensure that the old and new versions are compatible when adding, deleting, or modifying the Input, Output or Attribute of OPs (refer to official documentation).
That means that developers should ensure that the Input, Output and Attribute of OPs cannot be modified (except for documents) or deleted. And developers can add Input, Output and Attribute, but the added Input and Output must be set to be dispensable, and the default value of added Attribute must be set.
The Input, Output and Attribute of OPs are usually added, deleted or modified in the make()
function of the class OpMaker
, such as slice
OP (only part of the code of SliceOpMaker
is shown):
class SliceOpMaker : public framework::OpProtoAndCheckerMaker {
public:
void Make() override {
AddInput("Input", "(Tensor) Tensor of data to extract slices from.");
AddInput("EndsTensor","(Tensor<int32>, optional) If provided, slice will use this.It has the highest priority of EndsTensor, EndsTensorList and attr(ends).").AsDispensable()
AddOutput("Out", "Sliced data tensor.");
AddAttr<std::vector<int>>("starts","(list<int>) Starting indices of corresponding axis in `axes`").SetDefault({});
}
}
- Input/Output:
- duplicable (bool): Default: false. Set to true by call
.AsDuplicable()
. - intermediate (bool): Default: false. Set to true by call
.AsIntermediate()
. - dispensable (bool): Default: false. Set to true by call
.AsDispensable()
.
- duplicable (bool): Default: false. Set to true by call
- Attribute:
- type (int): Set by
AddAttr<>
. For example,AddAttr<std::vector<int>>
indicates that the type isstd::vector<int>
, and the value oftype
is the AttrTypeID corresponding tostd::vector<int>
. - generated (bool): The third parameter of the function
AddAttr<T>()
. Default: false. - default value: Set by
.SetDefault()
. For example,.SetDefault({})
indicates the default value of the attribute is empty vector.
- type (int): Set by
Add | Delete | Modify | |
---|---|---|---|
Input | Allowed, but dispensable must be true |
Not Allowed | Not Allowed |
Output | Allowed, but dispensable must be true |
Not Allowed | Not Allowed |
Attribute | Allowed, but default value must be set |
Not Allowed | Not Allowed |
The check of this specification has been enabled in PR_CI_CPU_Py2
. If the changes of Input/Output/Attribute of OP cause the check to fail, an error message in Build Log is similar to the following:
------------------------------
Op desc error for the changes of Inputs/Outputs/Attrs of OPs:
For OP 'slice':
* The added Input 'Out_test_2' is not dispensable.
* The Input 'EndsTensorList' is deleted.
* The arg 'dispensable' of Input 'EndsTensor' is changed: from 'True' to 'False'.
* The arg 'default_value' of Attr 'starts' is changed: from '{} to '{1}'.
------------------------------
Please modify your codes according to the error message to achieve the purpose of compatibility upgrade. If it is confirmed that the upgrade cannot be compatible, please find the relevant approvers(there is a list of approvers in CI Build Log) to review the code and at least one approval is required.
If you want to repeat the process of CI, please follow these steps:
- Compile and install paddle from develop branch
- Print op desc from develop branch, run:
python tools/print_op_desc.py > OP_DESC_DEV.spec
- Compile and install paddle from PR branch
- Print op desc from PR branch, run:
python tools/print_op_desc.py > OP_DESC_PR.spec
- Compare the two op desc, run:
python tools/check_op_desc.py OP_DESC_DEV.spec OP_DESC_PR.spec
If you have problems, please contact @ liym27.