You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册。
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.
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 Category
Operator Mechanism
PR Types
Deprecations
Description
Pcard-67164
What's New?
在 #66089 的基础上,移除了动态图下Yaml中关于 Reshape 算子的 XShape 字段,动静统一。具体修改如下:
1. 规范 yaml 定义
sparse_op.yaml
:无需改动,已为规范后的不带 XShape 形态dygraph_ops.yaml
:移除xshape
输出字段dygraph_backward.yaml
:reshape_grad 和 reshape_double_grad 移除 xshape并改为依赖x ,并标记 no_need_bufferstatic_ops.yaml
: 待移除reshape整个定义,与dygraph_ops.yaml 合并到 ops.yaml中,下个PR做static_backward.yaml
:待移除reshape_grad整个定义,与dygraph_backward.yaml 合并到backward.yaml中,下个PR做2. 规范 InferMeta 定义
移除
ReshapeGradInferMeta
,新增SameWithXInferMeta
,方便被Flatten/Squeeze/Unsqueeze 等反向算子给复用。3. 规范分布式spmd生成
一般而言,分布式的 spmd 生成逻辑默认是使用的 infermeta 相同的入参,但在dist_api_gen.py对于reshape特殊处理了,是由于reshape_grad的kernel参数表里没有使用x。个人觉得应该在reshape_grad的Kernel里显式地依赖x,下游其他组件就不用特殊处理了,故此PR 做了规范。
同时发现,在 reshape.cc 中有一个
ReshapeInferSpmdDynamic
,进行了如下处理:4. 规范前反向拆解逻辑
reshape是基础算子,只需要修改reshape_grad的签名,将 xshape 调整为 x 即可
5. 规范Kernel 命名和注册机制
对于旧静态图下Reshape2算子的执行,需要正确地将其关联到 ReshapeWithXShapeKernel。从实现上来看,需要在reshape_sig.cc里做修改,比如:
6. 动态图 inplace + stride 机制
reshape_ 在inplace 和stride 机制下,移除了xshape后,会导致x_dims获取错误,影响stride kernel 的计算逻辑。
动态图下的Inplace策略是DenseTensor的别名机制,为了避免infer meta阶段错误修改了了输入的Meta信息,导致在Kernel层面获取不到正确的infer_meta,因此优化了api_base.py里中对于InferMeta逻辑的处理。
对于 reshape_这里inplace的API中的部分字段,在infermeta之前做了临时DenseTensor的浅copy,保证infermeta是保留正确的Meta信息。比如,此PR下reshape_的Python C API 代码变动如下: