Skip to content

Commit

Permalink
Dev add jvp jacobian hessian (#10412)
Browse files Browse the repository at this point in the history
## 分支工作

添加jvp、jacobian、hessian、hvp、vhp接口到funcitional.py文件,添加测试代码到test_autograd_functional.py文件
## 代码修改部分
1. \_construct_standard_basis_for(): 因fill_ 不支持
NonContiguous,将fill_赋值替换为循环赋值。
(#10394)
2. \_construct_standard_basis_for(): 函数参数tensors: Tuple[torch.Tensor,
...]的写法会导致循环导入torch,因此将后面的描述去掉,变为tensors
3.
_grad_preprocess:因oneflow.torch没有is_sparse属性,只采用res.append(inp.view_as(inp))方式创建新tensor
4. _jacfwd: 删除vectorize情况的代码
5. 在test_autograd_functional.py文件中添加jvp、jacobian、hessian、hvp、vhp测试代码
## 添加接口

![1704862723128](https://github.com/Oneflow-Inc/oneflow/assets/49504565/8ca9cfa6-0f1c-425b-baa1-036335e3d3e1)

---------

Co-authored-by: Wang Yi <53533850+marigoold@users.noreply.github.com>
Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent 06c9ead commit b229019
Show file tree
Hide file tree
Showing 4 changed files with 956 additions and 27 deletions.
7 changes: 6 additions & 1 deletion docs/source/autograd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ functional
:toctree: generated
:nosignatures:

vjp
vjp
jvp
jacobian
hessian
vhp
hvp
7 changes: 7 additions & 0 deletions python/oneflow/autograd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
is_grad_enabled,
no_grad,
)
from oneflow.autograd.functional import vjp, jvp, jacobian, hessian, hvp, vhp
from . import graph

__all__ = [
Expand All @@ -34,4 +35,10 @@
"inference_mode",
"is_grad_enabled",
"no_grad",
"vjp",
"jvp",
"jacobian",
"hessian",
"hvp",
"vhp",
]
Loading

0 comments on commit b229019

Please sign in to comment.