From 92427f999b401c34aa45de811306926b68d75b57 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Wed, 13 Nov 2024 23:44:12 +0800 Subject: [PATCH 01/18] fix-docs --- .../api_difference/others/os.environ.get.md | 22 +++++++++++++++++ .../api_difference/others/setuptools.setup.md | 21 ++++++++++++++++ .../api_difference/torch/torch.pi.md | 15 ++++++++++++ .../torch.utils.checkpoint.checkpoint.md | 24 +++++++++++++++++++ ...tn.flash_attn_interface.flash_attn_func.md | 6 ++--- ...attn_interface.flash_attn_unpadded_func.md | 10 ++++---- ...on.transforms.InterpolationMode.BICUBIC.md | 15 ++++++++++++ ...n.transforms.InterpolationMode.BILINEAR.md | 15 ++++++++++++ ...vision.transforms.InterpolationMode.BOX.md | 15 ++++++++++++ ...on.transforms.InterpolationMode.HAMMING.md | 15 ++++++++++++ ...on.transforms.InterpolationMode.LANCZOS.md | 15 ++++++++++++ ...on.transforms.InterpolationMode.NEAREST.md | 15 ++++++++++++ ...nsforms.InterpolationMode.NEAREST_EXACT.md | 15 ++++++++++++ 13 files changed, 195 insertions(+), 8 deletions(-) create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BICUBIC.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BILINEAR.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BOX.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.HAMMING.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.LANCZOS.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST_EXACT.md diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md new file mode 100644 index 00000000000..7bcb9c7afcc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md @@ -0,0 +1,22 @@ +## [ 组合替代实现 ]os.environ.get + +### [os.environ.get](https://docs.python.org/zh-cn/3/library/os.html#os.environ) + +```python +os.environ.get(key, value) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法value +os.environ.get(key) + +# Paddle 写法 +if key =="WORLD_SIZE" + paddle.distributed.get_world_size() +else if key =="LOCAL_RANK" + padlde.distributed.get_rank() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md new file mode 100644 index 00000000000..8b72cd61cb2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md @@ -0,0 +1,21 @@ +## [ 组合替代实现 ]setuptools.setup + +### [setuptools.setup](https://setuptools.pypa.io/en/latest/userguide/quickstart.html) + +```python +setuptools.setup(*args, **attrs) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法value +setuptools.setup(*args, **attrs) + +# Paddle 写法 +if "cmdclass" in attrs: + if "paddle.utils.cpp_extension.BuildExtension" in attrs["cmdclass"]: + paddle.utils.cpp_extension.setup(attrs) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md new file mode 100644 index 00000000000..d89e99734be --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.pi + +### [torch.pi](https://github.com/pytorch/pytorch) + +```python +torch.pi +``` + +### [numpy.pi](https://github.com/numpy/numpy) + +```python +numpy.pi +``` + +功能一致,无参数。 \ No newline at end of file diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md new file mode 100644 index 00000000000..88fa7d81a22 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md @@ -0,0 +1,24 @@ +## [ torch 参数更多 ]torch.utils.checkpoint.checkpoint +### [torch.utils.checkpoint.checkpoint](https://pytorch.org/docs/stable/checkpoint.html#torch.utils.checkpoint.checkpoint) + +```python +torch.utils.checkpoint.checkpoint(function, *args, use_reentrant=True, **kwargs) +``` + +### [paddle.utils.cpp_extension.CppExtension](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/cpp_extension/CppExtension_cn.html) + +```python +paddle.distributed.fleet.utils.recompute(function, *args, **kwargs) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| function | function | 模型前向传播的部分连续的层函数组成的序列。 | +| preserve_rng_state | preserve_rng_state | 是否保存前向的 rng。 | +| use_reentrant | use_reentrant | recompute 的实现方式。 | +| determinism_check | - | 控制是否在反向传播时检查操作的确定性, Paddle 无此参数,暂无转写方式。 | +|*args | *args | function 的输入。 | +| **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/flash_attn/flash_attn.flash_attn_interface.flash_attn_func.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/flash_attn/flash_attn.flash_attn_interface.flash_attn_func.md index af0d5600aa2..1e6f1f45b75 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/flash_attn/flash_attn.flash_attn_interface.flash_attn_func.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/flash_attn/flash_attn.flash_attn_interface.flash_attn_func.md @@ -29,6 +29,6 @@ paddle.nn.functional.flash_attention.flash_attention(query, key, value, dropout= | deterministic | - | 是否应用确定性实现,Paddle 无此参数,暂无转写方式。 | | alibi_slopes | - | 用于注意力得分间的 bias,Paddle 无此参数,暂无转写方式。| | return_attn_probs | return_softmax | 是否返回注意力概率。 | -| | fixed_seed_offset | 为 dropout mask 固定 sedd, offset,PyTorch 无此参数,Paddle 保持默认即可。 | -| | rng_name | 选定 rng Generator,PyTorch 无此参数,Paddle 保持默认即可。 | -| | training | 是否在训练阶段,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | fixed_seed_offset | 为 dropout mask 固定 sedd, offset,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | rng_name | 选定 rng Generator,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | training | 是否在训练阶段,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/flash_attn/flash_attn.flash_attn_interface.flash_attn_unpadded_func.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/flash_attn/flash_attn.flash_attn_interface.flash_attn_unpadded_func.md index 880814bd9bc..8d13db0be99 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/flash_attn/flash_attn.flash_attn_interface.flash_attn_unpadded_func.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/flash_attn/flash_attn.flash_attn_interface.flash_attn_unpadded_func.md @@ -25,7 +25,7 @@ max_seqlen_q, max_seqlen_k, scale,dropout=0.0, causal=False, return_softmax=Fals | cu_seqlens_q | cu_seqlens_q | batch 中累计序列长度,用于索引 q。| | cu_seqlens_k | cu_seqlens_k | batch 中累计序列长度,用于索引 k。| | max_seqlen_q | max_seqlen_q | query 最大序列长度。| -| max_seqlen_k | max_seqlen_v | key 最大序列长度。| +| max_seqlen_k | max_seqlen_k | key 最大序列长度。| | dropout_p | dropout | 丢弃概率。 | | softmax_scale | scale | QK^T 的缩放因子。 | | causal | causal | 是否应用因果注意力 mask。 | @@ -35,7 +35,7 @@ max_seqlen_q, max_seqlen_k, scale,dropout=0.0, causal=False, return_softmax=Fals | alibi_slopes | - | 用于注意力得分间的 bias,Paddle 无此参数,暂无转写方式。 | | block_table | - | block 表,用于 paged KV cache,Paddle 无此参数,暂无转写方式。 | | return_attn_probs | return_softmax | 是否返回注意力概率。 | -| | fixed_seed_offset | 为 dropout mask 固定 sedd, offset,PyTorch 无此参数,Paddle 保持默认即可。 | -| | rng_name | 选定 rng Generator,PyTorch 无此参数,Paddle 保持默认即可。 | -| | training | 是否在训练阶段,PyTorch 无此参数,Paddle 保持默认即可。 | -| | name | 名称,PyTorch 无此参数,Paddle 保持默认即可。| +| - | fixed_seed_offset | 为 dropout mask 固定 sedd, offset,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | rng_name | 选定 rng Generator,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | training | 是否在训练阶段,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | name | 名称,PyTorch 无此参数,Paddle 保持默认即可。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BICUBIC.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BICUBIC.md new file mode 100644 index 00000000000..8424f5785e8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BICUBIC.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torchvision.transforms.InterpolationMode.BICUBIC + +### [torchvision.transforms.InterpolationMode.BICUBIC](https://pytorch.org/vision/stable/index.html) + +```python +torchvision.transforms.InterpolationMode.BICUBIC +``` + +### ['bicubic']() + +```python +'bicubic' +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BILINEAR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BILINEAR.md new file mode 100644 index 00000000000..cbc4d550564 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BILINEAR.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torchvision.transforms.InterpolationMode.BILINEAR + +### [torchvision.transforms.InterpolationMode.BILINEAR](https://pytorch.org/vision/stable/index.html) + +```python +torchvision.transforms.InterpolationMode.BILINEAR +``` + +### ['bilinear']() + +```python +'bilinear' +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BOX.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BOX.md new file mode 100644 index 00000000000..482bdd9e8ac --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BOX.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torchvision.transforms.InterpolationMode.BOX + +### [torchvision.transforms.InterpolationMode.BOX](https://pytorch.org/vision/stable/index.html) + +```python +torchvision.transforms.InterpolationMode.BOX +``` + +### ['box']() + +```python +'box' +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.HAMMING.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.HAMMING.md new file mode 100644 index 00000000000..0b324d7c316 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.HAMMING.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torchvision.transforms.InterpolationMode.HAMMING + +### [torchvision.transforms.InterpolationMode.HAMMING](https://pytorch.org/vision/stable/index.html) + +```python +torchvision.transforms.InterpolationMode.HAMMING +``` + +### ['hamming']() + +```python +'hamming' +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.LANCZOS.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.LANCZOS.md new file mode 100644 index 00000000000..63bc3717beb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.LANCZOS.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torchvision.transforms.InterpolationMode.LANCZOS + +### [torchvision.transforms.InterpolationMode.LANCZOS](https://pytorch.org/vision/stable/index.html) + +```python +torchvision.transforms.InterpolationMode.LANCZOS +``` + +### ['lanczos']() + +```python +'lanczos' +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST.md new file mode 100644 index 00000000000..a871a439851 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torchvision.transforms.InterpolationMode.NEAREST + +### [torchvision.transforms.InterpolationMode.NEAREST](https://pytorch.org/vision/stable/index.html) + +```python +torchvision.transforms.InterpolationMode.NEAREST +``` + +### ['nearest']() + +```python +'nearest' +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST_EXACT.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST_EXACT.md new file mode 100644 index 00000000000..595c041b388 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST_EXACT.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torchvision.transforms.InterpolationMode.NEAREST_EXACT + +### [torchvision.transforms.InterpolationMode.NEAREST_EXACT](https://pytorch.org/vision/stable/index.html) + +```python +torchvision.transforms.InterpolationMode.NEAREST_EXACT +``` + +### ['nearest_exact']() + +```python +'nearest_exact' +``` + +两者功能一致,无参数。 From 736b09b2221d9d393a1905cf46f713d99d324dd2 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Wed, 13 Nov 2024 23:57:15 +0800 Subject: [PATCH 02/18] fix pi --- .../convert_from_pytorch/api_difference/torch/torch.pi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md index d89e99734be..35e4aed5288 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md @@ -12,4 +12,4 @@ torch.pi numpy.pi ``` -功能一致,无参数。 \ No newline at end of file +功能一致,无参数。 From a91a4a35a083c0125a7457614c62264494b73969 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Thu, 14 Nov 2024 00:05:42 +0800 Subject: [PATCH 03/18] fix pi --- .../convert_from_pytorch/api_difference/torch/torch.pi.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md index 35e4aed5288..9c98dffb31d 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md @@ -3,13 +3,13 @@ ### [torch.pi](https://github.com/pytorch/pytorch) ```python -torch.pi +torch.pi() ``` ### [numpy.pi](https://github.com/numpy/numpy) ```python -numpy.pi +numpy.pi() ``` 功能一致,无参数。 From 232cb91d78769a53bbf002f47a8985400fa998dd Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Thu, 14 Nov 2024 11:54:54 +0800 Subject: [PATCH 04/18] fix docs --- .../api_difference/torch/torch.pi.md | 4 ++-- .../utils/torch.utils.checkpoint.checkpoint.md | 2 +- .../convert_from_pytorch/tools/validate_mapping_files.py | 9 +++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md index 9c98dffb31d..35e4aed5288 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.pi.md @@ -3,13 +3,13 @@ ### [torch.pi](https://github.com/pytorch/pytorch) ```python -torch.pi() +torch.pi ``` ### [numpy.pi](https://github.com/numpy/numpy) ```python -numpy.pi() +numpy.pi ``` 功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md index 88fa7d81a22..1c597bf17be 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md @@ -5,7 +5,7 @@ torch.utils.checkpoint.checkpoint(function, *args, use_reentrant=True, **kwargs) ``` -### [paddle.utils.cpp_extension.CppExtension](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/cpp_extension/CppExtension_cn.html) +### [paddle.distributed.fleet.utils.recompute](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/cpp_extension/CppExtension_cn.html) ```python paddle.distributed.fleet.utils.recompute(function, *args, **kwargs) diff --git a/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py b/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py index 3b5596511c1..302ad42ec27 100644 --- a/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py +++ b/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py @@ -300,7 +300,8 @@ def get_meta_from_diff_file( if title_match: mapping_type = title_match["type"].strip() src_api = unescape_api(title_match["src_api"].strip()) - + if src_api == "torch.pi": + dst_prefix="numpy." meta_data["src_api"] = unescape_api(src_api) meta_data["mapping_type"] = mapping_type @@ -326,6 +327,9 @@ def get_meta_from_diff_file( meta_data["src_api_url"] = real_url state = ParserState.wait_for_src_signature_begin elif state == ParserState.wait_for_dst_api: + paddle_pattern = re.compile( + rf"^### +\[ *(?P{re.escape(dst_prefix)}[^\]]+)\](\((?P[^\)]*)\))?$" + ) paddle_match = paddle_pattern.match(line) if paddle_match: @@ -472,7 +476,7 @@ def get_meta_from_diff_file( f"Unexpected state {state} when process {filepath} line: {line}" ) - # print(state) + # 允许没有参数映射列表 if mapping_type in ["无参数", "组合替代实现"]: @@ -492,6 +496,7 @@ def get_meta_from_diff_file( # 映射类型前三个级别必须要有对应的 dst_api if mapping_type_to_level[mapping_type] <= 3: if state != ParserState.end: + print(state) raise Exception( f"Unexpected End State at {state} in parsing file: {filepath}, current meta: {meta_data}" ) From 13b8becd63e9391c0920118287b3ac368f298160 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Thu, 14 Nov 2024 12:32:55 +0800 Subject: [PATCH 05/18] fix docs --- .../api_difference/others/os.environ.get.md | 2 +- .../api_difference/others/setuptools.setup.md | 2 +- .../convert_from_pytorch/tools/validate_mapping_files.py | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md index 7bcb9c7afcc..30436196462 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md @@ -11,7 +11,7 @@ Paddle 无此 API,需要组合实现。 ### 转写示例 ```python -# PyTorch 写法value +# PyTorch 写法 os.environ.get(key) # Paddle 写法 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md index 8b72cd61cb2..5961c1e28b9 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md @@ -11,7 +11,7 @@ Paddle 无此 API,需要组合实现。 ### 转写示例 ```python -# PyTorch 写法value +# PyTorch 写法 setuptools.setup(*args, **attrs) # Paddle 写法 diff --git a/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py b/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py index 302ad42ec27..e8f67254ea7 100644 --- a/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py +++ b/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py @@ -301,7 +301,7 @@ def get_meta_from_diff_file( mapping_type = title_match["type"].strip() src_api = unescape_api(title_match["src_api"].strip()) if src_api == "torch.pi": - dst_prefix="numpy." + dst_prefix = "numpy." meta_data["src_api"] = unescape_api(src_api) meta_data["mapping_type"] = mapping_type @@ -476,8 +476,6 @@ def get_meta_from_diff_file( f"Unexpected state {state} when process {filepath} line: {line}" ) - - # 允许没有参数映射列表 if mapping_type in ["无参数", "组合替代实现"]: if state == ParserState.wait_for_args: From 832dc5901f50fbc2b5dc41588e8c3e4d36e2123b Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Thu, 14 Nov 2024 16:15:48 +0800 Subject: [PATCH 06/18] fix docs --- .../api_difference/others/os.environ.get.md | 2 +- .../api_difference/others/setuptools.setup.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md index 30436196462..056441b06ea 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md @@ -11,7 +11,7 @@ Paddle 无此 API,需要组合实现。 ### 转写示例 ```python -# PyTorch 写法 +# PyTorch 写法 os.environ.get(key) # Paddle 写法 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md index 5961c1e28b9..ad4c8c8e75d 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md @@ -11,7 +11,7 @@ Paddle 无此 API,需要组合实现。 ### 转写示例 ```python -# PyTorch 写法 +# PyTorch 写法 setuptools.setup(*args, **attrs) # Paddle 写法 From 299d8a1a450367e41d9fdc5659c11254875fef4c Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Sun, 17 Nov 2024 22:09:04 +0800 Subject: [PATCH 07/18] fix bugs --- .../api_difference/others/os.environ.get.md | 2 +- .../api_difference/others/setuptools.setup.md | 2 +- .../utils/torch.utils.checkpoint.checkpoint.md | 4 ++-- .../torchvision.transforms.InterpolationMode.BICUBIC.md | 2 +- .../torchvision.transforms.InterpolationMode.BILINEAR.md | 2 +- .../torchvision.transforms.InterpolationMode.BOX.md | 2 +- .../torchvision.transforms.InterpolationMode.HAMMING.md | 2 +- .../torchvision.transforms.InterpolationMode.LANCZOS.md | 2 +- .../torchvision.transforms.InterpolationMode.NEAREST.md | 2 +- ...chvision.transforms.InterpolationMode.NEAREST_EXACT.md | 2 +- .../convert_from_pytorch/tools/validate_mapping_files.py | 8 ++++++-- 11 files changed, 17 insertions(+), 13 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md index 056441b06ea..7d042a5a506 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md @@ -6,7 +6,7 @@ os.environ.get(key, value) ``` -Paddle 无此 API,需要组合实现。 +Paddle 无此 API,需要组合实现。该API一般情况下与Paddle无关,仅在torch分布式相关的深度学习用法里才需转写。可以用来获取参与分布式训练的进程总数,以及获取当前进程的rank。 ### 转写示例 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md index ad4c8c8e75d..4b9d8e437c4 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md @@ -6,7 +6,7 @@ setuptools.setup(*args, **attrs) ``` -Paddle 无此 API,需要组合实现。 +Paddle 无此 API,需要组合实现。该API一般情况下与Paddle无关,仅在torch分布式相关的深度学习用法里才需转写,用来构建一个包含自定义扩展(如 C++ )的 PyTorch 包。 ### 转写示例 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md index 1c597bf17be..0e46326efea 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md @@ -2,13 +2,13 @@ ### [torch.utils.checkpoint.checkpoint](https://pytorch.org/docs/stable/checkpoint.html#torch.utils.checkpoint.checkpoint) ```python -torch.utils.checkpoint.checkpoint(function, *args, use_reentrant=True, **kwargs) +torch.utils.checkpoint.checkpoint(function, preserve_rng_state=True, use_reentrant=True, determinism_check="default", *args, **kwargs) ``` ### [paddle.distributed.fleet.utils.recompute](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/cpp_extension/CppExtension_cn.html) ```python -paddle.distributed.fleet.utils.recompute(function, *args, **kwargs) +paddle.distributed.fleet.utils.recompute(function, preserve_rng_state=True, use_reentrant=True, *args, **kwargs) ``` PyTorch 相比 Paddle 支持更多其他参数,具体如下: diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BICUBIC.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BICUBIC.md index 8424f5785e8..98ca3ce29a2 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BICUBIC.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BICUBIC.md @@ -12,4 +12,4 @@ torchvision.transforms.InterpolationMode.BICUBIC 'bicubic' ``` -两者功能一致,无参数。 +枚举对应到字符串,两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BILINEAR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BILINEAR.md index cbc4d550564..ee2ae73a4a9 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BILINEAR.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BILINEAR.md @@ -12,4 +12,4 @@ torchvision.transforms.InterpolationMode.BILINEAR 'bilinear' ``` -两者功能一致,无参数。 +枚举对应到字符串,两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BOX.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BOX.md index 482bdd9e8ac..808f1c2e5b1 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BOX.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.BOX.md @@ -12,4 +12,4 @@ torchvision.transforms.InterpolationMode.BOX 'box' ``` -两者功能一致,无参数。 +枚举对应到字符串,两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.HAMMING.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.HAMMING.md index 0b324d7c316..c29b69cf3bf 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.HAMMING.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.HAMMING.md @@ -12,4 +12,4 @@ torchvision.transforms.InterpolationMode.HAMMING 'hamming' ``` -两者功能一致,无参数。 +枚举对应到字符串,两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.LANCZOS.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.LANCZOS.md index 63bc3717beb..4551de8acd5 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.LANCZOS.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.LANCZOS.md @@ -12,4 +12,4 @@ torchvision.transforms.InterpolationMode.LANCZOS 'lanczos' ``` -两者功能一致,无参数。 +枚举对应到字符串,两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST.md index a871a439851..437300f96f8 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST.md @@ -12,4 +12,4 @@ torchvision.transforms.InterpolationMode.NEAREST 'nearest' ``` -两者功能一致,无参数。 +枚举对应到字符串,两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST_EXACT.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST_EXACT.md index 595c041b388..f9525451642 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST_EXACT.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.InterpolationMode.NEAREST_EXACT.md @@ -12,4 +12,4 @@ torchvision.transforms.InterpolationMode.NEAREST_EXACT 'nearest_exact' ``` -两者功能一致,无参数。 +枚举对应到字符串,两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py b/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py index e8f67254ea7..1b98c5c7357 100644 --- a/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py +++ b/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py @@ -13,6 +13,10 @@ PADDLE_DOCS_BASE_URL = "https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/" +validate_whitelist = [ + r"torch.pi.md", +] + mapping_type_levels = [ # type 0 ["UNDEFINED_MAPPING_TYPE_0"], @@ -300,8 +304,6 @@ def get_meta_from_diff_file( if title_match: mapping_type = title_match["type"].strip() src_api = unescape_api(title_match["src_api"].strip()) - if src_api == "torch.pi": - dst_prefix = "numpy." meta_data["src_api"] = unescape_api(src_api) meta_data["mapping_type"] = mapping_type @@ -740,6 +742,8 @@ def discover_all_metas(cfp_basedir): s, d = prefixs sh = get_table_header_by_prefix(s) for f in files: + if(os.path.basename(f) in validate_whitelist): + continue metas.append(get_meta_from_diff_file(f, s, d, src_argmap_title=sh)) metas.sort(key=lambda x: x["src_api"]) From 02e9bd41a1a7bc6b9605e351f228c01d261ee44c Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Sun, 17 Nov 2024 23:58:15 +0800 Subject: [PATCH 08/18] fix docs --- .../api_difference/others/os.environ.get.md | 2 +- .../api_difference/others/setuptools.setup.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md index 7d042a5a506..f23d34725f2 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/os.environ.get.md @@ -6,7 +6,7 @@ os.environ.get(key, value) ``` -Paddle 无此 API,需要组合实现。该API一般情况下与Paddle无关,仅在torch分布式相关的深度学习用法里才需转写。可以用来获取参与分布式训练的进程总数,以及获取当前进程的rank。 +Paddle 无此 API,需要组合实现。该 API 一般情况下与 Paddle 无关,仅在 torch 分布式相关的深度学习用法里才需转写。可以用来获取参与分布式训练的进程总数,以及获取当前进程的 rank。 ### 转写示例 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md index 4b9d8e437c4..171b4483db0 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md @@ -6,7 +6,7 @@ setuptools.setup(*args, **attrs) ``` -Paddle 无此 API,需要组合实现。该API一般情况下与Paddle无关,仅在torch分布式相关的深度学习用法里才需转写,用来构建一个包含自定义扩展(如 C++ )的 PyTorch 包。 +Paddle 无此 API,需要组合实现。该 API 一般情况下与 Paddle 无关,仅在 torch 分布式相关的深度学习用法里才需转写,用来构建一个包含自定义扩展(如 C++ )的 PyTorch 包。 ### 转写示例 From b0bb3a8a82c15380c2585f0a248336d627fbedef Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Mon, 18 Nov 2024 00:26:08 +0800 Subject: [PATCH 09/18] fix docs --- .../convert_from_pytorch/tools/validate_mapping_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py b/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py index 1b98c5c7357..b955d2d8076 100644 --- a/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py +++ b/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py @@ -742,7 +742,7 @@ def discover_all_metas(cfp_basedir): s, d = prefixs sh = get_table_header_by_prefix(s) for f in files: - if(os.path.basename(f) in validate_whitelist): + if os.path.basename(f) in validate_whitelist: continue metas.append(get_meta_from_diff_file(f, s, d, src_argmap_title=sh)) From 07408df3cbb6661cd4bd792a1bc3b7ec979640e0 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Mon, 18 Nov 2024 16:24:38 +0800 Subject: [PATCH 10/18] fix docs --- .../api_difference/others/setuptools.setup.md | 2 +- .../api_difference/utils/torch.utils.checkpoint.checkpoint.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md index 171b4483db0..37e6cd97198 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md @@ -6,7 +6,7 @@ setuptools.setup(*args, **attrs) ``` -Paddle 无此 API,需要组合实现。该 API 一般情况下与 Paddle 无关,仅在 torch 分布式相关的深度学习用法里才需转写,用来构建一个包含自定义扩展(如 C++ )的 PyTorch 包。 +Paddle 无此 API,需要组合实现。该 API 一般情况下与 Paddle 无关,用来构建一个包含自定义扩展(如 C++ )的 PyTorch 包。 ### 转写示例 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md index 0e46326efea..851999cbc26 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md @@ -19,6 +19,6 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | function | function | 模型前向传播的部分连续的层函数组成的序列。 | | preserve_rng_state | preserve_rng_state | 是否保存前向的 rng。 | | use_reentrant | use_reentrant | recompute 的实现方式。 | -| determinism_check | - | 控制是否在反向传播时检查操作的确定性, Paddle 无此参数,暂无转写方式。 | +| determinism_check | - | 控制是否在反向传播时检查操作的确定性, 一般对训练结果影响不大,可直接删除。 | |*args | *args | function 的输入。 | | **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | From 800ee3fb1aea3b86cf76313a34af73f392d138e5 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Mon, 18 Nov 2024 20:24:35 +0800 Subject: [PATCH 11/18] fix-docs --- .../api_difference/others/setuptools.setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md index 37e6cd97198..3e459df8b06 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/setuptools.setup.md @@ -6,7 +6,7 @@ setuptools.setup(*args, **attrs) ``` -Paddle 无此 API,需要组合实现。该 API 一般情况下与 Paddle 无关,用来构建一个包含自定义扩展(如 C++ )的 PyTorch 包。 +Paddle 无此 API,需要组合实现。该 API 一般情况下与 Paddle 无关,仅在与 torch 相关的深度学习用法里才需要转写,用来构建一个包含自定义扩展(如 C++ )的 PyTorch 包。 ### 转写示例 From 0b21fbff112f124a408e8b8f010be960fb2eba44 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Mon, 25 Nov 2024 22:46:38 +0800 Subject: [PATCH 12/18] fix docs --- .../api_difference/Tensor/torch.Tensor.ormqr.md | 4 ++-- .../torch.distributed.all_gather_object.md | 5 ++--- .../api_difference/nn/torch.nn.GRUCell.md | 12 +++++++++++- .../api_difference/nn/torch.nn.LSTMCell.md | 12 +++++++++++- .../api_difference/nn/torch.nn.RNNCell.md | 13 ++++++++++++- .../api_difference/torch/torch.ormqr.md | 8 +++++--- .../utils/torch.utils.checkpoint.checkpoint.md | 6 +++--- ... torchvision.transforms.functional.normalize.md} | 0 8 files changed, 46 insertions(+), 14 deletions(-) rename docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/{torchvision.transform.functional.normalize.md => torchvision.transforms.functional.normalize.md} (100%) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ormqr.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ormqr.md index ce84ef5a8ef..eb273b50223 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ormqr.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ormqr.md @@ -9,7 +9,7 @@ torch.Tensor.ormqr(input2, input3, left=True, transpose=False) ### [paddle.linalg.ormqr](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/ormqr_cn.html#ormqr) ```python -paddle.linalg.ormqr(x, tau, other, left=True, transpose=False) +paddle.linalg.ormqr(x, tau, y, left=True, transpose=False) ``` 两者功能一致且参数用法一致,仅参数名不一致,具体如下: @@ -19,6 +19,6 @@ paddle.linalg.ormqr(x, tau, other, left=True, transpose=False) | PyTorch | PaddlePaddle | 备注 | | --------- | ------------ | ---------------------------------- | | input2 | tau | Householder 反射系数,仅参数名不同 | -| input3 | other | 用于矩阵乘积,仅参数名不同 | +| input3 | y | 用于矩阵乘积,仅参数名不同 | | left | left | 决定了矩阵乘积运算的顺序,一致 | | transpose | transpose | 决定矩阵 Q 是否共轭转置变换,一致 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md index f4cc179f813..e9e4dae8b8a 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md @@ -1,4 +1,4 @@ -## [参数完全一致]torch.distributed.all_gather_object +## [ 输入参数用法不一致 ]torch.distributed.all_gather_object ### [torch.distributed.all_gather_object](https://pytorch.org/docs/stable/distributed.html?highlight=all_gather_object#torch.distributed.all_gather_object) @@ -18,8 +18,7 @@ paddle.distributed.all_gather_object(object_list, obj, group=None) | PyTorch | PaddlePaddle | 备注 | | -------- | ------------ | --------------------------------------------- | -| object_list | | 表示用于保存聚合结果的列表。需初始化成与 `group` 等长的列表 | -| | object_list | 表示用于保存聚合结果的列表。需初始化成空列表 | +| object_list | object_list | 表示用于保存聚合结果的列表。PyTorch 需初始化成与 `group` 等长的列表, Paddle 需初始化为空列表,需要转写。 | | obj | obj | 表示待聚合的对象。 | | group | group | 表示执行该操作的进程组实例。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md index d056c6a2d66..fcb9522e129 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md @@ -10,7 +10,7 @@ torch.nn.GRUCell(input_size, hidden_size, bias=True, device=None, dtype=None) paddle.nn.GRUCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, name=None) ``` -两者功能一致但参数不一,具体如下: +两者功能一致但参数不一,且二者的 forward 函数返回值格式不一致,具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | @@ -40,3 +40,13 @@ torch.nn.GRU(16, 32, bias=False) # Paddle 写法 paddle.nn.GRU(16, 32, bias_ih_attr=False, bias_hh_attr=False) ``` +#### forward:前向传播 +```python +# PyTorch 写法 +rnn = torch.nn.GRUCell(2, 2) +result = rnn(inp, h0) + +# Paddle 写法 +rnn = paddle.nn.GRUCell(2, 2) +result = rnn(inp, h0)[0] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md index c1a675c98a4..f3698d4ccb3 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md @@ -9,7 +9,7 @@ torch.nn.LSTMCell(input_size, hidden_size, bias=True, device=None, dtype=None) paddle.nn.LSTMCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, proj_size=0, name=None) ``` -两者功能一致但参数不一,具体如下: +两者功能一致但参数不一,且二者的 forward 函数返回值格式不一致, 具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | @@ -40,3 +40,13 @@ torch.nn.LSTMCell(16, 32, bias=False) # Paddle 写法 paddle.nn.LSTMCell(16, 32, bias_ih_attr=False, bias_hh_attr=False) ``` + +#### forward:前向传播 +```python +# PyTorch 写法 +rnn = torch.nn.LSTMCell(2, 2) +result = rnn(inp, h0) + +# Paddle 写法 +rnn = paddle.nn.LSTMCell(2, 2) +result = rnn(inp, h0)[1] diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md index 981a0f765fc..90a887676b1 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md @@ -9,7 +9,7 @@ torch.nn.RNNCell(input_size, hidden_size, bias=True, nonlinearity='tanh', device paddle.nn.SimpleRNNCell(input_size, hidden_size, activation='tanh', weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, name=None) ``` -两者功能一致但参数不一致,部分参数名不同,具体如下: +两者功能一致但参数不一致,部分参数名不同,且二者的 forward 函数返回值格式不一致, 具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | @@ -37,3 +37,14 @@ torch.nn.RNNCell(16, 32, bias=False) # Paddle 写法 paddle.nn.SimpleRNNCell(16, 32, bias_ih_attr=False, bias_hh_attr=False) ``` + +#### forward:前向传播 +```python +# PyTorch 写法 +rnn = torch.nn.RNNCell(2, 2) +result = rnn(inp, h0) + +# Paddle 写法 +rnn = paddle.nn.SimpleRNNCell(2, 2) +result = rnn(inp, h0)[0] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.ormqr.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.ormqr.md index 3e2973a7071..ba4e0fc6219 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.ormqr.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.ormqr.md @@ -1,4 +1,4 @@ -## [ 仅参数名不一致 ]torch.ormqr +## [ torch 参数更多 ]torch.ormqr ### [torch.ormqr](https://pytorch.org/docs/stable/generated/torch.ormqr.html#torch.ormqr) @@ -12,13 +12,15 @@ torch.ormqr(input, tau, other, left=True, transpose=False, *, out=None) paddle.linalg.ormqr(x, tau, other, left=True, transpose=False) ``` +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + ### 参数映射 | PyTorch | PaddlePaddle | 备注 | | --------- | ------------ | ---------------------------------------------- | | input | x | 输入的参数,用于表示矩阵 Q ,仅参数名字不一致 | -| tau | tau | Householder 反射系数,一致 | -| other | other | 用于矩阵乘积,一致 | +| input2 | tau | Householder 反射系数,一致 | +| input3 | other | 用于矩阵乘积,一致 | | left | left | 决定了矩阵乘积运算的顺序,一致 | | transpose | transpose | 决定矩阵 Q 是否共轭转置变换,一致 | | out | - | paddle 无此参数,需转写 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md index 851999cbc26..951f565a88e 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md @@ -2,13 +2,13 @@ ### [torch.utils.checkpoint.checkpoint](https://pytorch.org/docs/stable/checkpoint.html#torch.utils.checkpoint.checkpoint) ```python -torch.utils.checkpoint.checkpoint(function, preserve_rng_state=True, use_reentrant=True, determinism_check="default", *args, **kwargs) +torch.utils.checkpoint.checkpoint(function, *args, preserve_rng_state=True, use_reentrant=True, determinism_check="default", **kwargs) ``` ### [paddle.distributed.fleet.utils.recompute](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/cpp_extension/CppExtension_cn.html) ```python -paddle.distributed.fleet.utils.recompute(function, preserve_rng_state=True, use_reentrant=True, *args, **kwargs) +paddle.distributed.fleet.utils.recompute(function, *args, preserve_rng_state=True, use_reentrant=True, **kwargs) ``` PyTorch 相比 Paddle 支持更多其他参数,具体如下: @@ -17,8 +17,8 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | | function | function | 模型前向传播的部分连续的层函数组成的序列。 | +|*args | *args | function 的输入。 | | preserve_rng_state | preserve_rng_state | 是否保存前向的 rng。 | | use_reentrant | use_reentrant | recompute 的实现方式。 | | determinism_check | - | 控制是否在反向传播时检查操作的确定性, 一般对训练结果影响不大,可直接删除。 | -|*args | *args | function 的输入。 | | **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transform.functional.normalize.md b/docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.functional.normalize.md similarity index 100% rename from docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transform.functional.normalize.md rename to docs/guides/model_convert/convert_from_pytorch/api_difference_third_party/torchvision/torchvision.transforms.functional.normalize.md From 0d23f180b5298beea5a45ceccb2ce271eeaa350d Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Mon, 25 Nov 2024 23:01:02 +0800 Subject: [PATCH 13/18] fix tools --- .../convert_from_pytorch/tools/validate_mapping_files.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py b/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py index b955d2d8076..f6b0f92d4e5 100644 --- a/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py +++ b/docs/guides/model_convert/convert_from_pytorch/tools/validate_mapping_files.py @@ -496,7 +496,6 @@ def get_meta_from_diff_file( # 映射类型前三个级别必须要有对应的 dst_api if mapping_type_to_level[mapping_type] <= 3: if state != ParserState.end: - print(state) raise Exception( f"Unexpected End State at {state} in parsing file: {filepath}, current meta: {meta_data}" ) From 89129501ca4cda11bcdf8fbcea04efa01d271f22 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Mon, 25 Nov 2024 23:06:39 +0800 Subject: [PATCH 14/18] resolve conflict --- .../utils/torch.utils.checkpoint.checkpoint.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md index 951f565a88e..0aaf6205931 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md @@ -2,13 +2,13 @@ ### [torch.utils.checkpoint.checkpoint](https://pytorch.org/docs/stable/checkpoint.html#torch.utils.checkpoint.checkpoint) ```python -torch.utils.checkpoint.checkpoint(function, *args, preserve_rng_state=True, use_reentrant=True, determinism_check="default", **kwargs) +torch.utils.checkpoint.checkpoint(function, preserve_rng_state=True, use_reentrant=True, determinism_check="default", *args, **kwargs) ``` ### [paddle.distributed.fleet.utils.recompute](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/cpp_extension/CppExtension_cn.html) ```python -paddle.distributed.fleet.utils.recompute(function, *args, preserve_rng_state=True, use_reentrant=True, **kwargs) +paddle.distributed.fleet.utils.recompute(function, preserve_rng_state=True, use_reentrant=True, *args, **kwargs) ``` PyTorch 相比 Paddle 支持更多其他参数,具体如下: @@ -17,8 +17,8 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | | function | function | 模型前向传播的部分连续的层函数组成的序列。 | -|*args | *args | function 的输入。 | | preserve_rng_state | preserve_rng_state | 是否保存前向的 rng。 | | use_reentrant | use_reentrant | recompute 的实现方式。 | | determinism_check | - | 控制是否在反向传播时检查操作的确定性, 一般对训练结果影响不大,可直接删除。 | -| **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | +|*args | *args | function 的输入。 | +| **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | \ No newline at end of file From 44624c4a3759b8ebf12933ca1fe9737e708f8f0f Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Mon, 25 Nov 2024 23:11:44 +0800 Subject: [PATCH 15/18] resolve conflict --- .../api_difference/utils/torch.utils.checkpoint.checkpoint.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md index 0aaf6205931..851999cbc26 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md @@ -21,4 +21,4 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | use_reentrant | use_reentrant | recompute 的实现方式。 | | determinism_check | - | 控制是否在反向传播时检查操作的确定性, 一般对训练结果影响不大,可直接删除。 | |*args | *args | function 的输入。 | -| **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | \ No newline at end of file +| **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | From 6c549e23762cac2e576909e2ea1e534ca3df0132 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Tue, 26 Nov 2024 00:29:41 +0800 Subject: [PATCH 16/18] resubmit --- .../api_difference/utils/torch.utils.checkpoint.checkpoint.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md index 851999cbc26..c4ac4737174 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md @@ -22,3 +22,4 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | determinism_check | - | 控制是否在反向传播时检查操作的确定性, 一般对训练结果影响不大,可直接删除。 | |*args | *args | function 的输入。 | | **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | + From 097a752c33545a56eb9e13cf4f66bfae95e0a6af Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Tue, 26 Nov 2024 00:30:04 +0800 Subject: [PATCH 17/18] resubmit --- .../api_difference/utils/torch.utils.checkpoint.checkpoint.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md index c4ac4737174..851999cbc26 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.checkpoint.checkpoint.md @@ -22,4 +22,3 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | determinism_check | - | 控制是否在反向传播时检查操作的确定性, 一般对训练结果影响不大,可直接删除。 | |*args | *args | function 的输入。 | | **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | - From ba90b4a150fdc2cc7e88849226a922426fee4178 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Tue, 26 Nov 2024 21:19:15 +0800 Subject: [PATCH 18/18] fix docs --- .../torch.distributed.all_gather_object.md | 2 +- .../api_difference/nn/torch.nn.GRU.md | 2 +- .../api_difference/nn/torch.nn.GRUCell.md | 18 ++++++++---------- .../api_difference/nn/torch.nn.LSTM.md | 2 +- .../api_difference/nn/torch.nn.LSTMCell.md | 11 ++++------- .../api_difference/nn/torch.nn.RNN.md | 2 +- .../api_difference/nn/torch.nn.RNNBase.md | 2 +- .../api_difference/nn/torch.nn.RNNCell.md | 11 ++++------- 8 files changed, 21 insertions(+), 29 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md index e9e4dae8b8a..a9d010e3772 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md @@ -23,7 +23,7 @@ paddle.distributed.all_gather_object(object_list, obj, group=None) | group | group | 表示执行该操作的进程组实例。 | ### 转写示例 - +#### object_list:保存聚合结果列表 ```python # PyTorch 写法 import torch.distributed as dist diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRU.md index 69cc517c03a..0f80f94aab6 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRU.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRU.md @@ -34,7 +34,7 @@ paddle.nn.GRU(input_size, | input_size | input_size | 表示输入 x 的大小。 | | hidden_size | hidden_size | 表示隐藏状态 h 大小。 | | num_layers | num_layers | 表示循环网络的层数。 | -| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 | | batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 | | dropout | dropout | 表示 dropout 概率。 | | bidirectional | direction | PyTorch 表示是否进行双向 GRU,Paddle 使用字符串表示是双向 GRU(`bidirectional`)还是单向 GRU(`forward`)。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md index fcb9522e129..2101ebf83d1 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md @@ -1,4 +1,4 @@ -## [ 输入参数用法不一致 ]torch.nn.GRUCell +## [ 返回参数类型不一致 ]torch.nn.GRUCell ### [torch.nn.GRUCell](https://pytorch.org/docs/stable/generated/torch.nn.GRUCell.html#torch.nn.GRUCell) ```python @@ -10,14 +10,14 @@ torch.nn.GRUCell(input_size, hidden_size, bias=True, device=None, dtype=None) paddle.nn.GRUCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, name=None) ``` -两者功能一致但参数不一,且二者的 forward 函数返回值格式不一致,具体如下: +两者功能一致但输入参数用法不一致,且返回参数类型不同,具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | | input_size | input_size | 表示输入 x 的大小。 | | hidden_size | hidden_size | 表示隐藏状态 h 大小。 | -| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置,Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 | | device | - | 指定 Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | dtype | - | Tensor 的所需数据类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | @@ -28,19 +28,17 @@ paddle.nn.GRUCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=N #### bias:是否使用偏置 ```python # PyTorch 写法 -torch.nn.GRU(16, 32, bias=True) - +torch.nn.GRUCell(16, 32, bias=True) # Paddle 写法 -paddle.nn.GRU(16, 32) +paddle.nn.GRUCell(16, 32) ``` ```python # PyTorch 写法 -torch.nn.GRU(16, 32, bias=False) - +torch.nn.GRUCell(16, 32, bias=False) # Paddle 写法 -paddle.nn.GRU(16, 32, bias_ih_attr=False, bias_hh_attr=False) +paddle.nn.GRUCell(16, 32, bias_ih_attr=False, bias_hh_attr=False) ``` -#### forward:前向传播 +#### forward 类方法:前向传播 ```python # PyTorch 写法 rnn = torch.nn.GRUCell(2, 2) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTM.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTM.md index 014f18a2d19..4584fdf6908 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTM.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTM.md @@ -39,7 +39,7 @@ paddle.nn.LSTM(input_size, | input_size | input_size | 表示输入 x 的大小。 | | hidden_size | hidden_size | 表示隐藏状态 h 大小。 | | num_layers | num_layers | 表示循环网络的层数。 | -| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 | | batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 | | dropout | dropout | 表示 dropout 概率。 | | bidirectional | direction | PyTorch 表示是否进行双向,Paddle 使用字符串表示是双向 LSTM(`bidirectional`)还是单向 LSTM(`forward`)| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md index f3698d4ccb3..54adb123931 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md @@ -1,4 +1,4 @@ -## [ 输入参数用法不一致 ]torch.nn.LSTMCell +## [ 返回参数类型不一致 ]torch.nn.LSTMCell ### [torch.nn.LSTMCell](https://pytorch.org/docs/stable/generated/torch.nn.LSTMCell.html#torch.nn.LSTMCell) ```python torch.nn.LSTMCell(input_size, hidden_size, bias=True, device=None, dtype=None) @@ -9,14 +9,14 @@ torch.nn.LSTMCell(input_size, hidden_size, bias=True, device=None, dtype=None) paddle.nn.LSTMCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, proj_size=0, name=None) ``` -两者功能一致但参数不一,且二者的 forward 函数返回值格式不一致, 具体如下: +两者功能一致但输入参数用法不一致,且返回参数类型不同,具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | | input_size | input_size | 表示输入 x 的大小。 | | hidden_size | hidden_size | 表示隐藏状态 h 大小。 | -| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 | | device | - | 指定 Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | dtype | - | Tensor 的所需数据类型,一般对网络训练结果影响不大,可直接删除。 | | - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | @@ -29,19 +29,16 @@ paddle.nn.LSTMCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr= ```python # PyTorch 写法 torch.nn.LSTMCell(16, 32, bias=True) - # Paddle 写法 paddle.nn.LSTMCell(16, 32) ``` ```python # PyTorch 写法 torch.nn.LSTMCell(16, 32, bias=False) - # Paddle 写法 paddle.nn.LSTMCell(16, 32, bias_ih_attr=False, bias_hh_attr=False) ``` - -#### forward:前向传播 +#### forward 类方法:前向传播 ```python # PyTorch 写法 rnn = torch.nn.LSTMCell(2, 2) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNN.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNN.md index aab6b8ea854..54095b40d53 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNN.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNN.md @@ -27,7 +27,7 @@ paddle.nn.SimpleRNN(input_size, hidden_size, num_layers=1, activation='tanh', di | hidden_size | hidden_size | 表示隐藏状态 h 大小。 | | num_layers | num_layers | 表示循环网络的层数。 | | nonlinearity | activation | 表示激活函数类型,仅参数名不一致。 | -| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 | | batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 | | dropout | dropout | 表示 dropout 概率。 | | bidirectional | direction | PyTorch 表示是否进行双向 RNN,Paddle 使用字符串表示是双向 RNN(`bidirectional`)还是单向 RNN(`forward`)。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNBase.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNBase.md index 7b59964bec0..d4e45375bdf 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNBase.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNBase.md @@ -24,7 +24,7 @@ paddle.nn.layer.rnn.RNNBase(mode, input_size, hidden_size, | input_size | input_size | 表示输入 x 的大小。 | | hidden_size | hidden_size | 表示隐藏状态 h 大小。 | | num_layers | num_layers | 表示循环网络的层数。 | -| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 | | batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 | | dropout | dropout | 表示 dropout 概率。 | | bidirectional | direction | PyTorch 表示是否进行双向 RNN,Paddle 使用字符串表示是双向 RNN(`bidirectional`)还是单向 RNN(`forward`)。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md index 90a887676b1..7aa872d7ff6 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md @@ -1,4 +1,4 @@ -## [ 输入参数用法不一致 ]torch.nn.RNNCell +## [ 返回参数类型不一致 ]torch.nn.RNNCell ### [torch.nn.RNNCell](https://pytorch.org/docs/stable/generated/torch.nn.RNNCell.html#torch.nn.RNNCell) ```python torch.nn.RNNCell(input_size, hidden_size, bias=True, nonlinearity='tanh', device=None, dtype=None) @@ -9,14 +9,14 @@ torch.nn.RNNCell(input_size, hidden_size, bias=True, nonlinearity='tanh', device paddle.nn.SimpleRNNCell(input_size, hidden_size, activation='tanh', weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, name=None) ``` -两者功能一致但参数不一致,部分参数名不同,且二者的 forward 函数返回值格式不一致, 具体如下: +两者功能一致但输入参数用法不一致,且返回参数类型不同,具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | | input_size | input_size | 表示输入 x 的大小。 | | hidden_size | hidden_size | 表示隐藏状态 h 大小。 | -| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 | | nonlinearity | activation | 表示激活函数类型,仅参数名不一致。 | | - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | | - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | @@ -26,19 +26,16 @@ paddle.nn.SimpleRNNCell(input_size, hidden_size, activation='tanh', weight_ih_at ```python # PyTorch 写法 torch.nn.RNNCell(16, 32, bias=True) - # Paddle 写法 paddle.nn.SimpleRNNCell(16, 32) ``` ```python # PyTorch 写法 torch.nn.RNNCell(16, 32, bias=False) - # Paddle 写法 paddle.nn.SimpleRNNCell(16, 32, bias_ih_attr=False, bias_hh_attr=False) ``` - -#### forward:前向传播 +#### forward 类方法:前向传播 ```python # PyTorch 写法 rnn = torch.nn.RNNCell(2, 2)