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

映射文档 No. 49 #5849

Merged
merged 6 commits into from
May 12, 2023
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
@@ -1,5 +1,5 @@
## [torch 参数更多 ]torch.mm
### [torch.mm](https://pytorch.org/docs/stable/generated/torch.mm.html?highlight=mm#torch.mm)
### [torch.mm](https://pytorch.org/docs/1.13/generated/torch.mm.html?highlight=torch+mm#torch.mm)

```python
torch.mm(input,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## [ torch 参数更多 ]torch.mv
### [torch.mv](https://pytorch.org/docs/stable/generated/torch.mv.html?highlight=mv#torch.mv)
### [torch.mv](https://pytorch.org/docs/1.13/generated/torch.mv.html?highlight=torch+mv#torch.mv)
```python
torch.mv(input, vec, out=None)
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## [ torch 参数更多 ] torch.qr

### [torch.qr](https://pytorch.org/docs/1.13/generated/torch.qr.html#torch.qr)

```python
torch.qr(input, some=True, *, out=None)
```

### [paddle.linalg.qr](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/qr_cn.html#qr)

```python
paddle.linalg.qr(x, mode='reduced', name=None)
```

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

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 表示输入 Tensor,仅参数名不一致。 |
| some | mode | 表示 QR 分解的行为。 需进行转写。 |
| out | - | 表示输出的 Tensor 元组。 Paddle 无此参数,需要进行转写。 |

### 转写示例
### some:控制 QR 分解的行为
```python
# 当进行完整的 QR 分解时
# Pytorch 写法
q, r = torch.qr(x, some=False)
Copy link
Collaborator

Choose a reason for hiding this comment

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

some=True时怎么转写,也需要加上

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已添加


# Paddle 写法
q, r = paddle.linalg.qr(x, mode='complete')

#当进行减少的 QR 分解时
# Pytorch 写法
q, r = torch.qr(x, some=True)

# Paddle 写法
q, r = paddle.linalg.qr(x, mode='reduced')
```

#### out:指定输出
```python
# Pytorch 写法
torch.qr(x, out = (q, r) )

# Paddle 写法
q, r = paddle.linalg.qr(x)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## [ torch 参数更多 ] torch.svd

### [torch.svd](https://pytorch.org/docs/1.13/generated/torch.svd.html?highlight=torch+svd#torch.svd)

```python
torch.svd(input, some=True, compute_uv=True, *, out=None)
```

### [paddle.linalg.svd](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/svd_cn.html#svd)

```python
paddle.linalg.svd(x, full_matrics=False, name=None)
```

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

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入 Tensor ,仅参数名不一致。 |
| some | full_matrics | 表示需计算的奇异值数目。 与 Pytorch 默认值不同,需要转写。 |
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

Choose a reason for hiding this comment

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

torch.svd中的some参数默认值为True,paddle.linalg.svd中的full_matrics参数默认值为False,他们的默认值所导致的函数功能是一样的,都是计算完整的 U 和 V 矩阵,所以这样的情况我加了转写示例

| compute_uv | - | 表示是否计算 U 和 V 。 Paddle 暂无转写方式。 |
| out | - | 表示输出的 Tensor 元组。 Paddle 无此参数,需要进行转写。 |

### 转写示例
#### some:表示需计算的奇异值数目
```python
# Pytorch 写法
u, s, v = torch.svd(x, some = True )

# Paddle 写法
u, s, v = paddle.linalg.svd(x, full_matrics = False)
```
#### out:指定输出
```python
# Pytorch 写法
torch.svd(x, out=(u, s, v) )

# Paddle 写法
u, s, v = paddle.linalg.svd(x)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## [ torch 参数更多 ] torch.svd_lowrank

### [torch.svd_lowrank](https://pytorch.org/docs/1.13/generated/torch.svd_lowrank.html?highlight=torch+svd_lowrank#torch.svd_lowrank)

```python
torch.svd_lowrank(A, q=6, niter=2, M=None)
```

### [paddle.linalg.svd](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/svd_cn.html#svd)

```python
paddle.linalg.svd(x, full_matrics=False, name=None)
```

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

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| A | x | 表示输入 Tensor,仅参数名不一致。 |
| q | - | 表示输入 Tensor 略高估计秩。 Paddle 暂无转写方式。 |
| niter | - | 表示子空间进行迭代的数量。 Paddle 暂无转写方式。 |
| M | - | 表示输入 Tensor 的平均 size。 Paddle 暂无转写方式。 |
| - | full_matrics | 表示是否计算完整的 U 和 V 矩阵。 PyTorch 无此参数,Paddle 保持默认即可。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## [ torch 参数更多 ] torch.symeig

### [torch.symeig](https://pytorch.org/docs/1.13/generated/torch.symeig.html?highlight=torch+symeig#torch.symeig)

```python
torch.symeig(input, eigenvectors=False, upper=True, *, out=None)
```

### [paddle.linalg.eigh](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/eigh_cn.html#eigh)

```python
paddle.linalg.eigh(x, UPLO='L', name=None)
```

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

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的对称 Tensor,仅参数名不一致。 |
| eigenvectors | - | 表示是否计算特征向量。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

@whyn0tdance whyn0tdance May 10, 2023

Choose a reason for hiding this comment

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

pytorch中的eigenvectors参数表示是同时计算特征向量和特征值还是只计算特征值,paddle.linalg.eigh函数中没有这个功能对应,无法组合转写。
torch.symeig这个函数其实可以由torch.linalg.eigh所替代,且在官方文档中建议使用torch.linalg.eigh(),并表示在后续版本中移除torch.symeig

| upper | UPLO | 表示计算上三角或者下三角矩阵。 需进行转写。 |
| out | - | 表示输出的 Tensor 元组, Paddle 无此参数,需要进行转写。 |

### 转写示例
#### upper:表示计算上三角或者下三角矩阵
```python
# Pytorch 写法
e, v = torch.symeig(x, upper = False)

# Paddle 写法
e, v = paddle.linalg.eigh(x, UPLO = 'L')
```

#### out:指定输出
```python
# Pytorch 写法
torch.symeig(x, out=(e, v) )

# Paddle 写法
e, v = paddle.linalg.eigh(x)
```