Skip to content

新增映射文档 #7104

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

Merged
merged 4 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
### [torch.nn.modules.module.register_module_forward_hook](https://pytorch.org/docs/stable/generated/torch.nn.modules.module.register_module_forward_hook.html)

```python
torch.nn.modules.module.register_module_forward_hook(hook, *, prepend=False, with_kwargs=False, always_call=False)
torch.nn.modules.module.register_module_forward_hook(hook, *, always_call=False)
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官方文档上面有,但我实际使用应该没有

```

### [paddle.nn.Layer.register_forward_post_hook](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#register-forward-post-hook-hook)
Expand All @@ -11,12 +11,10 @@ torch.nn.modules.module.register_module_forward_hook(hook, *, prepend=False, wit
paddle.nn.Layer.register_forward_post_hook(hook)
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
其中,PyTorch 为给全局所有 module 注册 hook,而 Paddle 为给单个 Layer 注册 hook。PyTorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| hook | hook | 被注册为 forward pre-hook 的函数。 |
| prepend | - | 钩子执行顺序控制,Paddle 无此参数,暂无转写方式。 |
| with_kwargs | - | 是否传递关键字参数,Paddle 无此参数,暂无转写方式。 |
| always_call | - | 是否强制调用钩子,Paddle 无此参数,暂无转写方式。 |
| always_call | - | 是否强制调用钩子,Paddle 无此参数,一般对训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ torch.nn.modules.module.register_module_forward_pre_hook(hook)
paddle.nn.Layer.register_forward_pre_hook(hook)
```

功能一致,参数完全一致,具体如下:
其中,PyTorch 为给全局所有 module 注册 hook,而 Paddle 为给单个 Layer 注册 hook。参数完全一致,具体如下:

### 参数映射

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_abs

### [torch.\_foreach_abs](https://pytorch.org/docs/stable/generated/torch._foreach_abs.html#torch-foreach-abs)

```python
torch._foreach_abs(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_abs(tensors)

# Paddle 写法
[paddle.abs(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_abs_

### [torch.\_foreach_abs_](https://pytorch.org/docs/stable/generated/torch._foreach_abs_.html#torch-foreach-abs)

```python
torch._foreach_abs_(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_abs_(tensors)

# Paddle 写法
[paddle.abs_(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_acos

### [torch.\_foreach_acos](https://pytorch.org/docs/stable/generated/torch._foreach_acos.html#torch-foreach-acos)

```python
torch._foreach_acos(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_acos(tensors)

# Paddle 写法
[paddle.acos(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_acos_

### [torch.\_foreach_acos_](https://pytorch.org/docs/stable/generated/torch._foreach_acos_.html#torch-foreach-acos)

```python
torch._foreach_acos_(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_acos_(tensors)

# Paddle 写法
[paddle.acos_(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_asin

### [torch.\_foreach_asin](https://pytorch.org/docs/stable/generated/torch._foreach_asin.html#torch-foreach-asin)

```python
torch._foreach_asin(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_asin(tensors)

# Paddle 写法
[paddle.asin(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_asin_

### [torch.\_foreach_asin_](https://pytorch.org/docs/stable/generated/torch._foreach_asin_.html#torch-foreach-asin)

```python
torch._foreach_asin_(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_asin_(tensors)

# Paddle 写法
[paddle.asin_(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_atan

### [torch.\_foreach_atan](https://pytorch.org/docs/stable/generated/torch._foreach_atan.html#torch-foreach-atan)

```python
torch._foreach_atan(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_atan(tensors)

# Paddle 写法
[paddle.atan(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_atan_

### [torch.\_foreach_atan_](https://pytorch.org/docs/stable/generated/torch._foreach_atan_.html#torch-foreach-atan)

```python
torch._foreach_atan_(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_atan_(tensors)

# Paddle 写法
[paddle.atan_(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_ceil

### [torch.\_foreach_ceil](https://pytorch.org/docs/stable/generated/torch._foreach_ceil.html#torch-foreach-ceil)

```python
torch._foreach_ceil(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_ceil(tensors)

# Paddle 写法
[paddle.ceil(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_cos

### [torch.\_foreach_cos](https://pytorch.org/docs/stable/generated/torch._foreach_cos.html#torch-foreach-cos)

```python
torch._foreach_cos(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_cos(tensors)

# Paddle 写法
[paddle.cos(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_cos_

### [torch.\_foreach_cos_](https://pytorch.org/docs/stable/generated/torch._foreach_cos_.html#torch-foreach-cos)

```python
torch._foreach_cos_(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_cos_(tensors)

# Paddle 写法
[paddle.cos_(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_cosh

### [torch.\_foreach_cosh](https://pytorch.org/docs/stable/generated/torch._foreach_cosh.html#torch-foreach-cosh)

```python
torch._foreach_cosh(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_cosh(tensors)

# Paddle 写法
[paddle.cosh(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_cosh_

### [torch.\_foreach_cosh_](https://pytorch.org/docs/stable/generated/torch._foreach_cosh_.html#torch-foreach-cosh)

```python
torch._foreach_cosh_(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_cosh_(tensors)

# Paddle 写法
[paddle.cosh_(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_erf

### [torch.\_foreach_erf](https://pytorch.org/docs/stable/generated/torch._foreach_erf.html#torch-foreach-erf)

```python
torch._foreach_erf(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_erf(tensors)

# Paddle 写法
[paddle.erf(x) for x in tensors]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [组合替代实现]torch.\_foreach_erf_

### [torch.\_foreach_erf_](https://pytorch.org/docs/stable/generated/torch._foreach_erf_.html#torch-foreach-erf)

```python
torch._foreach_erf_(self)
```

Paddle 无此 API,需要组合实现。

### 转写示例

```python
# PyTorch 写法
torch._foreach_erf_(tensors)

# Paddle 写法
[paddle.erf_(x) for x in tensors]
```
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@
| ALIAS-REFERENCE-ITEM(`torch.igamma`, `torch.special.gammainc`) |
| ALIAS-REFERENCE-ITEM(`torch.igammac`, `torch.special.gammaincc`) |
| ALIAS-REFERENCE-ITEM(`torch.distributions.multivariate_normal.MultivariateNormal`, `torch.distributions.MultivariateNormal`) |
| ALIAS-REFERENCE-ITEM(`torch.concatenate`, `torch.cat`) |

## <span id="id25">功能缺失的 API 列表</span>

Expand Down Expand Up @@ -1036,6 +1037,9 @@
| NOT-IMPLEMENTED-ITEM(`torch.layout`, https://pytorch.org/docs/stable/tensor_attributes.html#torch.layout, 可新增,但框架底层无相关设计,成本高) |
| NOT-IMPLEMENTED-ITEM(`torch.cuda.is_current_stream_capturing`, https://pytorch.org/docs/stable/generated/torch.cuda.is_current_stream_capturing.html#torch-cuda-is-current-stream-capturing, 可新增,且框架底层有相关设计,成本低) |
| NOT-IMPLEMENTED-ITEM(`torch.cuda.device_of`, https://pytorch.org/docs/stable/generated/torch.cuda.device_of.html, 可新增,且框架底层有相关设计,成本低) |
| NOT-IMPLEMENTED-ITEM(`torch.nn.modules.module.register_module_forward_hook`, https://pytorch.org/docs/stable/generated/torch.nn.modules.module.register_module_forward_hook.html, 可新增,且框架底层有相关设计,成本低) |
| NOT-IMPLEMENTED-ITEM(`torch.nn.modules.module.register_module_forward_pre_hook`, https://pytorch.org/docs/stable/generated/torch.nn.modules.module.register_module_forward_pre_hook.html, 可新增,且框架底层有相关设计,成本低) |


Copy link
Collaborator

Choose a reason for hiding this comment

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

torch.nn.modules.module.register_module_forward_hook的分类改了吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已经修改了,现在不在功能缺失的名单里面了

## <span id="id26">映射关系开发中的 API 列表</span>

Expand All @@ -1054,23 +1058,7 @@
| IN-DEVELOPMENT-PATTERN(`torch.nn.parameter.UninitializedBuffer`, https://pytorch.org/docs/stable/generated/torch.nn.parameter.UninitializedBuffer.html#torch.nn.parameter.UninitializedBuffer) |
| IN-DEVELOPMENT-PATTERN(`torch.autograd.Function.jvp`, https://pytorch.org/docs/stable/generated/torch.autograd.Function.jvp.html#torch-autograd-function-jvp) |
| IN-DEVELOPMENT-PATTERN(`torch.memory_format`, https://pytorch.org/docs/stable/tensor_attributes.html#torch.memory_format) |
| IN-DEVELOPMENT-PATTERN(`torch.concatenate`, https://pytorch.org/docs/stable/generated/torch.concatenate.html#torch-concatenate) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_abs`, https://pytorch.org/docs/stable/generated/torch._foreach_abs.html#torch-foreach-abs) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_abs_`, https://pytorch.org/docs/stable/generated/torch._foreach_abs_.html#torch-foreach-abs) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_acos`, https://pytorch.org/docs/stable/generated/torch._foreach_acos.html#torch-foreach-acos) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_acos_`, https://pytorch.org/docs/stable/generated/torch._foreach_acos_.html#torch-foreach-acos) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_asin`, https://pytorch.org/docs/stable/generated/torch._foreach_asin.html#torch-foreach-asin) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_asin_`, https://pytorch.org/docs/stable/generated/torch._foreach_asin_.html#torch-foreach-asin) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_atan`, https://pytorch.org/docs/stable/generated/torch._foreach_atan.html#torch-foreach-atan) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_atan_`, https://pytorch.org/docs/stable/generated/torch._foreach_atan_.html#torch-foreach-atan) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_ceil`, https://pytorch.org/docs/stable/generated/torch._foreach_ceil.html#torch-foreach-ceil) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_ceil_`, https://pytorch.org/docs/stable/generated/torch._foreach_ceil_.html#torch-foreach-ceil) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_cos`, https://pytorch.org/docs/stable/generated/torch._foreach_cos.html#torch-foreach-cos) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_cos_`, https://pytorch.org/docs/stable/generated/torch._foreach_cos_.html#torch-foreach-cos) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_cosh`, https://pytorch.org/docs/stable/generated/torch._foreach_cosh.html#torch-foreach-cosh) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_cosh_`, https://pytorch.org/docs/stable/generated/torch._foreach_cosh_.html#torch-foreach-cosh) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_erf`, https://pytorch.org/docs/stable/generated/torch._foreach_erf.html#torch-foreach-erf) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_erf_`, https://pytorch.org/docs/stable/generated/torch._foreach_erf_.html#torch-foreach-erf) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_erfc`, https://pytorch.org/docs/stable/generated/torch._foreach_erfc.html#torch-foreach-erfc) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_erfc_`, https://pytorch.org/docs/stable/generated/torch._foreach_erfc_.html#torch-foreach-erfc) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_exp`, https://pytorch.org/docs/stable/generated/torch._foreach_exp.html#torch-foreach-exp) |
Expand Down