Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【映射文档】新增与维护部分映射文档 part2 #6500

Merged
merged 6 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ paddle.Tensor.argmax(axis=None, keepdim=False, dtype=int64, name=None)
| ------- | ------------ | ------------------ |
| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 |
| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 |
| - | dtype | 指定返回类型,PyTorch 无此参数,Paddle 保持默认即可。 |
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ torch.Tensor.nanmedian(dim=None, keepdim=False)
### [paddle.Tensor.nanmedian](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#nanmedian-axis-none-keepdim-true-name-none)

```python
paddle.Tensor.nanmedian(axis=None, keepdim=True, name=None)
paddle.Tensor.nanmedian(axis=None, keepdim=False, name=None)
```

其中 PyTorch 和 Paddle 功能一致,仅参数默认值不一致,具体如下:
Expand All @@ -19,4 +19,4 @@ paddle.Tensor.nanmedian(axis=None, keepdim=True, name=None)
| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | -- |
| dim | axis | 指定对 x 进行计算的轴,仅参数名不一致。 |
| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度,PyTorch 默认值为 False,Paddle 默认值为 True。Paddle 需设置为与 PyTorch 一致。 |
| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## [ 参数完全一致 ]torch.distributions.Distribution.log_prob

### [torch.distributions.Distribution.log\_prob](https://pytorch.org/docs/stable/distributions.html#torch.distributions.distribution.Distribution.log_prob)

```python
torch.distributions.Distribution.log_prob(value)
```

### [paddle.distributions.Distribution.log\_prob](https://pytorch.org/docs/stable/distributions.html#torch.distributions.distribution.Distribution.log_prob)

```python
paddle.distributions.Distribution.log_prob(value)
```


功能一致,参数完全一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ------------ |
| value | value | 输入 Tensor。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [ 仅参数名不一致 ]torch.distributions.Distribution.rsample

### [torch.distributions.Distribution.rsample](https://pytorch.org/docs/stable/distributions.html#torch.distributions.distribution.Distribution.rsample)

```python
torch.distributions.Distribution.rsample(sample_shape=torch.Size([]))
```

### [paddle.distribution.Distribution.rsample](https://github.com/PaddlePaddle/Paddle/blob/2bbd6f84c1db3e7401732869ee50aef2d9c97bdc/python/paddle/distribution/distribution.py#L96)

```python
paddle.distribution.Distribution.rsample(shape=())
```

其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------ | ------------ | ---- |
| sample_shape | shape | 重参数化的样本形状,仅参数名不同。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [ 仅参数名不一致 ]torch.distributions.Distribution.sample

### [torch.distributions.Distribution.sample](https://pytorch.org/docs/stable/distributions.html#torch.distributions.distribution.Distribution.sample)

```python
torch.distributions.Distribution.sample(sample_shape=torch.Size([]))
```

### [paddle.distribution.Distribution.sample](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Distribution_cn.html#sample)

```python
paddle.distribution.Distribution.sample(shape=())
```

其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------ | ------------ | -- |
| sample_shape | shape | 采样形状,仅参数名不一致。 |
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
torch.distributions.log_normal.LogNormal(loc, scale, validate_args=None)
```

### [paddle.distribution.Normal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Normal_cn.html#normal)
### [paddle.distribution.LogNormal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/LogNormal_cn.html#lognormal)

```python
paddle.distribution.Normal(loc, scale, name=None)
paddle.distribution.LogNormal(loc, scale, name=None)
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [ torch 参数更多 ]torch.distributions.transforms.AbsTransform

### [torch.distributions.transforms.AbsTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.AbsTransform)

```python
torch.distributions.transforms.AbsTransform(cache_size=0)
```

### [paddle.distribution.AbsTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/AbsTransform_cn.html#paddle.distribution.AbsTransform)

```python
paddle.distribution.AbsTransform()
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ---------- | ------------ | -- |
| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## [ torch 参数更多 ]torch.distributions.transforms.AffineTransform

### [torch.distributions.transforms.AffineTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.AffineTransform)

```python
torch.distributions.transforms.AffineTransform(loc, scale, event_dim=0, cache_size=0)
```

### [paddle.distribution.AffineTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/AffineTransform_cn.html#affinetransform)

```python
paddle.distribution.AffineTransform(loc, scale)
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ---------- | ------------ | -- |
| loc | loc | 偏置参数。 |
| scale | scale | 缩放参数。 |
| event_dim | - | event_shape 可选尺寸。对于单随机变量为 0,对于向量分布为 1,对于矩阵分布为 2。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个可直接删除吗,没有影响吗

Copy link
Contributor Author

@RedContritio RedContritio Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paddle 没有描述具体实现,可能需要实验来测试。
认为没有影响是因为参考 PaConvert/#341,对该参数做了直接删除处理。
此外 tests/test_distributions_AffineTransform.py 未覆盖 0、1、2 取值。

| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [ torch 参数更多 ]torch.distributions.transforms.ExpTransform

### [torch.distributions.transforms.ExpTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.ExpTransform)

```python
torch.distributions.transforms.ExpTransform(cache_size=0)
```

### [paddle.distribution.ExpTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/ExpTransform_cn.html#exptransform)

```python
paddle.distribution.ExpTransform()
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ---------- | ------------ | -- |
| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## [torch 参数更多]torch.distributions.transforms.IndependentTransform
## [ torch 参数更多 ]torch.distributions.transforms.IndependentTransform

### [torch.distributions.transforms.IndependentTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.IndependentTransform)

```python
torch.distributions.transforms.IndependentTransform(base_transform, reinterpreted_batch_ndims, cache_size=0)
```

### [paddle.distribution.IndependentTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/IndependentTransform_cn.html)
### [paddle.distribution.IndependentTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/IndependentTransform_cn.html#independenttransform)

```python
paddle.distribution.IndependentTransform(base, reinterpreted_batch_rank)
Expand All @@ -16,8 +16,8 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------------------- | ------------------------ | ---------------------------------------------------- |
| base_transform | base | 基础变换,仅参数名不一致。 |
| reinterpreted_batch_ndims | reinterpreted_batch_rank | 被扩展为事件维度的最右侧批维度数量,仅参数名不一致。 |
| cache_size | - | cache 大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| PyTorch | PaddlePaddle | 备注 |
| ------------------------- | ------------------------ | ------------------------ |
| base_transform | base | 基础变换,仅参数名不一致。 |
| reinterpreted_batch_ndims | reinterpreted_batch_rank | 被扩展为事件维度的最右侧批维度数量,需大于 0,仅参数名不一致。 |
| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## [ torch 参数更多 ]torch.distributions.transforms.PowerTransform

### [torch.distributions.transforms.PowerTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.SigmoidTransform)

```python
torch.distributions.transforms.PowerTransform(exponent, cache_size=0)
```

### [paddle.distribution.PowerTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/PowerTransform_cn.html#powertransform)

```python
paddle.distribution.PowerTransform(power)
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ---------- | ------------ | -- |
| exponent | power | 幂参数。 |
| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [ torch 参数更多 ]torch.distributions.transforms.SigmoidTransform

### [torch.distributions.transforms.SigmoidTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.SigmoidTransform)

```python
torch.distributions.transforms.SigmoidTransform(cache_size=0)
```

### [paddle.distribution.SigmoidTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/SigmoidTransform_cn.html#sigmoidtransform)

```python
paddle.distribution.SigmoidTransform()
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ---------- | ------------ | -- |
| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [ torch 参数更多 ]torch.distributions.transforms.TanhTransform

### [torch.distributions.transforms.TanhTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.TanhTransform)

```python
torch.distributions.transforms.TanhTransform(cache_size=0)
```

### [paddle.distribution.TanhTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/TanhTransform_cn.html#tanhtransform)

```python
paddle.distribution.TanhTransform()
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ---------- | ------------ | -- |
| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
## [ torch 参数更多 ]torch.fft.irfft
## [ torch 参数更多 ]torch.fft.rfft2

### [torch.fft.irfft](https://pytorch.org/docs/stable/generated/torch.fft.irfft.html#torch-fft-irfft)
### [torch.fft.rfft2](https://pytorch.org/docs/stable/generated/torch.fft.rfft2.html)

```python
torch.fft.irfft(input, s=None, dim=(- 2, - 1), norm='backward', *, out=None)
torch.fft.rfft2(input, s=None, dim=(-2, -1), norm=None, *, out=None)
```

### [paddle.fft.irfft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/irfft_cn.html#irfft)
### [paddle.fft.rfft2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/rfft2_cn.html#rfft2)

```python
paddle.fft.irfft(x, s=None, axes=(- 2, - 1), norm='backward', name=None)
paddle.fft.rfft2(x, s=None, axes=(- 2, - 1), norm='backward', name=None)
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ----------------------------------- | ------------ | ----------------------------------------------------------------------- |
| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ----- |
| input | x | 表示输入的 Tensor ,仅参数名不一致。 |
| n | n | 表示在傅里叶变换轴的长度 。 |
| s | s | 表示在傅里叶变换轴的长度 。 |
| dim | axis | 表示进行运算的轴,仅参数名不一致。 |
| norm | norm | 表示傅里叶变换的缩放模式。 |
| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 |
| norm | norm | 表示傅里叶变换的缩放模式。 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torch的None和 paddle的'backward' 是相同效果的吗

Copy link
Contributor Author

@RedContritio RedContritio Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 torch 会在该参数未指定或传入 None 的时候,内部使用默认值 "backward" (不依赖 python 语法的手动默认值设置)。

效果一致。

| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 |

### 转写示例
#### out:指定输出
```python
# PyTorch 写法
torch.fft.irfft(x, s, dim, norm, out=y)
torch.fft.rfft2(x, s, dim, norm, out=y)

# Paddle 写法
paddle.assign(paddle.fft.irfft(x, s, dim, norm) , y)
paddle.assign(paddle.fft.rfft2(x, s, dim, norm), y)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## [ 无参数 ]torch.backends.cudnn.version

### [torch.backends.cudnn.version](https://pytorch.org/docs/stable/generated/torch.backends.cudnn.version.html)

```python
torch.backends.cudnn.version()
```

### [paddle.device.get\_cudnn\_version](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/get_cudnn_version_cn.html#get-cudnn-version)

```python
paddle.device.get_cudnn_version()
```

两者功能一致,无参数。
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## [ 仅参数名不一致 ]torch.celu

### [torch.celu](https://pytorch.org/docs/stable/generated/torch.nn.functional.celu.html#torch.nn.functional.celu)

```python
torch.celu(input, alpha=1.0)
```

### [paddle.nn.functional.celu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/celu_cn.html#celu)

```python
paddle.nn.functional.celu(x, alpha=1.0, name=None)
```

其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | -- |
| input | x | 输入的 Tensor,仅参数名不一致。 |
| alpha | alpha | CELU 的 alpha 值,默认值为 1.0。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## [ torch 参数更多 ]torch.complex


### [torch.complex](https://pytorch.org/docs/stable/generated/torch.complex.html)

```python
torch.complex(real, imag, *, out=None)
```

### [paddle.complex](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/complex_cn.html#complex)

```python
paddle.complex(real, imag, name=None)
```

其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | -- |
| real | real | 实部,数据类型为:float32 或 float64。 |
| imag | imag | 虚部,数据类型和 real 相同。 |
| out | - | 输出 Tensor。 |

### 转写示例

```python
# PyTorch 写法
torch.complex(a, b, out=out)

# Paddle 写法
paddle.assign(paddle.complex(a, b), out)
```
Loading