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

【Hackathon 6th No. 27】为 paddle.io.RandomSampler/random_split /Layer.clear_gradients 进行功能增强 #6594

Merged
merged 2 commits into from
Apr 10, 2024

Conversation

NKNaN
Copy link
Contributor

@NKNaN NKNaN commented Apr 6, 2024

Copy link

paddle-bot bot commented Apr 6, 2024

感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-6594.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html
预览工具的更多说明,请参考:飞桨文档预览工具

@luotao1 luotao1 added the PaddlePaddle Hackathon 飞桨黑客松活动issue与PR label Apr 8, 2024
zhwesky2010 pushed a commit to zhwesky2010/docs that referenced this pull request Apr 8, 2024
* add backednds.cudnn.version

* add celu

* add torch.distributed.ReduceOp

* update some docs

* update some docs of PaddlePaddle#6594

* update some docs
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
PyTorch 的 `Module.zero_grad` 参数与 Paddle 的 `Layer.clear_gradients` 参数用法不同,具体如下:
Copy link
Collaborator

Choose a reason for hiding this comment

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

这两个写 参数用法刚好相反,这样好理解些

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改


### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ----------- | ------------ | ------------------------------------------------ |
| set_to_none | - | 是否设置为 None,Paddle 无此参数,暂无转写方式。 |
| set_to_none | set_to_zero | 设置如何清空梯度,PyTorch 默认设置为 None,Paddle 默认设置为 0,需要转写。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pytoch直接写None的表现吧,None就是设为True的意思吧

两者功能刚好相反,Paddle需设置为False

写的时候尽量让用户一眼就能直观看明白双方的差异(这个的差异是两者功能刚好相反),所以你要加入一些自己的理解,而不是直接复制原参数介绍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,已修改

@@ -9,13 +9,23 @@ torch.nn.Module.zero_grad(set_to_none=True)
### [paddle.nn.Layer.clear_gradients](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#clear-gradients)

```python
paddle.nn.Layer.clear_gradients()
paddle.nn.Layer.clear_gradients(set_to_zero=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

后面再给 paddle.nn.Layer.clear_gradients 加一个别名 paddle.nn.Layer.clear_grad 吧,这样可以和 paddle.optim.Optimizer.clear_grad 完全对应上

Copy link
Collaborator

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhwesky2010 zhwesky2010 merged commit f7683fc into PaddlePaddle:develop Apr 10, 2024
2 checks passed
@NKNaN NKNaN changed the title 【Hackthon 6th No. 27】为 paddle.io.RandomSampler/random_split /Layer.clear_gradients 进行功能增强 【Hackathon 6th No. 27】为 paddle.io.RandomSampler/random_split /Layer.clear_gradients 进行功能增强 Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor PaddlePaddle Hackathon 飞桨黑客松活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants