From 44b9344b08f8acf8e2939e7e2d382a7accbba7eb Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Thu, 13 Mar 2025 20:39:38 +0800 Subject: [PATCH 1/4] update docs --- ...les.module.register_module_forward_hook.md | 8 +++----- ...module.register_module_forward_pre_hook.md | 2 +- .../torch/torch._foreach_abs.md | 19 ++++++++++++++++++ .../torch/torch._foreach_abs_.md | 19 ++++++++++++++++++ .../torch/torch._foreach_acos.md | 19 ++++++++++++++++++ .../torch/torch._foreach_acos_.md | 19 ++++++++++++++++++ .../torch/torch._foreach_asin.md | 19 ++++++++++++++++++ .../torch/torch._foreach_asin_.md | 19 ++++++++++++++++++ .../torch/torch._foreach_atan.md | 19 ++++++++++++++++++ .../torch/torch._foreach_atan_.md | 19 ++++++++++++++++++ .../torch/torch._foreach_ceil.md | 19 ++++++++++++++++++ .../torch/torch._foreach_cos.md | 19 ++++++++++++++++++ .../torch/torch._foreach_cos_.md | 19 ++++++++++++++++++ .../torch/torch._foreach_cosh.md | 19 ++++++++++++++++++ .../torch/torch._foreach_cosh_.md | 19 ++++++++++++++++++ .../torch/torch._foreach_erf.md | 19 ++++++++++++++++++ .../torch/torch._foreach_erf_.md | 19 ++++++++++++++++++ .../pytorch_api_mapping_cn.md | 20 ++++--------------- 18 files changed, 293 insertions(+), 22 deletions(-) create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_abs.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_abs_.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_acos.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_acos_.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_asin.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_asin_.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_atan.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_atan_.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cos.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cos_.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cosh.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cosh_.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erf.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erf_.md diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md index 0f003d4fb79..fb4a0a030ec 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md @@ -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) ``` ### [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) @@ -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 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md index fec1fe697c2..219f4d535e5 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md @@ -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。参数完全一致,具体如下: ### 参数映射 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_abs.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_abs.md new file mode 100644 index 00000000000..a5cd941f425 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_abs.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_abs_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_abs_.md new file mode 100644 index 00000000000..c042098546e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_abs_.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_acos.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_acos.md new file mode 100644 index 00000000000..26388d16fb1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_acos.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_acos_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_acos_.md new file mode 100644 index 00000000000..1d3a948cd8b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_acos_.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_asin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_asin.md new file mode 100644 index 00000000000..947dfb9143d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_asin.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_asin_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_asin_.md new file mode 100644 index 00000000000..b0681f6b38d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_asin_.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_atan.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_atan.md new file mode 100644 index 00000000000..309375b63f3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_atan.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_atan_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_atan_.md new file mode 100644 index 00000000000..5816dca2257 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_atan_.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil.md new file mode 100644 index 00000000000..887efbdab19 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cos.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cos.md new file mode 100644 index 00000000000..5c4a79ca6c9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cos.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cos_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cos_.md new file mode 100644 index 00000000000..d84b577c229 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cos_.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cosh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cosh.md new file mode 100644 index 00000000000..10152f0a7c4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cosh.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cosh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cosh_.md new file mode 100644 index 00000000000..11ffca5a1c6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_cosh_.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erf.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erf.md new file mode 100644 index 00000000000..954fb7242e1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erf.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erf_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erf_.md new file mode 100644 index 00000000000..fe3474866f5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erf_.md @@ -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] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md b/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md index 4a22caf0ac8..996c492d260 100644 --- a/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md +++ b/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md @@ -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`) | ## 功能缺失的 API 列表 @@ -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, 可新增,且框架底层有相关设计,成本低) | + ## 映射关系开发中的 API 列表 @@ -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) | From a9b4b0155711aad4c68fd9e580b8e73825bf1d75 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Sat, 15 Mar 2025 20:42:22 +0800 Subject: [PATCH 2/4] update docs --- ...modules.module.register_module_forward_hook.md | 15 +++++++++++++-- ...les.module.register_module_forward_pre_hook.md | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md index fb4a0a030ec..658e24316b5 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md @@ -1,4 +1,4 @@ -## [ torch 参数更多 ]torch.nn.modules.module.register_module_forward_hook +## [ 组合替代实现 ]torch.nn.modules.module.register_module_forward_hook ### [torch.nn.modules.module.register_module_forward_hook](https://pytorch.org/docs/stable/generated/torch.nn.modules.module.register_module_forward_hook.html) ```python @@ -16,5 +16,16 @@ paddle.nn.Layer.register_forward_post_hook(hook) | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | -| hook | hook | 被注册为 forward pre-hook 的函数。 | +| hook | hook | 被注册为 forward post-hook 的函数。 | | always_call | - | 是否强制调用钩子,Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | + +### 转写示例 + +```python +# PyTorch 写法 +torch.nn.modules.module.register_module_forward_hook(hook) + +# Paddle 写法 +for layer in model.sublayers(): + layer.register_forward_post_hook(hook) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md index 219f4d535e5..07eb0b9e0ee 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md @@ -1,4 +1,4 @@ -## [ 参数完全一致 ]torch.nn.modules.module.register_module_forward_pre_hook +## [ 组合替代实现 ]torch.nn.modules.module.register_module_forward_pre_hook ### [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) @@ -12,10 +12,21 @@ torch.nn.modules.module.register_module_forward_pre_hook(hook) paddle.nn.Layer.register_forward_pre_hook(hook) ``` -其中,PyTorch 为给全局所有 module 注册 hook,而 Paddle 为给单个 Layer 注册 hook。参数完全一致,具体如下: +其中,PyTorch 为给全局所有 module 注册 hook,而 Paddle 为给单个 Layer 注册 hook, 具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | |---------|--------------|-----------------------------------------------------------------------------------------------| | hook | hook | 被注册为 forward pre-hook 的函数。 | + +### 转写示例 + +```python +# PyTorch 写法 +torch.nn.modules.module.register_module_forward_pre_hook(hook) + +# Paddle 写法 +for layer in model.sublayers(): + layer.register_forward_pre_hook(hook) +``` From 6f0d4a036ab3e075b43a8bc26a351256ada02dc6 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Sat, 15 Mar 2025 21:05:03 +0800 Subject: [PATCH 3/4] update docs --- .../convert_from_pytorch/pytorch_api_mapping_cn.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md b/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md index 996c492d260..fd8d34dd595 100644 --- a/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md +++ b/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md @@ -1037,8 +1037,6 @@ | 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, 可新增,且框架底层有相关设计,成本低) | ## 映射关系开发中的 API 列表 From f754268cb95c5e3dad04d40d084bde1d74b82825 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Mon, 17 Mar 2025 13:56:33 +0800 Subject: [PATCH 4/4] update docs --- ....nn.modules.module.register_module_forward_hook.md | 11 +++++++++-- ...modules.module.register_module_forward_pre_hook.md | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md index 658e24316b5..4544be7b9dd 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md @@ -23,9 +23,16 @@ paddle.nn.Layer.register_forward_post_hook(hook) ```python # PyTorch 写法 +Linear = torch.nn.Linear(2, 4) +Conv2d = torch.nn.Conv2d(3, 16, 3) +Batch2d = torch.nn.BatchNorm2d(10) torch.nn.modules.module.register_module_forward_hook(hook) # Paddle 写法 -for layer in model.sublayers(): - layer.register_forward_post_hook(hook) +Linear = paddle.nn.Linear(2, 4) +Conv2d = paddle.nn.Conv2d(3, 16, 3) +Batch2d = paddle.nn.BatchNorm2D(10) +Linear.register_forward_post_hook(hook) +Conv2d.register_forward_post_hook(hook) +Batch2d.register_forward_post_hook(hook) ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md index 07eb0b9e0ee..ebff2a16c1c 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md @@ -24,9 +24,16 @@ paddle.nn.Layer.register_forward_pre_hook(hook) ```python # PyTorch 写法 +Linear = torch.nn.Linear(2, 4) +Conv2d = torch.nn.Conv2d(3, 16, 3) +Batch2d = torch.nn.BatchNorm2d(10) torch.nn.modules.module.register_module_forward_pre_hook(hook) # Paddle 写法 -for layer in model.sublayers(): - layer.register_forward_pre_hook(hook) +Linear = paddle.nn.Linear(2, 4) +Conv2d = paddle.nn.Conv2d(3, 16, 3) +Batch2d = paddle.nn.BatchNorm2D(10) +Linear.register_forward_pre_hook(hook) +Conv2d.register_forward_pre_hook(hook) +Batch2d.register_forward_pre_hook(hook) ```