Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dy2static] add set_dynamic_shape for dy2static high-level users. #58155

Merged
merged 2 commits into from Oct 18, 2023

Conversation

2742195759
Copy link
Contributor

@2742195759 2742195759 commented Oct 17, 2023

PR types

Function optimization

PR changes

Others

Description

[Dy2static] add set_dynamic_shape for dy2static high-level users.
支持了控制流中动态修改shape的优化逻辑,不再需要使用reshape,可以直接使用这个函数:

        def dygraph_func(loop_number):
            mask = paddle.randn([2,2])
            paddle.jit.dy2static.utils_helper.set_dynamic_shape(mask, [-1, 2])
            n = paddle.randn([1,2])
            for i in range(loop_number):
                mask = paddle.concat([mask, n], axis=0)
                if mask.shape[0] == 5: 
                    break
            return mask

这里的 dygraph_func 中的mask是一个动态shape,可以被 set_dynamic_shape 来显示指定。
注意这里的shape一定要对应,可以将某些值变为 -1 ,不可以随便指定。否则会有未定义错误。后续会添加更多的断言。

PCard-66972

@paddle-bot
Copy link

paddle-bot bot commented Oct 17, 2023

你的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.

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

@2742195759 2742195759 merged commit 793da42 into PaddlePaddle:develop Oct 18, 2023
28 checks passed
@2742195759 2742195759 deleted the add-set-dynamic-shape branch October 18, 2023 10:34
hitywt pushed a commit to hitywt/Paddle that referenced this pull request Oct 24, 2023
jiahy0825 pushed a commit to jiahy0825/Paddle that referenced this pull request Oct 26, 2023
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants