From ed34bc295fd52b617247b4abeee1eea72757c766 Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Fri, 27 Dec 2024 22:45:30 +0800
Subject: [PATCH 01/13] fix mapping
---
.../api_difference/Tensor/torch.Tensor.itemsize.md | 6 +++---
.../distributed/torch.distributed.rpc.rpc_async.md | 4 ++--
.../distributed/torch.distributed.rpc.rpc_sync.md | 4 ++--
.../functional/torch.nn.functional.ctc_loss.md | 2 +-
.../api_difference/nn/torch.nn.CTCLoss.md | 2 +-
.../convert_from_pytorch/pytorch_api_mapping_cn.md | 11 ++++++-----
6 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.itemsize.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.itemsize.md
index 8e56dd2dea0..933f6c6ff9f 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.itemsize.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.itemsize.md
@@ -1,9 +1,9 @@
-## [ 无参数 ]torch.Tensor.item_size
+## [ 无参数 ]torch.Tensor.itemsize
-### [torch.Tensor.item_size](https://pytorch.org/docs/stable/generated/torch.Tensor.itemsize.html)
+### [torch.Tensor.itemsize](https://pytorch.org/docs/stable/generated/torch.Tensor.itemsize.html)
```python
-torch.Tensor.item_size()
+torch.Tensor.itemsize
```
### [paddle.Tensor.element_size](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#element-size)
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_async.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_async.md
index 87e18d68144..0da6723ef57 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_async.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_async.md
@@ -1,4 +1,4 @@
-## [仅参数名不一致]torch.distributed.rpc.rpc_async
+## [输入参数用法不一致]torch.distributed.rpc.rpc_async
### [torch.distributed.rpc.rpc_async](https://pytorch.org/docs/stable/rpc.html#torch.distributed.rpc.rpc_async)
@@ -20,6 +20,6 @@ paddle.distributed.rpc.rpc_async(to, fn, args=None, kwargs=None, timeout=- 1)
| ------- | ------------ | ---------------------------------- |
| to | to | 目标 worker 的名字。 |
| func | fn | 一个可调用的函数,仅参数名不一致。 |
-| args | args | 函数 fn 的参数。 |
+| args | args | 函数 fn 的参数, paddle 不支持输入类型为张量,暂无转写方式。 |
| kwargs | kwargs | 函数 fn 的字典参数。 |
| timeout | timeout | RPC 调用的超时时间。 |
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_sync.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_sync.md
index ee70c6c2a49..baf36a20b02 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_sync.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_sync.md
@@ -1,4 +1,4 @@
-## [仅参数名不一致]torch.distributed.rpc.rpc_sync
+## [输入参数用法不一致]torch.distributed.rpc.rpc_sync
### [torch.distributed.rpc.rpc_sync](https://pytorch.org/docs/stable/rpc.html#torch.distributed.rpc.rpc_sync)
@@ -20,6 +20,6 @@ paddle.distributed.rpc.rpc_sync(to, fn, args=None, kwargs=None, timeout=- 1)
| ------- | ------------ | ---------------------------------- |
| to | to | 目标 worker 的名字。 |
| func | fn | 一个可调用的函数,仅参数名不一致。 |
-| args | args | 函数 fn 的参数。 |
+| args | args | 函数 fn 的参数, paddle 不支持输入类型为张量,暂无转写方式。 |
| kwargs | kwargs | 函数 fn 的字典参数。 |
| timeout | timeout | RPC 调用的超时时间。 |
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.ctc_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.ctc_loss.md
index ae66326d426..393975a9891 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.ctc_loss.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.ctc_loss.md
@@ -12,7 +12,7 @@ torch.nn.functional.ctc_loss(log_probs, targets, input_lengths, target_lengths,
paddle.nn.functional.ctc_loss(log_probs, labels, input_lengths, label_lengths, blank=0, reduction='mean')
```
-PyTorch 相比 Paddle 支持更多其他参数,具体如下:
+其中 torch 的 log_softmax+ctc_loss 相当于 paddle 的 ctc_loss,是一个二对一的情况,暂时无法转写。PyTorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数映射
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md
index f3722ced51b..69ed1ae3055 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md
@@ -15,7 +15,7 @@ paddle.nn.CTCLoss(blank=0,
reduction='mean')
```
-其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下:
+其中,torch 的 log_softmax+ctc_loss 相当于 paddle 的 ctc_loss,是一个二对一的情况,暂时无法转写,且 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数映射
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 2579069e0de..b830810fdbf 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
@@ -33,6 +33,9 @@
| [transformers.xx](#id21) | 第三方库 transformers API |
| [flash_attn.xx](#id22) | 第三方库 flash_attn API |
| [torchvision.xx](#id23) | 第三方库 torchvision API |
+| [API 别名映射](#id24) | API 别名映射列表 |
+| [功能缺失的 API](#id25) | 功能缺失的 API 列表 |
+| [映射关系开发中的 API](#id26) | 映射关系开发中的 API 列表 |
## torch.XX API 映射列表
@@ -250,7 +253,7 @@
***持续更新...***
-## API 别名映射列表
+## API 别名映射列表
| 序号 | Pytorch 最新 release | Paddle develop | 映射关系分类 | 备注 |
| ---- | -------------------- | -------------- | ----------- | ---- |
@@ -366,7 +369,7 @@
| ALIAS-REFERENCE-ITEM(`torch.utils.data.sampler.SubsetRandomSampler`, `torch.utils.data.SubsetRandomSampler`) |
| ALIAS-REFERENCE-ITEM(`torch.utils.data.sampler.WeightedRandomSampler`, `torch.utils.data.WeightedRandomSampler`) |
- ## 功能缺失的 API 列表
+ ## 功能缺失的 API 列表
| 序号 | Pytorch 最新 release | Paddle develop | 映射关系分类 | 备注 |
| ----- | ----------- | ----------------- | ----------- | ------- |
@@ -378,7 +381,6 @@
| NOT-IMPLEMENTED-ITEM(`torch.Tensor.dequantize`, https://pytorch.org/docs/stable/generated/torch.Tensor.dequantize.html#torch-tensor-dequantize, 有对应相近功能但设计差异大无法映射,一般无需新增) |
| NOT-IMPLEMENTED-ITEM(`torch.xpu.synchronize`, https://pytorch.org/docs/stable/generated/torch.xpu.synchronize.html#torch-xpu-synchronize, 有对应相近功能但设计差异大无法映射,一般无需新增) |
| NOT-IMPLEMENTED-ITEM(`torch.vmap`, https://pytorch.org/docs/stable/generated/torch.vmap.html#torch-vmap, 可新增,且框架底层有相关设计,成本低) |
-| NOT-IMPLEMENTED-ITEM(`torch.Tensor.resize_`, https://pytorch.org/docs/stable/generated/torch.Tensor.resize_.html#torch-tensor-resize, 废弃 API ,无需新增) |
| NOT-IMPLEMENTED-ITEM(`torch.fx.symbolic_trace`, https://pytorch.org/docs/stable/fx.html#torch.fx.symbolic_trace, 有对应相近功能但设计差异大无法映射,一般无需新增) |
| NOT-IMPLEMENTED-ITEM(`torch.jit.annotate`, https://pytorch.org/docs/stable/generated/torch.jit.annotate.html#torch-jit-annotate, 有对应相近功能但设计差异大无法映射,一般无需新增) |
| NOT-IMPLEMENTED-ITEM(`torch.quantize_per_tensor`, https://pytorch.org/docs/stable/generated/torch.quantize_per_tensor.html#torch-quantize-per-tensor, 有对应相近功能但设计差异大无法映射,一般无需新增) |
@@ -1030,7 +1032,7 @@
| 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, 可新增,且框架底层有相关设计,成本低) |
-## 映射关系开发中的 API 列表
+## 映射关系开发中的 API 列表
| 序号 | Pytorch 最新 release | Paddle develop | 映射关系分类 | 备注 |
| ----- | ----------- | ----------------- | ----------- | ------- |
@@ -1117,7 +1119,6 @@
| IN-DEVELOPMENT-PATTERN(`torch._foreach_trunc`, https://pytorch.org/docs/stable/generated/torch._foreach_trunc.html#torch-foreach-trunc) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_trunc_`, https://pytorch.org/docs/stable/generated/torch._foreach_trunc_.html#torch-foreach-trunc) |
| IN-DEVELOPMENT-PATTERN(`torch._foreach_zero_`, https://pytorch.org/docs/stable/generated/torch._foreach_zero_.html#torch-foreach-zero) |
-| IN-DEVELOPMENT-PATTERN(`torch.Tensor.itemsize`, https://pytorch.org/docs/stable/generated/torch.Tensor.itemsize.html#torch-tensor-itemsize) |
| IN-DEVELOPMENT-PATTERN(`torch.Tensor.to_sparse_csr`, https://pytorch.org/docs/stable/generated/torch.Tensor.to_sparse_csr.html#torch-tensor-to-sparse-csr) |
| IN-DEVELOPMENT-PATTERN(`torch.autograd.graph.Node.name`, https://pytorch.org/docs/stable/generated/torch.autograd.graph.Node.name.html#torch-autograd-graph-node-name) |
| IN-DEVELOPMENT-PATTERN(`torch.autograd.graph.Node.metadata`, https://pytorch.org/docs/stable/generated/torch.autograd.graph.Node.metadata.html#torch-autograd-graph-node-metadata) |
From a617301641062dd3d39f2874de8787b57c102269 Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Mon, 24 Feb 2025 19:30:02 +0800
Subject: [PATCH 02/13] fix-docs
---
.../Tensor/torch.Tensor.requires_grad.md | 24 ++++++++++++++
....distributed.optim.DistributedOptimizer.md | 2 +-
.../torch.nn.functional.batch_norm.md | 18 +++++------
.../torch.nn.functional.instance_norm.md | 18 +++++------
.../init/torch.nn.init.kaiming_normal_.md | 4 ++-
.../init/torch.nn.init.orthogonal_.md | 4 ++-
.../init/torch.nn.init.trunc_normal_.md | 4 ++-
.../init/torch.nn.init.uniform_.md | 4 ++-
.../init/torch.nn.init.xavier_uniform_.md | 4 ++-
.../nn/torch.nn.InstanceNorm1d.md | 30 +++++++++---------
.../nn/torch.nn.InstanceNorm2d.md | 31 ++++++++++++-------
.../nn/torch.nn.InstanceNorm3d.md | 12 ++++++-
.../torch.nn.modules.batchnorm._BatchNorm.md | 11 ++++++-
.../pytorch_api_mapping_cn.md | 5 ++-
14 files changed, 115 insertions(+), 56 deletions(-)
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad.md
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad.md
new file mode 100644
index 00000000000..6a3bc403e7e
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad.md
@@ -0,0 +1,24 @@
+## [组合替代实现]torch.Tensor.requires_grad_
+
+### [torch.Tensor.requires_grad](https://pytorch.org/docs/stable/generated/torch.Tensor.requires_grad.html)
+
+```python
+torch.Tensor.requires_grad
+```
+
+### [paddle.Tensor.stop_gradient](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#stop-gradient)
+
+```python
+paddle.Tensor.stop_gradient
+```
+
+两者功能一致,且均无参数,Paddle 返回结果与 PyTorch 返回结果相反,具体如下:
+
+
+### 转写示例
+```python
+# torch 写法
+x.requires_grad
+
+# paddle 写法
+not x.stop_gradient
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.optim.DistributedOptimizer.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.optim.DistributedOptimizer.md
index 7a9672074f6..4883f722167 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.optim.DistributedOptimizer.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.optim.DistributedOptimizer.md
@@ -19,7 +19,7 @@ paddle.distributed.fleet.distributed_optimizer(optimizer, strategy=None)
| PyTorch | PaddlePaddle | 备注 |
| --------------- | ------------ | --------------------------------------------------------------------- |
-| optimizer_class | optimizer | 优化器。 |
+| optimizer_class | optimizer | 优化器,仅参数名不一致。 |
| params_rref | - | 远程引用( RRef )列表,为 RRef 类型,代表要优化的参数。而 Paddle 在实例化 optimizer 时传入,为 Tensor 类型 |
| args | - | 优化器实例化参数, Paddle 在实例化 optimizer 时传入。 |
| kwargs | - | 优化器实例化字典参数, Paddle 在实例化 optimizer 时传入。 |
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.batch_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.batch_norm.md
index 29686476e8f..762289c914a 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.batch_norm.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.batch_norm.md
@@ -16,15 +16,15 @@ paddle.nn.functional.batch_norm(x, running_mean, running_var, weight, bias, trai
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
-| input | x | 表示输入的 Tensor ,仅参数名不一致。 |
-| running_mean | running_mean | 均值的 Tensor。 |
-| running_var | running_var | 方差的 Tensor。 |
-| weight | weight | 权重的 Tensor。 |
-| bias | bias | 偏置的 Tensor。 |
-| eps | epsilon | 为了数值稳定加在分母上的值。 |
-| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写。 |
-| training | training | 是否可训练。 |
-| - | data_format | 指定输入数据格式,PyTorch 无此参数,Paddle 保持默认即可。 |
+| input | x | 表示输入的 Tensor ,仅参数名不一致。 |
+| running_mean | running_mean | 均值的 Tensor。 |
+| running_var | running_var | 方差的 Tensor。 |
+| weight | weight | 权重的 Tensor。 |
+| bias | bias | 偏置的 Tensor。 |
+| eps | epsilon | 为了数值稳定加在分母上的值。 |
+| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写。 |
+| training | training | 是否可训练。 |
+| - | data_format | 指定输入数据格式,PyTorch 无此参数,Paddle 保持默认即可。 |
### 转写示例
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.instance_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.instance_norm.md
index d999ab26e43..9300661736c 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.instance_norm.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.instance_norm.md
@@ -16,15 +16,15 @@ paddle.nn.functional.instance_norm(x, running_mean=None, running_var=None, weigh
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
-| input | x | 表示输入的 Tensor ,仅参数名不一致。 |
-| running_mean | running_mean | 均值的 Tensor |
-| running_var | running_var | 方差的 Tensor |
-| weight | weight | 权重的 Tensor |
-| bias | bias | 偏置的 Tensor |
-| eps | eps | 为了数值稳定加在分母上的值 |
-| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写 |
-| - | training | 是否可训练。 PyTorch 无此参数。保持默认即可。 |
-| - | data_format | 指定输入数据格式。 PyTorch 无此参数。保持默认即可。 |
+| input | x | 表示输入的 Tensor ,仅参数名不一致。 |
+| running_mean | running_mean | 均值的 Tensor |
+| running_var | running_var | 方差的 Tensor |
+| weight | weight | 权重的 Tensor |
+| bias | bias | 偏置的 Tensor |
+| eps | eps | 为了数值稳定加在分母上的值 |
+| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写 |
+| - | training | 是否可训练。 PyTorch 无此参数。保持默认即可。 |
+| - | data_format | 指定输入数据格式。 PyTorch 无此参数。保持默认即可。 |
### 转写示例
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.kaiming_normal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.kaiming_normal_.md
index 4b7784effb8..869505fc2ad 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.kaiming_normal_.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.kaiming_normal_.md
@@ -6,7 +6,8 @@
torch.nn.init.kaiming_normal_(tensor,
a=0,
mode='fan_in',
- nonlinearity='leaky_relu')
+ nonlinearity='leaky_relu',
+ generator=None)
```
### [paddle.nn.initializer.KaimingNormal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/KaimingNormal_cn.html)
@@ -27,6 +28,7 @@ paddle.nn.initializer.KaimingNormal(fan_in=None,
| a | negative_slope | 只适用于使用 leaky_relu 作为激活函数时的 negative_slope 参数。仅参数名不一致。 |
| nonlinearity | nonlinearity | 非线性激活函数。参数默认值不一样,PyTorch 默认值为`leaky_relu`,Paddle 默认值为`relu`,Paddle 需保持与 PyTorch 一致。 |
| mode | - | "fan_in"(默认)或 "fan_out"。Paddle 无此参数,mode="fan_out"时,Paddle 无此参数,暂无转写方式。 |
+| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| - | fan_in | 可训练的 Tensor 的 in_features 值。PyTorch 无此参数,Paddle 保持默认即可。 |
### 转写示例
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.orthogonal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.orthogonal_.md
index becbfd8c431..4b1f427747c 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.orthogonal_.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.orthogonal_.md
@@ -4,7 +4,8 @@
```python
torch.nn.init.orthogonal_(tensor,
- gain=1)
+ gain=1,
+ generator=None)
```
### [paddle.nn.initializer.Orthogonal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/Orthogonal_cn.html)
@@ -22,6 +23,7 @@ paddle.nn.initializer.Orthogonal(gain=1.0,
| ------------- | ------------ | ------------------------------------------------------ |
| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 |
| gain | gain | 参数初始化的增益系数。参数名和参数默认值均一致。 |
+| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
### 转写示例
```python
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.trunc_normal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.trunc_normal_.md
index 89bf02c2f4b..1093156f4c5 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.trunc_normal_.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.trunc_normal_.md
@@ -7,7 +7,8 @@ torch.nn.init.trunc_normal_(tensor,
mean=0.0,
std=1.0,
a=-2.0,
- b=2.0)
+ b=2.0,
+ generator=None)
```
### [paddle.nn.initializer.TruncatedNormal](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/initializer/TruncatedNormal_cn.html)
@@ -31,6 +32,7 @@ paddle.nn.initializer.TruncatedNormal(mean=0.0,
| std | std | 正态分布的标准差。参数名和默认值一致。 |
| a | a | 截断正态分布的下界。参数名和默认值一致。 |
| b | b | 截断正态分布的上界。参数名和默认值一致。 |
+| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
### 转写示例
```python
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.uniform_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.uniform_.md
index b86874f2f3e..f3b15ad1175 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.uniform_.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.uniform_.md
@@ -5,7 +5,8 @@
```python
torch.nn.init.uniform_(tensor,
a=0.0,
- b=1.0)
+ b=1.0,
+ generator=None)
```
### [paddle.nn.initializer.Uniform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/Uniform_cn.html)
@@ -25,6 +26,7 @@ paddle.nn.initializer.Uniform(low=-1.0,
| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 |
| a | low | 均匀分布的下界,参数默认值不一致, PyTorch 默认为`0.0`,Paddle 为`-1.0`,Paddle 需保持与 PyTorch 一致。 |
| b | high | 均匀分布的上界,仅参数名不一致。 |
+| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
### 转写示例
```python
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.xavier_uniform_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.xavier_uniform_.md
index 809c56a90ea..a6f97798e46 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.xavier_uniform_.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.xavier_uniform_.md
@@ -4,7 +4,8 @@
```python
torch.nn.init.xavier_uniform_(tensor,
- gain=1.0)
+ gain=1.0,
+ generator=None)
```
### [paddle.nn.initializer.XavierUniform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/XavierUniform_cn.html)
@@ -24,6 +25,7 @@ paddle.nn.initializer.XavierUniform(fan_in=None,
| ------------- | ------------ | ------------------------------------------------------ |
| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 |
| gain | gain | 缩放因子。 |
+| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| - | fan_in | 用于泽维尔初始化的 fan_in。PyTorch 无此参数,Paddle 保持默认即可。 |
| - | fan_out | 用于泽维尔初始化的 fan_out。PyTorch 无此参数,Paddle 保持默认即可。 |
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm1d.md
index 560df50438b..f71a317a2e3 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm1d.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm1d.md
@@ -16,34 +16,32 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
-| num_features | num_features | 指明输入的通道数量 |
-| eps | epsilon | 为了数值稳定加在分母上的值 |
-| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写。 |
-| affine | - | 是否使用可学习的仿射参数,Paddle 无此参数,需要转写。可通过 weight_attr 和 bias_attr 控制。 |
-| track_running_stats | - | 是否跟踪运行时的 mean 和 var, Paddle 无此参数,暂无转写方式。 |
-| dtype | - | 输出数据类型, Paddle 无此参数, 需要转写。Paddle 应使用 astype 对计算结果做类型转换。 |
-| - | weight_attr | 可学习参数——权重的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 |
-| - | bias_attr | 可学习参数——偏差的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 |
-| - | data_format | 指定输入数据格式。 PyTorch 无此参数。 |
+| num_features | num_features | 指明输入的通道数量 |
+| eps | epsilon | 为了数值稳定加在分母上的值 |
+| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写。 |
+| affine | - | 是否使用可学习的仿射参数,Paddle 无此参数,需要转写。可通过 weight_attr 和 bias_attr 控制。 |
+| track_running_stats | - | 是否跟踪运行时的 mean 和 var, Paddle 无此参数,暂无转写方式。 |
+| dtype | - | 输出数据类型, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
+| - | weight_attr | 可学习参数——权重的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 |
+| - | bias_attr | 可学习参数——偏差的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 |
+| - | data_format | 指定输入数据格式。 PyTorch 无此参数。 |
### 转写示例
#### affine:是否使用可学习的仿射参数
```python
# PyTorch 写法
-IN = torch.nn.InstanceNorm1d(num_features, eps=1e-05, momentum=0.1, affine=False)
+IN = torch.nn.InstanceNorm1d(num_features, eps=1e-05, affine=False)
# Paddle 写法
-IN = paddle.nn.InstanceNorm1D(num_features, epsilon=1e-05, momentum=0.9, weight_attr=False, bias_attr=False)
+IN = paddle.nn.InstanceNorm1D(num_features, epsilon=1e-05,weight_attr=False, bias_attr=False)
```
-#### dtype:输出数据类型
+#### momentum:
```python
# PyTorch 写法
-IN = torch.nn.InstanceNorm1d(num_features, eps=1e-05, momentum=0.1, affine=False, dtype=torch.float32)
-y = IN(x)
+IN = torch.nn.InstanceNorm1d(num_features, eps=1e-05, momentum=0.8)
# Paddle 写法
-IN = paddle.nn.InstanceNorm1D(num_features, epsilon=1e-05, momentum=0.9, weight_attr=False, bias_attr=False)
-y = IN(x).astype(paddle.float32)
+IN = paddle.nn.InstanceNorm1D(num_features, epsilon=1e-05, momentum=0.2)
```
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm2d.md
index 78cff9d8dd3..2faa1735bbc 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm2d.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm2d.md
@@ -16,23 +16,32 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
-| num_features | num_features | 指明输入的通道数量。 |
-| eps | epsilon | 为了数值稳定加在分母上的值。 |
-| momentum | momentum | 此值用于计算 moving_mean 和 moving_var,值的大小 Paddle = 1 - PyTorch,需要转写。 |
-| affine | - | 是否使用可学习的仿射参数,Paddle 无此参数。可通过 weight_attr 和 bias_attr 控制。 |
-| track_running_stats | - | 是否跟踪运行时的 mean 和 var, Paddle 无此参数。暂无转写方式。 |
-| dtype | - | 输出数据类型, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
-| - | weight_attr | 可学习参数——权重的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 |
-| - | bias_attr | 可学习参数——偏差的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 |
-| - | data_format | 指定输入数据格式。 PyTorch 无此参数。 |
+| num_features | num_features | 指明输入的通道数量。 |
+| eps | epsilon | 为了数值稳定加在分母上的值。 |
+| momentum | momentum | 此值用于计算 moving_mean 和 moving_var,值的大小 Paddle = 1 - PyTorch,需要转写。 |
+| affine | - | 是否使用可学习的仿射参数,Paddle 无此参数。可通过 weight_attr 和 bias_attr 控制。 |
+| track_running_stats | - | 是否跟踪运行时的 mean 和 var, Paddle 无此参数。暂无转写方式。 |
+| dtype | - | 输出数据类型, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
+| - | weight_attr | 可学习参数——权重的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 |
+| - | bias_attr | 可学习参数——偏差的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 |
+| - | data_format | 指定输入数据格式。 PyTorch 无此参数。 |
### 转写示例
#### affine:是否使用可学习的仿射参数
```python
# PyTorch 写法
-IN = torch.nn.InstanceNorm2d(num_features, eps=1e-05, momentum=0.1, affine=False)
+IN = torch.nn.InstanceNorm2d(num_features, eps=1e-05, affine=False)
# Paddle 写法
-IN = paddle.nn.InstanceNorm2D(num_features, epsilon=1e-05, momentum=0.9, weight_attr=False, bias_attr=False)
+IN = paddle.nn.InstanceNorm2D(num_features, epsilon=1e-05, weight_attr=False, bias_attr=False)
+```
+
+#### momentum:
+```python
+# PyTorch 写法
+IN = torch.nn.InstanceNorm2d(num_features, eps=1e-05, momentum=0.8)
+
+# Paddle 写法
+IN = paddle.nn.InstanceNorm2D(num_features, epsilon=1e-05, momentum=0.2)
```
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm3d.md
index 7bbe3561b2f..c167070048a 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm3d.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm3d.md
@@ -20,7 +20,7 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
| ------------------- | ------------ | --------------------------------------------------------------- |
| num_features | num_features | 输入 Tensor 的通道数量。 |
| eps | epsilon | 为了数值稳定加在分母上的值,仅参数名不一致。 |
-| momentum | momentum | 此值用于计算 moving_mean 和 moving_var。 |
+| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写。。 |
| affine | - | 是否进行仿射变换,Paddle 无此参数,需要转写。 |
| track_running_stats | - | 是否跟踪运行时的 mean 和 var, Paddle 无此参数。暂无转写方式。 |
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
@@ -46,3 +46,13 @@ torch.nn.InstanceNorm3d(num_features, affine=True)
# paddle 写法
paddle.nn.InstanceNorm3d(num_features)
```
+
+
+#### momentum:
+```python
+# PyTorch 写法
+IN = torch.nn.InstanceNorm3d(num_features, eps=1e-05, momentum=0.8)
+
+# Paddle 写法
+IN = paddle.nn.InstanceNorm3d(num_features, epsilon=1e-05, momentum=0.2)
+```
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.nn.modules.batchnorm._BatchNorm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.nn.modules.batchnorm._BatchNorm.md
index 9abaf5a10c3..3d560cc815a 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.nn.modules.batchnorm._BatchNorm.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.nn.modules.batchnorm._BatchNorm.md
@@ -20,7 +20,7 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
| ------------------- | ---------------------------- | --------- |
| num_features | num_features | 特征数量。 |
| eps | epsilon | 一个极小正数,仅参数名不一致。 |
-| momentum | momentum | 动量因子,参数默认值不一致。 |
+| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写。 |
| affine | - | 是否进行仿射变换,Paddle 无此参数,需要转写。 |
| track_running_stats | - | 是否跟踪运行时的 mean 和 var, Paddle 无此参数。暂无转写方式。 |
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
@@ -46,3 +46,12 @@ torch.nn.modules.batchnorm._BatchNorm(num_features, affine=True)
# paddle 写法
paddle.nn.layer.norm._BatchNormBase(num_features)
```
+
+#### momentum:
+```python
+# PyTorch 写法
+m = torch.nn.modules.batchnorm._BatchNorm(num_features=24, momentum=0.2)
+
+# Paddle 写法
+m = paddle.nn.BatchNorm3D(num_features=24, momentum=0.8)
+```
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 897e5a86f21..7342df51194 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
@@ -368,6 +368,8 @@
| ALIAS-REFERENCE-ITEM(`torch.utils.data.sampler.SequentialSampler`, `torch.utils.data.SequentialSampler`) |
| ALIAS-REFERENCE-ITEM(`torch.utils.data.sampler.SubsetRandomSampler`, `torch.utils.data.SubsetRandomSampler`) |
| ALIAS-REFERENCE-ITEM(`torch.utils.data.sampler.WeightedRandomSampler`, `torch.utils.data.WeightedRandomSampler`) |
+| ALIAS-REFERENCE-ITEM(`torch.special.gammainc`, `torch.igamma`) |
+| ALIAS-REFERENCE-ITEM(`torch.special.gammaincc`, `torch.igammac`) |
## 功能缺失的 API 列表
@@ -1037,12 +1039,9 @@
| 序号 | Pytorch 最新 release | Paddle develop | 映射关系分类 | 备注 |
| ----- | ----------- | ----------------- | ----------- | ------- |
-| IN-DEVELOPMENT-PATTERN(`torch.igamma`, https://pytorch.org/docs/stable/generated/torch.igamma.html#torch-igamma) |
-| IN-DEVELOPMENT-PATTERN(`torch.igammac`, https://pytorch.org/docs/stable/generated/torch.igammac.html#torch-igammac) |
| IN-DEVELOPMENT-PATTERN(`torch.nn.parameter.UninitializedParameter`, https://pytorch.org/docs/stable/generated/torch.nn.parameter.UninitializedParameter.html#torch.nn.parameter.UninitializedParameter) |
| IN-DEVELOPMENT-PATTERN(`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#torch-nn-modules-module-register-module-forward-pre-hook) |
| IN-DEVELOPMENT-PATTERN(`torch.nn.modules.module.register_module_forward_hook`, https://pytorch.org/docs/stable/generated/torch.nn.modules.module.register_module_forward_hook.html#torch-nn-modules-module-register-module-forward-hook) |
-| IN-DEVELOPMENT-PATTERN(`torch.Tensor.requires_grad`, https://pytorch.org/docs/stable/generated/torch.Tensor.requires_grad.html#torch-tensor-requires-grad) |
| IN-DEVELOPMENT-PATTERN(`torch.cuda.device_of`, https://pytorch.org/docs/stable/generated/torch.cuda.device_of.html#torch.cuda.device_of) |
| IN-DEVELOPMENT-PATTERN(`torch.cuda.get_rng_state`, https://pytorch.org/docs/stable/generated/torch.cuda.get_rng_state.html#torch-cuda-get-rng-state) |
| IN-DEVELOPMENT-PATTERN(`torch.cuda.set_per_process_memory_fraction`, https://pytorch.org/docs/stable/generated/torch.cuda.set_per_process_memory_fraction.html#torch-cuda-set-per-process-memory-fraction) |
From b7f12ca77c153f51f4fd17fe6a5c3c7ca1062fc7 Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Mon, 24 Feb 2025 23:18:25 +0800
Subject: [PATCH 03/13] fix-docs
---
.../Tensor/torch.Tensor.requires_grad.md | 24 -------------------
1 file changed, 24 deletions(-)
delete mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad.md
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad.md
deleted file mode 100644
index 6a3bc403e7e..00000000000
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad.md
+++ /dev/null
@@ -1,24 +0,0 @@
-## [组合替代实现]torch.Tensor.requires_grad_
-
-### [torch.Tensor.requires_grad](https://pytorch.org/docs/stable/generated/torch.Tensor.requires_grad.html)
-
-```python
-torch.Tensor.requires_grad
-```
-
-### [paddle.Tensor.stop_gradient](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#stop-gradient)
-
-```python
-paddle.Tensor.stop_gradient
-```
-
-两者功能一致,且均无参数,Paddle 返回结果与 PyTorch 返回结果相反,具体如下:
-
-
-### 转写示例
-```python
-# torch 写法
-x.requires_grad
-
-# paddle 写法
-not x.stop_gradient
From 2be1f0a5efb0004b7fa2cef0d36d8c561232f81d Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Tue, 25 Feb 2025 00:05:24 +0800
Subject: [PATCH 04/13] fix-docs
---
.../convert_from_pytorch/pytorch_api_mapping_cn.md | 4 ++--
1 file changed, 2 insertions(+), 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 7342df51194..a3ee752d44d 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
@@ -368,8 +368,8 @@
| ALIAS-REFERENCE-ITEM(`torch.utils.data.sampler.SequentialSampler`, `torch.utils.data.SequentialSampler`) |
| ALIAS-REFERENCE-ITEM(`torch.utils.data.sampler.SubsetRandomSampler`, `torch.utils.data.SubsetRandomSampler`) |
| ALIAS-REFERENCE-ITEM(`torch.utils.data.sampler.WeightedRandomSampler`, `torch.utils.data.WeightedRandomSampler`) |
-| ALIAS-REFERENCE-ITEM(`torch.special.gammainc`, `torch.igamma`) |
-| ALIAS-REFERENCE-ITEM(`torch.special.gammaincc`, `torch.igammac`) |
+| ALIAS-REFERENCE-ITEM(`torch.igamma`, `torch.special.gammainc`) |
+| ALIAS-REFERENCE-ITEM(`torch.igammac`, `torch.special.gammaincc`) |
## 功能缺失的 API 列表
From 467f0911e31fd36718c29f4c120b55beebdc92fa Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Wed, 26 Feb 2025 15:50:26 +0800
Subject: [PATCH 05/13] fix-docs
---
.../distributed/torch.distributed.optim.DistributedOptimizer.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.optim.DistributedOptimizer.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.optim.DistributedOptimizer.md
index 4883f722167..e2204e54593 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.optim.DistributedOptimizer.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.optim.DistributedOptimizer.md
@@ -19,7 +19,7 @@ paddle.distributed.fleet.distributed_optimizer(optimizer, strategy=None)
| PyTorch | PaddlePaddle | 备注 |
| --------------- | ------------ | --------------------------------------------------------------------- |
-| optimizer_class | optimizer | 优化器,仅参数名不一致。 |
+| optimizer_class | optimizer | 优化器,PyTorch 输入为 class, Paddle 输入为实例化的 optimizer。 |
| params_rref | - | 远程引用( RRef )列表,为 RRef 类型,代表要优化的参数。而 Paddle 在实例化 optimizer 时传入,为 Tensor 类型 |
| args | - | 优化器实例化参数, Paddle 在实例化 optimizer 时传入。 |
| kwargs | - | 优化器实例化字典参数, Paddle 在实例化 optimizer 时传入。 |
From ecb30a7d8aa072976337040adc0338c32311dcce Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Thu, 6 Mar 2025 09:04:00 +0800
Subject: [PATCH 06/13] update docs
---
.../Tensor/torch.Tensor.where.md | 21 ++++++-------
.../cuda/torch.cuda.get_rng_state.md | 19 ++++++++++++
...ch.cuda.set_per_process_memory_fraction.md | 19 ++++++++++++
.../torch.distributed.is_available.md | 15 +++++++++
.../torch.distributed.is_nccl_available.md | 15 +++++++++
.../torch.distributed.monitored_barrier.md | 22 +++++++++++++
...les.module.register_module_forward_hook.md | 22 +++++++++++++
...module.register_module_forward_pre_hook.md | 21 +++++++++++++
.../torch.optim.Optimizer.zero_grad.md | 31 +++++++++++++++++++
.../torch/torch.get_default_device.md | 15 +++++++++
.../torch/torch.set_default_device.md | 20 ++++++++++++
.../pytorch_api_mapping_cn.md | 11 +------
12 files changed, 210 insertions(+), 21 deletions(-)
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_per_process_memory_fraction.md
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.is_available.md
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.is_nccl_available.md
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.monitored_barrier.md
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.zero_grad.md
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.get_default_device.md
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.where.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.where.md
index 991983b53e0..80725f504c7 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.where.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.where.md
@@ -3,23 +3,24 @@
### [torch.Tensor.where](https://pytorch.org/docs/stable/generated/torch.Tensor.where.html#torch.Tensor.where)
```python
-torch.Tensor.where(condition, y)
+torch.Tensor.where(condition, other)
```
-### [paddle.Tensor.where](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#where-y-name-none)
+### [paddle.where](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/where_cn.html)
```python
-paddle.Tensor.where(x, y, name=None)
+paddle.where(condition, x=None, y=None, name=None)
```
-两者功能一致,参数名和参数用法不一致,具体如下:
+Pytorch 为 Tensor 类方法,Paddle 为普通函数,具体如下:
+
### 参数映射
+
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
-| condition | - | condition 为判断条件。Paddle 无此参数,需要转写。|
-| - | x | 当 condition 为 true 时,选择 x 中元素。|
-| y | y | 当 condition 为 false 时,选择 y 中元素。|
-
+| condition | condition | 判断条件。|
+| self | x | 当 condition 为 true 时,选择的元素,调用 torch.Tensor 类方法的 self Tensor 传入。|
+| other | y | 当 condition 为 false 时,选择的元素,仅参数名不一致。|
### 转写示例
@@ -30,7 +31,5 @@ b = torch.tensor([2, 3, 0])
c = a.where(a > 0, b)
# paddle 写法
-a = paddle.to_tensor([0, 1, 2])
-b = paddle.to_tensor([2, 3, 0])
-c = (a > 0).where(a, b)
+paddle.where(a > 0, a, b)
```
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md
new file mode 100644
index 00000000000..90cb2f80ef3
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md
@@ -0,0 +1,19 @@
+## [ torch 参数更多 ]torch.cuda.get_rng_state
+### [torch.cuda.get_rng_state](https://pytorch.org/docs/stable/generated/torch.cuda.get_rng_state.html#torch-cuda-get-rng-state)
+
+```python
+torch.cuda.get_rng_state(device='cuda')
+```
+
+### [paddle.get_cuda_rng_state](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/get_cuda_rng_state_cn.html#get-cuda-rng-state)
+
+```python
+paddle.get_cuda_rng_state()
+```
+
+PyTorch 相比 Paddle 支持更多其他参数,具体如下:
+### 参数映射
+
+| PyTorch | PaddlePaddle | 备注 |
+| ------------- | ------------ | ------------------------------------------------------ |
+| device | - | 返回 RNG 状态的设备,Paddle 无此参数,暂无转写方式。 |
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_per_process_memory_fraction.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_per_process_memory_fraction.md
new file mode 100644
index 00000000000..901523350b9
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_per_process_memory_fraction.md
@@ -0,0 +1,19 @@
+## [ 组合替代实现 ]torch.cuda.set_per_process_memory_fraction
+
+### [torch.cuda.set_per_process_memory_fraction](https://pytorch.org/docs/stable/generated/torch.cuda.set_per_process_memory_fraction.html)
+
+```python
+torch.cuda.set_per_process_memory_fraction(fraction, device=None)
+```
+
+限制当前进程在指定 GPU 上最多能分配的显存比例,Paddle 无此 API,需要组合实现。
+
+### 转写示例
+
+```python
+# PyTorch 写法
+torch.cuda.set_per_process_memory_fraction(0.5)
+
+# Paddle 写法
+os.environ['FLAGS_fraction_of_gpu_memory_to_use'] = '0.5'
+```
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.is_available.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.is_available.md
new file mode 100644
index 00000000000..8112fb6400c
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.is_available.md
@@ -0,0 +1,15 @@
+## [无参数]torch.distributed.is_available
+
+### [torch.distributed.is_available](https://pytorch.org/docs/stable/distributed.html#torch.distributed.is_available)
+
+```python
+torch.distributed.is_available()
+```
+
+### [paddle.distributed.is_available](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/is_available_cn.html#cn-api-paddle-distributed-is-available)
+
+```python
+paddle.distributed.is_available()
+```
+
+两者功能一致,无参数。
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.is_nccl_available.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.is_nccl_available.md
new file mode 100644
index 00000000000..f2bb6841402
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.is_nccl_available.md
@@ -0,0 +1,15 @@
+## [无参数]torch.distributed.is_nccl_available
+
+### [torch.distributed.is_nccl_available](https://pytorch.org/docs/stable/distributed.html#torch.distributed.is_nccl_available)
+
+```python
+torch.distributed.is_nccl_available()
+```
+
+### [paddle.core.is_compiled_with_nccl](https://github.com/PaddlePaddle/Paddle/blob/61de6003525166856157b6220205fe53df638376/python/paddle/jit/sot/utils/paddle_api_config.py#L159)
+
+```python
+paddle.core.is_compiled_with_nccl()
+```
+
+两者功能一致,无参数。
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.monitored_barrier.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.monitored_barrier.md
new file mode 100644
index 00000000000..b72a13b5357
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.monitored_barrier.md
@@ -0,0 +1,22 @@
+## [ torch 参数更多 ] torch.distributed.monitored_barrier
+### [torch.distributed.monitored_barrier](https://pytorch.org/docs/stable/distributed.html#torch.distributed.monitored_barrier)
+
+```python
+torch.distributed.monitored_barrier(group=None, timeout=None, wait_all_ranks=False)
+```
+
+### [paddle.distributed.barrier](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/barrier_cn.html)
+
+```python
+paddle.distributed.barrier(group=None)
+```
+
+PyTorch 相比 Paddle 支持更多其他参数,具体如下:
+
+### 参数映射
+
+| PyTorch | PaddlePaddle | 备注 |
+| ------------- | ------------ | ------------------------------------------------------|
+| group | group | 进程组编号。 |
+| timeout | - | 超时时间,Paddle 无此参数,暂无转写方式。 |
+| wait_all_ranks | - | 是否等待所有进程超时后才报错,Paddle 无此参数,暂无转写方式。 |
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
new file mode 100644
index 00000000000..0f003d4fb79
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_hook.md
@@ -0,0 +1,22 @@
+## [ torch 参数更多 ]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
+torch.nn.modules.module.register_module_forward_hook(hook, *, prepend=False, with_kwargs=False, 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)
+
+```python
+paddle.nn.Layer.register_forward_post_hook(hook)
+```
+
+PyTorch 相比 Paddle 支持更多其他参数,具体如下:
+### 参数映射
+
+| PyTorch | PaddlePaddle | 备注 |
+| ------------- | ------------ | ------------------------------------------------------ |
+| hook | hook | 被注册为 forward pre-hook 的函数。 |
+| prepend | - | 钩子执行顺序控制,Paddle 无此参数,暂无转写方式。 |
+| with_kwargs | - | 是否传递关键字参数,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
new file mode 100644
index 00000000000..fec1fe697c2
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.module.register_module_forward_pre_hook.md
@@ -0,0 +1,21 @@
+## [ 参数完全一致 ]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)
+
+```python
+torch.nn.modules.module.register_module_forward_pre_hook(hook)
+```
+
+### [paddle.nn.Layer.register_forward_pre_hook](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#register-forward-pre-hook-hook)
+
+```python
+paddle.nn.Layer.register_forward_pre_hook(hook)
+```
+
+功能一致,参数完全一致,具体如下:
+
+### 参数映射
+
+| PyTorch | PaddlePaddle | 备注 |
+|---------|--------------|-----------------------------------------------------------------------------------------------|
+| hook | hook | 被注册为 forward pre-hook 的函数。 |
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.zero_grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.zero_grad.md
new file mode 100644
index 00000000000..cb2902cd689
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.zero_grad.md
@@ -0,0 +1,31 @@
+## [ 输入参数用法不一致 ]torch.nn.Module.zero_grad
+
+### [torch.optim.Optimizer.zero_grad](https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html)
+
+```python
+torch.optim.Optimizer.zero_grad(set_to_none=True)
+```
+
+### [paddle.optimizer.Optimizer.clear_gradients](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Optimizer_cn.html#clear-grad)
+
+```python
+paddle.optimizer.Optimizer.clear_gradients(set_to_zero=True)
+```
+
+PyTorch 的 `Optimizer.zero_grad` 参数与 Paddle 的 `Optimizer.clear_gradients` 参数用法刚好相反,具体如下:
+
+### 参数映射
+
+| PyTorch | PaddlePaddle | 备注 |
+| ----------- | ------------ | ------------------------------------------------ |
+| set_to_none | set_to_zero | 设置如何清空梯度,PyTorch 默认 set_to_none 为 True,Paddle 默认 set_to_zero 为 True,两者功能刚好相反,Paddle 需设置为 False。 |
+
+### 转写示例
+
+```python
+# PyTorch 写法
+torch.optim.Optimizer.zero_grad(set_to_none=True)
+
+# Paddle 写法
+paddle.optimizer.Optimizer.clear_gradients(set_to_zero=False)
+```
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.get_default_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.get_default_device.md
new file mode 100644
index 00000000000..757a680e1c9
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.get_default_device.md
@@ -0,0 +1,15 @@
+## [无参数]torch.get_default_device
+
+### [torch.get_default_device](https://pytorch.org/docs/stable/generated/torch.get_default_device.html#torch-get-default-device)
+
+```python
+torch.get_default_device()
+```
+
+### [paddle.device.get_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/get_device_cn.html#get-device)
+
+```python
+paddle.device.get_device()
+```
+
+功能一致,无参数。
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md
new file mode 100644
index 00000000000..a735fc5c0d5
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md
@@ -0,0 +1,20 @@
+## [ 输入参数类型不一致 ]torch.set_default_device
+
+### [torch.set_default_device](https://pytorch.org/docs/stable/generated/torch.set_default_device.html#torch-set-default-device)
+
+```python
+torch.set_default_device(device)
+```
+
+### [paddle.device.set_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/set_device_cn.html#set-device)
+
+```python
+paddle.device.set_device(device)
+```
+
+功能一致,参数类型不一致,具体如下:
+### 参数映射
+
+| PyTorch | PaddlePaddle | 备注 |
+| ------------- | ------------ |------------------------------------------------|
+| device | device | PyTorch 支持 torch.device 。PaddlePaddle 支持 str。 |
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 a3ee752d44d..9f7d64b92fb 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
@@ -370,6 +370,7 @@
| ALIAS-REFERENCE-ITEM(`torch.utils.data.sampler.WeightedRandomSampler`, `torch.utils.data.WeightedRandomSampler`) |
| 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`) |
## 功能缺失的 API 列表
@@ -1040,16 +1041,9 @@
| 序号 | Pytorch 最新 release | Paddle develop | 映射关系分类 | 备注 |
| ----- | ----------- | ----------------- | ----------- | ------- |
| IN-DEVELOPMENT-PATTERN(`torch.nn.parameter.UninitializedParameter`, https://pytorch.org/docs/stable/generated/torch.nn.parameter.UninitializedParameter.html#torch.nn.parameter.UninitializedParameter) |
-| IN-DEVELOPMENT-PATTERN(`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#torch-nn-modules-module-register-module-forward-pre-hook) |
-| IN-DEVELOPMENT-PATTERN(`torch.nn.modules.module.register_module_forward_hook`, https://pytorch.org/docs/stable/generated/torch.nn.modules.module.register_module_forward_hook.html#torch-nn-modules-module-register-module-forward-hook) |
| IN-DEVELOPMENT-PATTERN(`torch.cuda.device_of`, https://pytorch.org/docs/stable/generated/torch.cuda.device_of.html#torch.cuda.device_of) |
-| IN-DEVELOPMENT-PATTERN(`torch.cuda.get_rng_state`, https://pytorch.org/docs/stable/generated/torch.cuda.get_rng_state.html#torch-cuda-get-rng-state) |
-| IN-DEVELOPMENT-PATTERN(`torch.cuda.set_per_process_memory_fraction`, https://pytorch.org/docs/stable/generated/torch.cuda.set_per_process_memory_fraction.html#torch-cuda-set-per-process-memory-fraction) |
| IN-DEVELOPMENT-PATTERN(`torch.distributed.Backend`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.Backend) |
-| IN-DEVELOPMENT-PATTERN(`torch.distributed.is_available`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.is_available) |
-| IN-DEVELOPMENT-PATTERN(`torch.distributed.is_nccl_available`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.is_nccl_available) |
| IN-DEVELOPMENT-PATTERN(`torch.distributed.gather_object`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.gather_object) |
-| IN-DEVELOPMENT-PATTERN(`torch.distributions.multivariate_normal.MultivariateNormal`, https://pytorch.org/docs/stable/distributions.html#torch.distributions.multivariate_normal.MultivariateNormal) |
| IN-DEVELOPMENT-PATTERN(`torch.jit.script`, https://pytorch.org/docs/stable/generated/torch.jit.script.html#torch-jit-script) |
| IN-DEVELOPMENT-PATTERN(`torch.jit.trace`, https://pytorch.org/docs/stable/generated/torch.jit.trace.html#torch-jit-trace) |
| IN-DEVELOPMENT-PATTERN(`torch.jit.save`, https://pytorch.org/docs/stable/generated/torch.jit.save.html#torch-jit-save) |
@@ -1058,8 +1052,6 @@
| IN-DEVELOPMENT-PATTERN(`torch.utils.checkpoint.checkpoint_sequential`, https://pytorch.org/docs/stable/checkpoint.html#torch.utils.checkpoint.checkpoint_sequential) |
| IN-DEVELOPMENT-PATTERN(`torch.utils.tensorboard.writer.SummaryWriter`, https://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter) |
| 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.optim.Optimizer.zero_grad`, https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html#torch-optim-optimizer-zero-grad) |
-| IN-DEVELOPMENT-PATTERN(`torch.distributed.monitored_barrier`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.monitored_barrier) |
| 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.set_default_device`, https://pytorch.org/docs/stable/generated/torch.set_default_device.html#torch-set-default-device) |
@@ -1137,7 +1129,6 @@
| IN-DEVELOPMENT-PATTERN(`torch.distributed.reduce_scatter_tensor`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.reduce_scatter_tensor) |
| IN-DEVELOPMENT-PATTERN(`torch.distributed.all_to_all_single`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.all_to_all_single) |
| IN-DEVELOPMENT-PATTERN(`torch.utils.set_module`, https://pytorch.org/docs/stable/generated/torch.utils.set_module.html#torch-utils-set-module) |
-| IN-DEVELOPMENT-PATTERN(`torch.get_default_device`, https://pytorch.org/docs/stable/generated/torch.get_default_device.html#torch-get-default-device) |
| IN-DEVELOPMENT-PATTERN(`torch.nn.utils.fuse_conv_bn_eval`, https://pytorch.org/docs/stable/generated/torch.nn.utils.fuse_conv_bn_eval.html#torch-nn-utils-fuse-conv-bn-eval) |
| IN-DEVELOPMENT-PATTERN(`torch.nn.utils.fuse_conv_bn_weights`, https://pytorch.org/docs/stable/generated/torch.nn.utils.fuse_conv_bn_weights.html#torch-nn-utils-fuse-conv-bn-weights) |
| IN-DEVELOPMENT-PATTERN(`torch.nn.utils.fuse_linear_bn_eval`, https://pytorch.org/docs/stable/generated/torch.nn.utils.fuse_linear_bn_eval.html#torch-nn-utils-fuse-linear-bn-eval) |
From 299586967439b72813ccb43ceb0a903c86e282fe Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Thu, 6 Mar 2025 09:42:31 +0800
Subject: [PATCH 07/13] fix-bugs
---
.../api_difference/optimizer/torch.optim.Optimizer.zero_grad.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.zero_grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.zero_grad.md
index cb2902cd689..4811ba85966 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.zero_grad.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.zero_grad.md
@@ -1,4 +1,4 @@
-## [ 输入参数用法不一致 ]torch.nn.Module.zero_grad
+## [ 输入参数用法不一致 ]torch.optim.Optimizer.zero_grad
### [torch.optim.Optimizer.zero_grad](https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html)
From d9240e6f08ea45e88bf0c7d2de98262153530a69 Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Thu, 6 Mar 2025 18:45:50 +0800
Subject: [PATCH 08/13] update docs
---
.../cuda/torch.cuda.device_of.md | 21 +++++++++++++++++++
.../pytorch_api_mapping_cn.md | 1 -
2 files changed, 21 insertions(+), 1 deletion(-)
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
new file mode 100644
index 00000000000..6af3d0f190b
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
@@ -0,0 +1,21 @@
+## [组合替代实现]torch.cuda.device_of
+
+### [torch.cuda.device_of](https://pytorch.org/docs/stable/generated/torch.cuda.device_of.html)
+
+```python
+torch.cuda.device_of(obj)
+```
+
+Paddle 无此 API,需要组合实现。
+
+### 转写示例
+
+```python
+# PyTorch 写法
+torch.cuda.device_of(obj)
+
+# Paddle 写法
+device_id = obj.place.gpu_device_id()
+paddle.set_device(f"gpu:{device_id}")
+paddle.device.get_device()
+```
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 9f7d64b92fb..ed94e758428 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
@@ -1041,7 +1041,6 @@
| 序号 | Pytorch 最新 release | Paddle develop | 映射关系分类 | 备注 |
| ----- | ----------- | ----------------- | ----------- | ------- |
| IN-DEVELOPMENT-PATTERN(`torch.nn.parameter.UninitializedParameter`, https://pytorch.org/docs/stable/generated/torch.nn.parameter.UninitializedParameter.html#torch.nn.parameter.UninitializedParameter) |
-| IN-DEVELOPMENT-PATTERN(`torch.cuda.device_of`, https://pytorch.org/docs/stable/generated/torch.cuda.device_of.html#torch.cuda.device_of) |
| IN-DEVELOPMENT-PATTERN(`torch.distributed.Backend`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.Backend) |
| IN-DEVELOPMENT-PATTERN(`torch.distributed.gather_object`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.gather_object) |
| IN-DEVELOPMENT-PATTERN(`torch.jit.script`, https://pytorch.org/docs/stable/generated/torch.jit.script.html#torch-jit-script) |
From e571b61afd63814f7d19ab8cb030b889ea978d34 Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Sun, 9 Mar 2025 15:14:47 +0800
Subject: [PATCH 09/13] update docs
---
.../cuda/torch.cuda.device_of.md | 21 -------------------
.../cuda/torch.cuda.get_rng_state.md | 20 +++++++++++++++---
.../torch/torch.get_default_device.md | 4 ++--
.../torch/torch.set_default_device.md | 4 ++--
.../pytorch_api_mapping_cn.md | 1 +
5 files changed, 22 insertions(+), 28 deletions(-)
delete mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
deleted file mode 100644
index 6af3d0f190b..00000000000
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
+++ /dev/null
@@ -1,21 +0,0 @@
-## [组合替代实现]torch.cuda.device_of
-
-### [torch.cuda.device_of](https://pytorch.org/docs/stable/generated/torch.cuda.device_of.html)
-
-```python
-torch.cuda.device_of(obj)
-```
-
-Paddle 无此 API,需要组合实现。
-
-### 转写示例
-
-```python
-# PyTorch 写法
-torch.cuda.device_of(obj)
-
-# Paddle 写法
-device_id = obj.place.gpu_device_id()
-paddle.set_device(f"gpu:{device_id}")
-paddle.device.get_device()
-```
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md
index 90cb2f80ef3..7d0557aa589 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md
@@ -1,4 +1,4 @@
-## [ torch 参数更多 ]torch.cuda.get_rng_state
+## [ 返回参数类型不一致 ]torch.cuda.get_rng_state
### [torch.cuda.get_rng_state](https://pytorch.org/docs/stable/generated/torch.cuda.get_rng_state.html#torch-cuda-get-rng-state)
```python
@@ -11,9 +11,23 @@ torch.cuda.get_rng_state(device='cuda')
paddle.get_cuda_rng_state()
```
-PyTorch 相比 Paddle 支持更多其他参数,具体如下:
+torch 参数更多,并且 torch 与 paddle 的返回参数类型不一致,具体如下:
+
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
-| device | - | 返回 RNG 状态的设备,Paddle 无此参数,暂无转写方式。 |
+| device | - | 返回 RNG 状态的设备,Paddle 无此参数,需要转写。 |
+| 返回值 | 返回值 | 返回参数类型不一致, PyTorch 返回 torch.ByteTensor,Paddle 返回 GeneratorState 对象列表。 |
+
+### 转写示例
+
+#### 返回参数类型不同
+
+```python
+# PyTorch 写法,返回 torch.ByteTensor
+x = torch.cuda.get_rng_state(device='cuda:0')
+
+# Paddle 写法,返回 GeneratorState 对象
+x = paddle.get_cuda_rng_state()[0]
+```
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.get_default_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.get_default_device.md
index 757a680e1c9..d7fd2889bcf 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.get_default_device.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.get_default_device.md
@@ -6,10 +6,10 @@
torch.get_default_device()
```
-### [paddle.device.get_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/get_device_cn.html#get-device)
+### [paddle.get_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/get_device_cn.html#get-device)
```python
-paddle.device.get_device()
+paddle.get_device()
```
功能一致,无参数。
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md
index a735fc5c0d5..ed831e09731 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md
@@ -6,10 +6,10 @@
torch.set_default_device(device)
```
-### [paddle.device.set_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/set_device_cn.html#set-device)
+### [paddle.set_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/set_device_cn.html#set-device)
```python
-paddle.device.set_device(device)
+paddle.set_device(device)
```
功能一致,参数类型不一致,具体如下:
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 ed94e758428..50c192acbb9 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
@@ -1042,6 +1042,7 @@
| ----- | ----------- | ----------------- | ----------- | ------- |
| IN-DEVELOPMENT-PATTERN(`torch.nn.parameter.UninitializedParameter`, https://pytorch.org/docs/stable/generated/torch.nn.parameter.UninitializedParameter.html#torch.nn.parameter.UninitializedParameter) |
| IN-DEVELOPMENT-PATTERN(`torch.distributed.Backend`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.Backend) |
+| IN-DEVELOPMENT-PATTERN(`torch.cuda.device_of`, https://pytorch.org/docs/stable/generated/torch.cuda.device_of.html#torch.cuda.device_of) |
| IN-DEVELOPMENT-PATTERN(`torch.distributed.gather_object`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.gather_object) |
| IN-DEVELOPMENT-PATTERN(`torch.jit.script`, https://pytorch.org/docs/stable/generated/torch.jit.script.html#torch-jit-script) |
| IN-DEVELOPMENT-PATTERN(`torch.jit.trace`, https://pytorch.org/docs/stable/generated/torch.jit.trace.html#torch-jit-trace) |
From 9aae6cdea370cb0d828e746276656779bf23482f Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Mon, 10 Mar 2025 15:06:00 +0800
Subject: [PATCH 10/13] update docs
---
.../cuda/torch.cuda.device_of.md | 31 +++++++++++++++++++
.../pytorch_api_mapping_cn.md | 1 -
2 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
new file mode 100644
index 00000000000..68ecfb35538
--- /dev/null
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
@@ -0,0 +1,31 @@
+## [ 输入参数类型不一致 ]torch.cuda.device_of
+
+### [torch.cuda.device_of](https://pytorch.org/docs/stable/generated/torch.cuda.device_of.html)
+
+```python
+torch.cuda.device_of(obj)
+```
+
+### [paddle.static.device_guard](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/static/device_guard_cn.html#device-guard)
+
+```python
+paddle.static.device_guard(device=None)
+```
+
+其中 PyTorch 与 Paddle 的参数支持类型不一致,具体如下:
+
+### 参数映射
+
+| PyTorch | PaddlePaddle | 备注 |
+| ------- | ------------ | -------------------------------------------------------------------------------- |
+| obj | device | PyTorch 输入为在所选设备上分配的对象,Paddle 为 指定上下文中使用的设备,需要转写。 |
+
+
+### 转写示例
+```python
+
+# PyTorch 写法
+with torch.cuda.device_of(innput_tensor)
+
+# Paddle 写法
+with paddle.static.device_guard("gpu:{}".format(input_tensor.place.gpu_device_id()))
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 50c192acbb9..ed94e758428 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
@@ -1042,7 +1042,6 @@
| ----- | ----------- | ----------------- | ----------- | ------- |
| IN-DEVELOPMENT-PATTERN(`torch.nn.parameter.UninitializedParameter`, https://pytorch.org/docs/stable/generated/torch.nn.parameter.UninitializedParameter.html#torch.nn.parameter.UninitializedParameter) |
| IN-DEVELOPMENT-PATTERN(`torch.distributed.Backend`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.Backend) |
-| IN-DEVELOPMENT-PATTERN(`torch.cuda.device_of`, https://pytorch.org/docs/stable/generated/torch.cuda.device_of.html#torch.cuda.device_of) |
| IN-DEVELOPMENT-PATTERN(`torch.distributed.gather_object`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.gather_object) |
| IN-DEVELOPMENT-PATTERN(`torch.jit.script`, https://pytorch.org/docs/stable/generated/torch.jit.script.html#torch-jit-script) |
| IN-DEVELOPMENT-PATTERN(`torch.jit.trace`, https://pytorch.org/docs/stable/generated/torch.jit.trace.html#torch-jit-trace) |
From e1590b895799230d84704e2e960d17f19019b206 Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Mon, 10 Mar 2025 16:35:04 +0800
Subject: [PATCH 11/13] update docs
---
.../distributed/torch.distributed.monitored_barrier.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.monitored_barrier.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.monitored_barrier.md
index b72a13b5357..12de62e200b 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.monitored_barrier.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.monitored_barrier.md
@@ -18,5 +18,5 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------|
| group | group | 进程组编号。 |
-| timeout | - | 超时时间,Paddle 无此参数,暂无转写方式。 |
-| wait_all_ranks | - | 是否等待所有进程超时后才报错,Paddle 无此参数,暂无转写方式。 |
+| timeout | - | 超时时间,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
+| wait_all_ranks | - | 是否等待所有进程超时后才报错,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
From fa80805557e4369bbee04f7d821f293a2ddda6fa Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Mon, 10 Mar 2025 17:37:24 +0800
Subject: [PATCH 12/13] update docs
---
.../cuda/torch.cuda.device_of.md | 31 -------------------
.../pytorch_api_mapping_cn.md | 1 +
2 files changed, 1 insertion(+), 31 deletions(-)
delete mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
deleted file mode 100644
index 68ecfb35538..00000000000
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_of.md
+++ /dev/null
@@ -1,31 +0,0 @@
-## [ 输入参数类型不一致 ]torch.cuda.device_of
-
-### [torch.cuda.device_of](https://pytorch.org/docs/stable/generated/torch.cuda.device_of.html)
-
-```python
-torch.cuda.device_of(obj)
-```
-
-### [paddle.static.device_guard](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/static/device_guard_cn.html#device-guard)
-
-```python
-paddle.static.device_guard(device=None)
-```
-
-其中 PyTorch 与 Paddle 的参数支持类型不一致,具体如下:
-
-### 参数映射
-
-| PyTorch | PaddlePaddle | 备注 |
-| ------- | ------------ | -------------------------------------------------------------------------------- |
-| obj | device | PyTorch 输入为在所选设备上分配的对象,Paddle 为 指定上下文中使用的设备,需要转写。 |
-
-
-### 转写示例
-```python
-
-# PyTorch 写法
-with torch.cuda.device_of(innput_tensor)
-
-# Paddle 写法
-with paddle.static.device_guard("gpu:{}".format(input_tensor.place.gpu_device_id()))
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 ed94e758428..dbe74c38192 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
@@ -1035,6 +1035,7 @@
| NOT-IMPLEMENTED-ITEM(`torch.cuda.memory_usage`, https://pytorch.org/docs/stable/generated/torch.cuda.memory_usage.html#torch-cuda-memory-usage, 可新增,且框架底层有相关设计,成本低) |
| 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, 可新增,且框架底层有相关设计,成本低) |
## 映射关系开发中的 API 列表
From f08ac9213a3256518251bc41b047f95f0b8f65e8 Mon Sep 17 00:00:00 2001
From: xxa <1829994704@qq.com>
Date: Wed, 12 Mar 2025 11:58:52 +0800
Subject: [PATCH 13/13] update docs
---
.../api_difference/cuda/torch.cuda.get_rng_state.md | 8 ++++++++
.../convert_from_pytorch/pytorch_api_mapping_cn.md | 1 -
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md
index 7d0557aa589..c28c60a81d1 100644
--- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md
+++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state.md
@@ -31,3 +31,11 @@ x = torch.cuda.get_rng_state(device='cuda:0')
# Paddle 写法,返回 GeneratorState 对象
x = paddle.get_cuda_rng_state()[0]
```
+
+```python
+# PyTorch 写法,返回 torch.ByteTensor
+x = torch.cuda.get_rng_state()
+
+# Paddle 写法,返回 GeneratorState 对象
+x = paddle.get_cuda_rng_state()[paddle.framework._current_expected_place().get_device_id()]
+```
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 dbe74c38192..4a22caf0ac8 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
@@ -1054,7 +1054,6 @@
| 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.set_default_device`, https://pytorch.org/docs/stable/generated/torch.set_default_device.html#torch-set-default-device) |
| 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) |