From 4da15bc07c48c452ea8c05317c74ddff9fc12d6d Mon Sep 17 00:00:00 2001 From: wenyin Date: Tue, 9 May 2023 18:16:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=A0=E5=B0=84=E6=96=87=E6=A1=A3=20No.=2059?= =?UTF-8?q?=20(#5857)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 映射文档 No. 59 * 映射文档 No. 59 * 映射文档 No. 59 --- .../Tensor/torch.Tensor.bernoulli.md | 33 ++++++++++++++++ .../Tensor/torch.Tensor.bfloat16.md | 33 ++++++++++++++++ .../Tensor/torch.Tensor.bool.md | 33 ++++++++++++++++ .../Tensor/torch.Tensor.byte.md | 33 ++++++++++++++++ .../Tensor/torch.Tensor.char.md | 31 +++++++++++++++ .../Tensor/torch.Tensor.clone.md | 21 ++++++++++ .../Tensor/torch.Tensor.copy_.md | 5 ++- .../api_difference/Tensor/torch.Tensor.div.md | 38 +++++++++++++++++++ .../Tensor/torch.Tensor.divide.md | 38 +++++++++++++++++++ .../Tensor/torch.Tensor.double.md | 31 +++++++++++++++ 10 files changed, 294 insertions(+), 2 deletions(-) create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bernoulli.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bfloat16.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bool.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.byte.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.char.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clone.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.div.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.divide.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.double.md diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bernoulli.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bernoulli.md new file mode 100644 index 00000000000..528bf116391 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bernoulli.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ] torch.Tensor.bernoulli + +### [torch.Tensor.bernoulli](https://pytorch.org/docs/1.13/generated/torch.Tensor.bernoulli.html#torch.Tensor.bernoulli) + +```python +torch.Tensor.bernoulli(*, generator=None) +``` + +### [paddle.bernoulli](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bernoulli_cn.html#bernoulli) + +```python +paddle.bernoulli(x, name=None) +``` + +其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| generator | - | 用于采样的伪随机数生成器, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.tensor([0.2, 0.6, 0.8]) +y = x.bernoulli() + +# paddle 写法 +x = paddle.to_tensor([0.2, 0.6, 0.8]) +y = paddle.bernoulli(x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bfloat16.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bfloat16.md new file mode 100644 index 00000000000..d5a54a49f18 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bfloat16.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ] torch.Tensor.bfloat16 + +### [torch.Tensor.bfloat16](https://pytorch.org/docs/1.13/generated/torch.Tensor.bfloat16.html#torch.Tensor.bfloat16) + +```python +torch.Tensor.bfloat16(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('bfloat16') +``` + +其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.randn(3, 3) +y = x.bfloat16() + +# paddle 写法 +x = paddle.randn([3, 3]) +y = x.astype('bfloat16') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bool.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bool.md new file mode 100644 index 00000000000..6476ef09200 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bool.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ] torch.Tensor.bool + +### [torch.Tensor.bool](https://pytorch.org/docs/1.13/generated/torch.Tensor.bool.html#torch.Tensor.bool) + +```python +torch.Tensor.bool(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('bool') +``` + +其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.tensor([-1, 0, 1]) +y = x.bool() + +# paddle 写法 +x = paddle.to_tensor([-1, 0, 1]) +y = x.astype('bool') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.byte.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.byte.md new file mode 100644 index 00000000000..405c99817a3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.byte.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ] torch.Tensor.byte + +### [torch.Tensor.byte](https://pytorch.org/docs/1.13/generated/torch.Tensor.byte.html#torch.Tensor.byte) + +```python +torch.Tensor.byte(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('uint8') +``` + +其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.tensor([0, 1, 2, 3]) +y = x.byte() + +# paddle 写法 +x = paddle.to_tensor([0, 1, 2, 3]) +y = x.astype('uint8') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.char.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.char.md new file mode 100644 index 00000000000..a29cf358426 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.char.md @@ -0,0 +1,31 @@ +## [ torch 参数更多 ] torch.Tensor.char + +### [torch.Tensor.char](https://pytorch.org/docs/1.13/generated/torch.Tensor.char.html#torch.Tensor.char) + +```python +torch.Tensor.char(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('int8') +``` + +其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +```python +# torch 写法 +x.char() + +# paddle 写法 +x.astype('int8') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clone.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clone.md new file mode 100644 index 00000000000..cae5feeb191 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clone.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.clone + +### [torch.Tensor.clone](https://pytorch.org/docs/1.13/generated/torch.Tensor.clone.html#torch.Tensor.clone) + +```python +torch.Tensor.clone(*, memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.clone](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#clone) + +```python +paddle.Tensor.clone() +``` + +其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.copy_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.copy_.md index a0f4a067370..07292bf3492 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.copy_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.copy_.md @@ -1,5 +1,6 @@ -## torch.Tensor.copy_ -### [torch.Tensor.copy_](https://pytorch.org/docs/stable/generated/torch.Tensor.copy_.html?highlight=copy_#torch.Tensor.copy_) +## [ torch 参数更多 ] torch.Tensor.copy_ + +### [torch.Tensor.copy_](https://pytorch.org/docs/1.13/generated/torch.Tensor.copy_.html#torch.Tensor.copy_) ```python torch.Tensor.copy_(src, non_blocking=False) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.div.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.div.md new file mode 100644 index 00000000000..1aaad8a3874 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.div.md @@ -0,0 +1,38 @@ +## [ torch 参数更多 ] torch.Tensor.div + +### [torch.Tensor.div](https://pytorch.org/docs/1.13/generated/torch.Tensor.div.html#torch.Tensor.div) + +```python +torch.Tensor.div(other, *, rounding_mode=None) +``` + +### [paddle.Tensor.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#divide-y-name-none) + +```python +paddle.Tensor.divide(y, name=None) +``` + +其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| rounding_mode | - | 用于指定在执行截断除法时的舍入模式,可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要进行转写。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.tensor([4, 8, 12], dtype=torch.float32) +y = torch.tensor([3, 4, 5], dtype=torch.float32) +z1 = x.div(y, rounding_mode='floor') # 向下取整 +z2 = x.div(y, rounding_mode='trunc') # 向零取整 + +# paddle 写法 +x = paddle.to_tensor([4, 8, 12], dtype='float32') +y = paddle.to_tensor([3, 4, 5], dtype='float32') +z1 = x.divide(y).floor() # 向下取整 +z2 = x.divide(y).trunc() # 向零取整 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.divide.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.divide.md new file mode 100644 index 00000000000..098ed923f55 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.divide.md @@ -0,0 +1,38 @@ +## [ torch 参数更多 ] torch.Tensor.divide + +### [torch.Tensor.divide](https://pytorch.org/docs/1.13/generated/torch.Tensor.divide.html#torch.Tensor.divide) + +```python +torch.Tensor.divide(other, *, rounding_mode=None) +``` + +### [paddle.Tensor.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#divide-y-name-none) + +```python +paddle.Tensor.divide(y, name=None) +``` + +其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| rounding_mode | - | 用于指定在执行截断除法时的舍入模式。可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要进行转写。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.tensor([4, 8, 12], dtype=torch.float32) +y = torch.tensor([3, 4, 5], dtype=torch.float32) +z1 = x.divide(y, rounding_mode='floor') # 向下取整 +z2 = x.divide(y, rounding_mode='trunc') # 向零取整 + +# paddle 写法 +x = paddle.to_tensor([4, 8, 12], dtype='float32') +y = paddle.to_tensor([3, 4, 5], dtype='float32') +z1 = x.divide(y).floor() # 向下取整 +z2 = x.divide(y).trunc() # 向零取整 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.double.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.double.md new file mode 100644 index 00000000000..2c80c2f4e5a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.double.md @@ -0,0 +1,31 @@ +## [ torch 参数更多 ] torch.Tensor.double + +### [torch.Tensor.double](https://pytorch.org/docs/1.13/generated/torch.Tensor.double.html#torch-Tensor-double) + +```python +torch.Tensor.double(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('float64') +``` + +其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +```python +# torch 写法 +x.double() + +# paddle 写法 +x.astype('float64') +```