diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.quantile.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.quantile.md new file mode 100644 index 00000000000..1747e3ad0ba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.quantile.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.Tensor.quantile + +### [torch.Tensor.quantile](https://pytorch.org/docs/1.13/generated/torch.Tensor.quantile.html#torch.Tensor.quantile) + +```python +torch.Tensor.quantile(q, dim=None, keepdim=False, *, interpolation='linear') +``` + +### [paddle.Tensor.quantile](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#quantile-q-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.quantile(q, axis=None, keepdim=False, name=None) +``` + +其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------ | +| q | q |待计算的分位数。 | +| dim | axis |指定对 x 进行计算的轴,仅参数名不一致。| +| keepdim | keepdim |是否在输出 Tensor 中保留减小的维度。| +| interpolation | - |两个数据点的插补取值方法,Paddle 无此参数,暂无转写方式。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round.md new file mode 100644 index 00000000000..222c576f6ba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round.md @@ -0,0 +1,32 @@ +## [torch 参数更多]torch.Tensor.round + +### [torch.Tensor.round](https://pytorch.org/docs/1.13/generated/torch.Tensor.round.html#torch.Tensor.round) + +```python +torch.Tensor.round(decimals=0) +``` + +### [paddle.Tensor.round](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#round-name-none) + +```python +paddle.Tensor.round(name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------- | ------- | +| decimals | - | 舍入小数位数 | + +### 转写示例 +#### decimals:要舍入到的小数位数 +```python +# Pytorch 写法 +torch.tensor([3.345, 5.774]).round(decimals=2) + +# Paddle 写法 +(paddle.to_tensor([3.345, 5.774]) * 1e2).round() / 1e2 + +# 注:Paddle 可使用 10 的 decimals 次方来实现 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round_.md new file mode 100644 index 00000000000..2d7dcf6ac7e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round_.md @@ -0,0 +1,32 @@ +## [torch 参数更多]torch.Tensor.round_ + +### [torch.Tensor.round_](https://pytorch.org/docs/1.13/generated/torch.Tensor.round_.html#torch.Tensor.round_) + +```python +torch.Tensor.round_(decimals=0) +``` + +### [paddle.Tensor.round_](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#round-name-none) + +```python +paddle.Tensor.round_(name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------- | ------- | +| decimals | - | 舍入小数位数 | + +### 转写示例 +#### decimals:要舍入到的小数位数 +```python +# Pytorch 写法 +torch.tensor([3.345, 5.774]).round_(decimals=2) + +# Paddle 写法 +(paddle.to_tensor([3.345, 5.774]) * 1e2).round_() / 1e2 + +# 注:Paddle 可使用 10 的 decimals 次方来实现 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.md new file mode 100644 index 00000000000..040b2dbe69c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.md @@ -0,0 +1,24 @@ +## [仅 paddle 参数更多]torch.Tensor.scatter + +### [torch.Tensor.scatter](https://pytorch.org/docs/1.13/generated/torch.Tensor.scatter.html#torch.Tensor.scatter) + +```python +torch.Tensor.scatter(dim, index, src) +``` + +### [paddle.Tensor.put_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#put-along-axis-arr-index-value-axis-reduce-assign) + +```python +paddle.Tensor.put_along_axis(index, value, axis, reduce="assign") + +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------- | +| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 | +| index | index | 表示输入的索引张量,仅参数名不一致。 | +| src | value | 表示需要插入的值,仅参数名不一致。 | +| - | reduce | 归约操作类型,PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_add.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_add.md new file mode 100644 index 00000000000..1dcc7889a0c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_add.md @@ -0,0 +1,20 @@ +## [组合替代实现]torch.Tensor.scatter_add + +### [torch.Tensor.scatter_add](https://pytorch.org/docs/1.13/generated/torch.Tensor.scatter_add.html#torch.Tensor.scatter_add) + +```python +torch.Tensor.scatter_add(dim, index, src) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# Pytorch 写法 +x.scatter_add(dim, index, src) + +# Paddle 写法 +x2 = paddle.zeros(x.shape) +y = x + x2.put_along_axis(index, value, axis) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.short.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.short.md new file mode 100644 index 00000000000..df5aebcde9b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.short.md @@ -0,0 +1,20 @@ +## [torch 参数更多]torch.Tensor.short + +### [torch.Tensor.short](https://pytorch.org/docs/1.13/generated/torch.Tensor.short.html#torch.Tensor.short) + +```python +torch.Tensor.short(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#put-along-axis-arr-index-value-axis-reduce-assign) + +```python +paddle.Tensor.astype('int16') +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md new file mode 100644 index 00000000000..4c4a38c927a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md @@ -0,0 +1,30 @@ +## [torch 参数更多]torch.Tensor.size + +### [torch.Tensor.size](https://pytorch.org/docs/1.13/generated/torch.Tensor.size.html#torch.Tensor.size) + +```python +torch.Tensor.size(dim=None) +``` + +### [paddle.Tensor.shape](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#shape) + +```python +paddle.Tensor.shape +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------- | +| dim | - | 表示获取大小的轴,Paddle 无此参数,需要进行转写。 | + +### 转写示例 + +```python +# Pytorch 写法 +torch.tensor([-1, -2, 3]).size(0) + +# Paddle 写法 +paddle.to_tensor([-0.4, -0.2, 0.1, 0.3]).shape[0] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.stft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.stft.md new file mode 100644 index 00000000000..7232708842a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.stft.md @@ -0,0 +1,38 @@ +## [torch 参数更多]torch.Tensor.stft + +### [torch.Tensor.stft](https://pytorch.org/docs/1.13/generated/torch.Tensor.stft.html#torch.Tensor.stft) + +```python +torch.Tensor.stft(n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=None, return_complex=None) +``` + +### [paddle.signal.stft](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/signal/stft_cn.html) + +```python +paddle.signal.stft(x, n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=True, name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | ------- | +| n_fft | n_fft | 离散傅里叶变换的样本点个数。 | +| hop_length | hop_length | 对输入分帧时,相邻两帧偏移的样本点个数。 | +| win_length | win_length | 信号窗的长度。 | +| window | window | 维度为 1D 长度为 win_length 的 Tensor。 | +| center | center | 选择是否将输入信号进行补长。 | +| pad_mode | pad_mode | 当 center 为 True 时,确定 padding 的模式。 | +| normalized | normalized | 是否将傅里叶变换的结果乘以值为 1/sqrt(n) 的缩放系数。 | +| onesided | onesided | 当输入为实信号时,选择是否只返回傅里叶变换结果的一半的频点值。 | +| return_complex | - | 表示当输入为复数时,是否以复数形式返回,还是将实部与虚部分开以实数形式返回。Paddle 目前只支持返回复数,分开返回实部与虚部的情况,需要使用 as_real 进行转写。 | + +### 转写示例 +#### return_complex:是否返回复数 +```python +# Pytorch 写法 +y = torch.rand(512,512).stft(n_fft=512, return_complex=False) + +# Paddle 写法 +y = paddle.as_real(paddle.signal.stft(paddle.rand((512,512)), n_fft=512)) +```