-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
PFCCPaddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfccPaddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfccstatus/close已关闭已关闭
Description
问题描述 Please describe your issue
子图验证&核心机制完善
本项目是新IR推全测试,兼容现有动转静执行逻辑的重要环节。目前我们通过动态图组网 -> AST翻译 ->
静态图表示 -> ProgramTranslator -> 新IR下的静态图表示 -> NewIRInterpreter 这样的路径支持了在新IR下飞桨的动转静功能。
目前从旧静态图到新静态图下存在某些问题,需要经过充分的测试。
我们希望通过复用现有的子图级别的测试(即test/dygraph_to_static目录下的测试)验证新IR的功能完备性和正确性。
目前动转静测试中存在问题的内容有:
- 在 PIR 下缺少对应的算子
- ProgramTranslator 转译过程中部分 Op 在新旧 IR 下定义不同导致需要特殊处理。
修复
为新 IR 添加算子
对于缺少对应的算子,报错信息类似于 Op xxx should have corresponding OpInfo pd_op.xxx
以下几个步骤对应来解决
1. 配置 ops.yaml 和 backward.yaml
- 首先根据该 Op 在旧 IR 下的定义,来补充该 Op 在新 ir 下的定义。
旧 IR 的 Op 定义文件名称一般都为 xxx_op.cc,我们可以直接看到 xxxOpMaker 下的 make 来查看 input、output等信息。
如果该 Op 有反向过程,就需要对前反向同时进行补充。 - 新 ir 下的 Op 可以通过 yaml 定义自动生成,文件在
paddle/fluid/pir/dialect/operator/ir/ops.yaml
和paddle/fluid/pir/dialect/operator/ir/backward.yaml
yaml 文件的前反向规则可以参考 C++算子开发文档的3.1 算子 Yaml 文件配置
2. 配置 op_compat.yaml
- 转译过程中新旧 IR 的 Op 参数名称不同,其映射定义在 paddle/phi/api/yaml/op_compat.yaml 中。
- 一般地我们只需要将旧 IR 下对应驼峰命名转为新 IR 下的下划线命名即可。
3.配置 infermeta 信息
- 根据旧 IR 下的 Op 文件中的 InferShape 来进行具体的配置。
- 一般情况下我们只需要将 InferShape 内的函数直接迁移到 InferMeta 下,修改一下函数的名称,删除 InferShapeContext 的相关逻辑即可。
- 详细的信息可以查看C++算子开发文档的3.2 实现 InferMeta 函数
一般情况下根据上面几步骤就能解决问题,有较为特殊的算子需要具体分析。
转译过程中的特殊处理
转译的过程一般通过 ProgramTranslator 来执行,在文件 paddle/fluid/ir_adaptor/translator/program_translator.cc
TranslateBlock 负责 BlockDesc 的转译,而 BlockDesc 内包含的 OpDesc 则是由 OpTranslator 负责,在文件 paddle/fluid/ir_adaptor/translator/op_translator.cc 下
通用的翻译规则一般是以下几步
- LoopkUpOpInfo 获得 yaml 里定义的 Op 的 input、output、attr 等等信息。
- GenerateOperationInput、GenerateOperationOutput 生成新 ir 下的输入输出。
- TranslateOpAttribute 转译 attr。
- 生成新 op,放入新 IR 中。
- RecordOpResultMapping 记录该 Op 新旧 ir 的 result 的映射关系。
在分析了特殊的情况后,可以根据定位的报错信息来具体改写相对应的函数。
验收标准
- 打开 FLAGS_enable_pir_in_executor 的情况下单测成功运行
- 为单测内的 test 函数添加装饰器 test_legacy_and_pir 并且成功运行。
Q&A
无
待修复的测试内容
经过测试,以下的案例在 new IR 下未通过测试。
序号 | 任务 | 失败原因 | PR | 开发者 |
---|---|---|---|---|
1 | test_build_strategy | 已部分修复,仍存在问题:反向中没有 Intermediate_out_grad | #57827 | @yangguohao |
2 | test_seq2seq | 部分解决,现在还存在 Lod_array_length,tensor_array 等问题 | ||
3 | test_lstm | CUDNN value error | ||
6 | test_len/test_slice/test_list | 部分修复,单测内都存在 lod_array_length 的问题 | ||
7 | test_error | pd_op.reshape raises an EnforceNotMet exception | @chen2016013 | |
8 | test_program_translator | IfOp 翻译过程出现问题 | ||
9 | test_lac | UserWarning: full_graph=False don't support input_spec arguments. It will not produce any effect.You can set full_graph=True, then you can assign input spec. | ||
10 | test_pylayer | Op pylayer should have corresponding OpInfo pd_op.pylayer | ||
12 | test_jit_setitem | While_instruction 的执行过程存在问题 |
以下的测试用例不会运行到转译和 PIR 执行器中,或是无需进行测试,在此记录。
序号 | 任务 | 失败原因 | PR | 开发者 |
---|---|---|---|---|
32 | test_eval_frame | |||
35 | test_op_attr | |||
36 | test_origin_info | |||
37 | test_params_no_grad | |||
38 | test_local_cast | |||
39 | test_tensor_hook | 无需修复 |
kangguangli and gouzil
Metadata
Metadata
Assignees
Labels
PFCCPaddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfccPaddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfccstatus/close已关闭已关闭