-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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).
Starting from version 2.2rc, the OP can be horizontally divided into three parts: Def (definition), Quant (quantization), and Extra.
Module | Clip while export fp32 model | Clip while export quantization model | explanation |
---|---|---|---|
Def | No | No | The native definition of the operator. All paddle backends need to support, and is also the external standard of the paddle operator |
Quant | No | Yes | The quantization expansion of the operator |
Extra | Yes | Yes | The runtime expansion of the operator |
the modification of the Extra part will not affect the compatibility of the operator, and the modification of the non-Extra part must consider compatibility issues.
In order to ensure compatibility, the Input, Output, and Attributes belonging to the non-Extra part of the OP are not allowed to be modified (except for documents) or deleted. They can be added, but the new Input and Output must be set to AsDispensable, and the new Attribute must be set to the default value.
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:
Field | Type | Default Value | Set Method |
---|---|---|---|
duplicable | bool | false | Set to true by call .AsDuplicable()
|
intermediate | bool | false | Set to true by call .AsIntermediate()
|
dispensable | bool | false | Set to true by call .AsDispensable()
|
extra | bool | false | Set to true by call .AsExtra()
|
quant | bool | false | Set to true by call .AsQuant()
|
- Attribute:
Field | Type | Default Value | Set Method |
---|---|---|---|
type | int | --- | The setting is determined by the template parameter T of the function AddAttr<T> . The value is the AttrTypeID value corresponding to T . |
generated | bool | false | The third parameter of AddAttr<T>() . |
default value | Decided by "type" field | --- | Set by .SetDefault() . |
extra | bool | false | Set to true by call .AsExtra()
|
quant | bool | false | Set to true by call .AsQuant()
|
There is no compatibility requirement for the modification of Input/Output/Attribute whose extra is true. For non-extra Input/Output/Attribute modification, the following requirements must be met:
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 @ winter-wang.