PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
22.24k stars 5.58k forks source link

梯度裁剪 #32100

Closed songsong-L closed 1 year ago

songsong-L commented 3 years ago

想要实现一个类似梯度裁剪的功能,只是梯度处理办法不一样。 看了一下源码,总的来说是这样:

params_grads=>clip这个op=>return params_grads

不过没整明白params_grads怎么传进去的,以及怎么被应用到step()的。 之前就尝试过自定义op来实现,发现没有什么api把处理过的梯度放进去,突然想起来梯度裁剪的思路,请教一下!

paddle-bot-old[bot] commented 3 years ago

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网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!

MissPenguin commented 3 years ago

可以贴一下源码的位置吗

songsong-L commented 3 years ago

可以贴一下源码的位置吗

源码就是梯度裁剪的源码

https://github.com/PaddlePaddle/Paddle/blob/release/2.0/python/paddle/fluid/clip.py#L152

songsong-L commented 3 years ago

可以贴一下源码的位置吗

后面又研究了一下,optimizer优化器有个属性是存clip的,会判断这个属性,如果要裁剪,然后调用梯度裁剪的op,然后apply_minimize()。还是回归到了自定义op的问题上去了。