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

Add jacobian and hessian #53331

Merged
merged 29 commits into from
Apr 27, 2023
Merged

Conversation

HydrogenSulfate
Copy link
Contributor

PR types

New features

PR changes

APIs

Description

Pcard-66961

Add 2 high-order differential API: paddle.autograd.jacobianpaddle.autograd.hessian,and related unitest file.

Move paddle.incubate.autograd.Jacobian/Hessian to paddle.incubate.autograd.functional.Jacobian/Hessian

already.
2. support non-inplace math operation via magical method overwriting.
2. increase TIMEOUT to 100
@paddle-bot
Copy link

paddle-bot bot commented Apr 25, 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.

@paddle-bot
Copy link

paddle-bot bot commented Apr 25, 2023

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

Copy link
Contributor

@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.

主要是一些格式对齐问题

The ``xs`` tuples are identical in one-to-one correspondence.

- When ``batch_axis=None``, only 0-dimensional Tensor or 1-dimensional Tensor is
supported, assuming the shape of ``xs`` is ``[N, ]``, the shape of ``ys`` is
Copy link
Contributor

Choose a reason for hiding this comment

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

该段开头部分,需要when对齐,如

  • When batch_axis=None, only 0-dimensional Tensor or 1-dimensional Tensor is
    supported, assuming the shape of xs is [N, ], the shape of ys is
    [M, ], then the output Jacobian matrix shape is [M, N].

否则会出现解析错误,下同
image

Returns:

Union[Tuple[Tuple[Jacobian, ...], ...], Tuple[Jacobian, ...], Jacobian]: Jacobian(s) of ys
deriveted from xs.
Copy link
Contributor

Choose a reason for hiding this comment

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

该行开头也和上一行对齐
image

``(([M1, M1], [M1, M2]), ([M2, M1], [M2, M2]))``

- When ``batch_axis=None``, only 0-dimensional Tensor or 1-dimensional Tensor is
supported, assuming that the shape of ``xs`` is ``[N, ]``, and the shape of ``ys`` is ``[ ]``(0-dimensional Tensor), the final output is a single Hessian matrix whose shape is ``[N, N]``.
Copy link
Contributor

Choose a reason for hiding this comment

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

开头和when对齐,而不是和 -对齐,下同

Returns:

Union[Tuple[Tuple[Hessian, ...], ...], Tuple[Hessian, ...], Hessian]: Hessian(s) of ys
deriveted from xs.
Copy link
Contributor

Choose a reason for hiding this comment

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

和上一行开头对齐

XieYunshen
XieYunshen previously approved these changes Apr 26, 2023
Copy link
Contributor

@XieYunshen XieYunshen left a comment

Choose a reason for hiding this comment

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

LGTM for set_tests_properties(test_autograd_dynamic PROPERTIES TIMEOUT 100)

sunzhongkai588
sunzhongkai588 previously approved these changes Apr 26, 2023
Copy link
Contributor

@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.

@HydrogenSulfate 文档问题后续提pr修复

):
xs_grad = xs_grad[0]
else:
xs_grad = paddle.incubate.autograd.grad(ys, xs, v)
Copy link
Contributor

Choose a reason for hiding this comment

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

正式接口的代码不应依赖incubate里的代码,
假设incubate里的代码全部删除或者发生修改,正式接口的代码需要能正常运行。

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

return xs


def _grad(ys, xs, v=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

这个函数名比较短,是否能在函数名称上体现一下跟grad的区别?
担心被认为是基础接口被其他代码调用

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

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@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.

文档问题后续修复

@cxxly cxxly merged commit e8d296e into PaddlePaddle:develop Apr 27, 2023
@HydrogenSulfate HydrogenSulfate deleted the addjachess branch April 27, 2023 03:40
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

6 participants