add the op def proto, test=develop #33098
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Bug fixes
PR changes
OPs
Describe
飞桨算子定义有效性约束数据结构(OpDef)说明
目前,框架所有可用的算子定义均包含在
paddle::framework::proto::OpProto
数据结构中,但此数据结构还包含了一些执行态相关信息,这些信息对用户无效,在序列化时冗余。因为状态的累积,目前仅靠算子参数(及输入输出)名称,已无法自动化分辨哪些属性为必需。所以需要人工摘取算子定义的必要信息,并用一个分类能力更强的数据结构保存这些信息。在推理 Pass 升级过程中,必须知道哪些输入、输出、参数是需要识别且满足前置要求的(如
while
算子仅在参数"sub_block"
存在且取值大于等于1
时才触发某些 Pass;相关信息将包含在下文示例中的OpDef::def
域)。但是,目前原有数据结构OpProto
拿到的算子属性是杂糅的,不易限定,所以给出本提交。此提交合入后,在 Pass 升级中,相应负责人需同步对涉及到的算子属性进行分类(即完成算子对应的
pbtxt
文本文件书写),并将其存放到指定目录(paddle/fluid/operators/compat
)中。示例
下面以
while
算子为例,给出一个满足新数据结构的内容形式(while.pbtxt
):注意事项
1、
OpDef
和原有数据结构OpProto
是一一对应的:OpProto
中的每个输入、输出、参数,必归属到OpDef
的def
或extra
二者的其中一类。所以OpDef
数据结构实际上是对OpProto
区分为“必需”和“冗余”的二分类过程。2、每个区分完成的算子定义应提交到
paddle/fluid/operators/compat
目录,并以"算子名称+.pbtxt"
文件名存放。3、CI 应确保
paddle/fluid/operators/compat
目录中的每个文件都能被OpDef
正常加载,且OpDef
在二分类过程中相对于OpProto
没有项目丢失。4、为方便大家快速完成相关工作,不被 Protobuf 文本格式困扰,我们准备了未分类的
pbtxt
基础文件(压缩包下载)。只需挑选对应算子进行增量开发,将一部分属性行从def
(必需)移动到extra
(冗余),即可完成全部工作。按要求完成如下修改的while.pbtxt
在内容与格式上应与本文档首次出现的示例一致。5、对应地,在对 Pass 进行升级时,下列函数调用的
Input
、Output
、Attr
只需要关心(且须全部添加,不能遗漏)属性中的def
部分。extra
属性 按需 涉及,以避免代码过于冗长。此处的“按需”指的是:根据extra
属性的正误是否影响 Pass 运行,灵活判断是否加入前置条件。6、本提交规范的是框架训练前向算子的通用性。由于推理自身原因,在 Pass 中由于新增
OpDesc
并自定义属性,导致出现既不在extra
中的OpAttr
的问题暂未涉及,遇到此类疑问时单独对接处理。7、Pass 中新增的算子类型如下。这些算子只会出现在经过 Pass 之后的计算图中(是推理优化专用算子,不在训练原始模型出现),所以暂时不需纳入 pbtxt 的统计。