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

新动态图模式SGD下降结果与之前版本不一致 #49782

Closed
JiehangXie opened this issue Jan 12, 2023 · 8 comments
Closed

新动态图模式SGD下降结果与之前版本不一致 #49782

JiehangXie opened this issue Jan 12, 2023 · 8 comments
Assignees

Comments

@JiehangXie
Copy link

bug描述 Describe the Bug

问题复现链接:https://aistudio.baidu.com/aistudio/projectdetail/5387434?sUid=168825&shared=1&ts=1673534614456

问题描述:2.4.0版本开始默认使用新动态图模式后,该项目SGD梯度下降的结果出现反向优化的情况。更换Adam、Momentum等优化器后,结果与2.3.2版本保持一致。经过代码对比后发现,2.4.0版本后SGD默认in_dygraph_mode()模式,底层部分代码改动较大,因此该部分出现BUG的概率比较大,希望官方能进一步排查。

以下分别为2.3.2,2.4.0,2.4.1版本下相同代码的结果,其中2.3.2为正常结果
691673534507_ pic

681673534121_ pic

671673533760_ pic

其他补充信息 Additional Supplementary Information

No response

@paddle-bot
Copy link

paddle-bot bot commented Jan 12, 2023

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

@paddle-bot paddle-bot bot added status/following-up 跟进中 and removed status/new-issue 新建 labels Jan 13, 2023
@AnnaTrainingG
Copy link
Contributor

你好 在paddle2.4版本的SGD API 中新增了multi_precision参数,因此在调用的时候需要保证参数对应哟,避免出现计算错误的问题。https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/optimizer/SGD_en.html
辛苦提供一下完成的模型运行demo便于进行后续问题定位

@paddle-bot paddle-bot bot removed the status/following-up 跟进中 label Jan 13, 2023
@JiehangXie
Copy link
Author

JiehangXie commented Jan 13, 2023

你好 在paddle2.4版本的SGD API 中新增了multi_precision参数,因此在调用的时候需要保证参数对应哟,避免出现计算错误的问题。https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/optimizer/SGD_en.html 辛苦提供一下完成的模型运行demo便于进行后续问题定位

问题没解决,这个项目里面有一个d2l的文件夹,里面paddle.py文件有一个train_ch6的函数,里面的SGD参数是有写参数名的,应该不是这个问题

def train_ch6(net, train_iter, test_iter, num_epochs, lr, device):
    """用GPU训练模型(在第六章定义)"""
    def init_weights(m):
        if type(m) == nn.Linear or type(m) == nn.Conv2D:
            nn.initializer.XavierUniform(m.weight)
    net.apply(init_weights)
    print('training on', device)
    net.to(device)
    optimizer = paddle.optimizer.SGD(learning_rate=lr, parameters=net.parameters())

@AnnaTrainingG
Copy link
Contributor

AnnaTrainingG commented Jan 13, 2023

2.4.0版本后SGD默认in_dygraph_mode()模式,底层部分代码改动较大,因此该部分出现BUG的概率比较大,希望官方能进一步排查。

你好,可以尝试手动在SGD代码调用处修改in_dygraph_mode的调用,直接走老动态图的形式,进一步验证in_dygraph_mode的问题。

  1. 当前常用的算子都是默认走in_dygraph_mode的。
  2. 从您之前的验证我们无法确定是SGD调用新动态图导致的,我本地也进行了验证,但是d2l一直报错。
  3. 同时您也可以直接save SGD的输入输出数据进一步验证SGD的正确性,或提供简易demo

@JiehangXie
Copy link
Author

2.4.0版本后SGD默认in_dygraph_mode()模式,底层部分代码改动较大,因此该部分出现BUG的概率比较大,希望官方能进一步排查。

你好,可以尝试手动在SGD代码调用处修改in_dygraph_mode的调用,直接走老动态图的形式,进一步验证in_dygraph_mode的问题。

  1. 当前常用的算子都是默认走in_dygraph_mode的。
  2. 从您之前的验证我们无法确定是SGD调用新动态图导致的,我本地也进行了验证,但是d2l一直报错。
  3. 同时您也可以直接save SGD的输入输出数据进一步验证SGD的正确性,或提供简易demo

701673620016_ pic

721673622412_ pic

第一张图是2.4.1原版的SGD代码,第二张图将in_dygraph_mode()里面的算子换成了_legacy_C_ops,跑出来的结果,legacy是正常的,bug确实极大可能出现在新动态图模式的算子,下面附上notebook代码,可以用vscode直接打开跑。

main.zip

@AnnaTrainingG
Copy link
Contributor

好的 感谢提供,我会尽快进行本地复现的请稍等

@paddle-bot paddle-bot bot added status/following-up 跟进中 and removed status/need-more-info 信息不全 labels Jan 17, 2023
@AnnaTrainingG
Copy link
Contributor

AnnaTrainingG commented Jan 29, 2023

你好 已经复现您说的现象,已联系相关api负责人

@paddle-bot paddle-bot bot closed this as completed Jan 30, 2024
Copy link

paddle-bot bot commented Feb 4, 2024

Since you haven't replied for more than a year, we have closed this issue/pr.
If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up.
由于您超过一年未回复,我们将关闭这个issue/pr。
若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants