[Dy2Stat]Refactor convert_shape transformer logic #43846
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
Others
PR changes
Others
Describe
What's New?
重构了动转静中对于
x.shape
和paddle.shape
的转写逻辑,升级为JIT运行时动态图判断执行,解决了shape API的重要头部问题,用户不需要再手动去调整此类代码,极大地提升了用户的转写体验。1. 问题背景
在之前的动转静场景中,用户模型代码中经常用到类似
B, C, H, W = x.shape
的代码,但当x中包含动态shape时(值含有-1或None),上述代码在转静时会返回-1,失去了动态语义。因此动转静会做静态分析,将其转换为B,C,H,W = paddle.shape(x)
,这样处理有如下缺点:2. 迭代方案
此 PR 将 Tensor Shape逻辑转换为 JIT 动态判断执行,统一将
B, C, H, W = x.shape
转换为B, C, H, W = _jst.convert_shape(x)
:简而言之,分为如下两个场景:
3. 方案优势
升级后的方案,具有如下优势:
4. 主要工作
TODO: