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

[PyLayer] pylayer add api #5148

Merged
merged 6 commits into from
Aug 22, 2022

Conversation

wanghuancoder
Copy link
Contributor

为PyLayer添加3个API的中文文档。
mark_not_inplace
set_materialize_grads
mark_non_differentiable

@paddle-bot
Copy link

paddle-bot bot commented Aug 17, 2022

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

Copy link
Collaborator

@momozi1996 momozi1996 left a comment

Choose a reason for hiding this comment

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

为了用户更清楚的了解新增的三个API的功能和参数,请在意见底下进行修改,辛苦了!

这个函数最多只能在 ``forward`` 调用一次,并且所有的参数必须是 ``forward`` 输入的 ``Tensor`` 。
如果 ``forward`` 的输入输出是同一个 ``Tensor`` ,并且这个 ``Tensor`` 被标记为 not_inplace 的。Paddle 会替用户创建一个新的 Tensor 作为输出。
这样可以防止输入的 ``Tensor`` 的 auto grad 信息被错误的篡改。

Copy link
Collaborator

Choose a reason for hiding this comment

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

需要补充mark_not_inplace(self, *args) 下参数args的说明,方便用户理解,参考此文档中save_for_backward(self, *tensors)对参数tensors的说明,如图片:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done,thx!


mark_not_inplace(self, *args)
'''''''''

Copy link
Collaborator

Choose a reason for hiding this comment

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

1、补充对mark_not_inplace(self, *args) 功能的一句话说明,便于用户理解。 参考此文档中save_for_backward(self, *tensors)的一句话说明:
image

2、注意事项,也可以参考图片中蓝色高亮的形式,优化一下。用户会更加清楚这个API的注意事项。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done,thx!


mark_non_differentiable(self, *args)
'''''''''

Copy link
Collaborator

Choose a reason for hiding this comment

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

1、补充对mark_non_differentiable(self, *args)功能的一句话说明,便于用户理解。 参考此文档中save_for_backward(self, *tensors)的一句话说明:
image

2、注意事项,也可以参考图片中蓝色高亮的形式,优化一下。用户会更加清楚这个API的注意事项。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done,thx!

如果 ``forward`` 的输入输出是同一个 ``Tensor`` ,并且这个 ``Tensor`` 被标记为 not_inplace 的。Paddle 会替用户创建一个新的 Tensor 作为输出。
将不需要反向的 ``Tensor`` 标记为 non-differentiable,可以提升反向的性能。但是你在 ``backward`` 函数的输入参数中,仍要为其留有反向梯度的位置。
只是这个反向梯度是 1 个全为 0 的、shape 和 ``forward`` 的输出一样的 ``Tensor`` .

Copy link
Collaborator

Choose a reason for hiding this comment

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

mark_non_differentiable(self, *args) 需要补充参数args的说明,方便用户理解。同上

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done,thx!


set_materialize_grads(self, value: bool)
'''''''''

Copy link
Collaborator

Choose a reason for hiding this comment

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

1、补充对set_materialize_grads(self, value: bool) 功能的一句话说明,便于用户理解。同上
2、注意事项,也可以参考图片中蓝色高亮的形式,优化一下。用户会更加清楚这个API的注意事项。
3、 value: bool) 这个地方,注意一下书写规范。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done,thx!

这个函数最多只能在 ``forward`` 中调用。
如果设置为 True,框架会将未初始化的反向梯度数据初始化为 0,然后再调用 ``backward`` 函数。
如果设置为 False,框架会将未初始化的反向梯度以 None 向 ``backward`` 函数传递。

Copy link
Collaborator

Choose a reason for hiding this comment

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

1、value: bool 能否特殊注明一下,同样需要单独对参数说明:参考图中:
image
2、说明一下是bool类型。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done,thx!

Copy link
Collaborator

@momozi1996 momozi1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@wanghuancoder wanghuancoder merged commit a6143dd into PaddlePaddle:develop Aug 22, 2022
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.

2 participants