Skip to content

Commit 3eb0013

Browse files
authored
映射文档更新 (#7322)
* update docs * update docs * update docs
1 parent 7f98642 commit 3eb0013

13 files changed

+223
-73
lines changed
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
## [ 组合替代实现 ]torch.Tensor.baddbmm
1+
## [ 仅参数名不一致 ]torch.Tensor.baddbmm
22

33
### [torch.Tensor.baddbmm](https://pytorch.org/docs/stable/generated/torch.Tensor.baddbmm.html#torch.Tensor.baddbmm)
44

55
```python
6-
torch.Tensor.baddbmm(batch1, batch2, beta=1, alpha=1)
6+
torch.Tensor.baddbmm(batch1, batch2, *, beta=1, alpha=1)
77
```
8-
Paddle 无此 API,需要组合实现。
98

10-
### 转写示例
9+
### [paddle.Tensor.baddbmm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tensor)
1110

1211
```python
13-
# PyTorch 写法
14-
y = input.baddbmm(batch1, batch2, beta=beta, alpha=alpha)
15-
16-
# Paddle 写法
17-
y = beta * input + alpha * paddle.bmm(batch1, batch2)
12+
paddle.Tensor.baddbmm(x, y, beta=1, alpha=1, name=None)
1813
```
14+
15+
两者功能一致,仅参数名不一致,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------- | ------------ | ------------------------------------------------------------------------------------------ |
21+
| batch1 | x | 表示输入的第一个 Tensor ,仅参数名不一致。 |
22+
| batch2 | y | 表示输入的第二个 Tensor ,仅参数名不一致。 |
23+
| beta | beta | 表示乘以 input 的标量。 |
24+
| alpha | alpha | 表示乘以 batch1 * batch2 的标量。 |
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
## [ 组合替代实现 ]torch.Tensor.baddbmm_
1+
## [ 仅参数名不一致 ]torch.Tensor.baddbmm_
22

33
### [torch.Tensor.baddbmm_](https://pytorch.org/docs/stable/generated/torch.Tensor.baddbmm_.html#torch.Tensor.baddbmm_)
44

55
```python
6-
torch.Tensor.baddbmm_(batch1, batch2, beta=1, alpha=1)
6+
torch.Tensor.baddbmm_(batch1, batch2, *, beta=1, alpha=1)
77
```
8-
Paddle 无此 API,需要组合实现。
98

10-
### 转写示例
9+
### [paddle.Tensor.baddbmm_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tensor)
1110

1211
```python
13-
# PyTorch 写法
14-
input.baddbmm_(batch1, batch2, beta=beta, alpha=alpha)
15-
16-
# Paddle 写法
17-
input.multiply_(paddle.to_tensor(beta, dtype=input.dtype)).add_(alpha * paddle.bmm(batch1, batch2))
12+
paddle.Tensor.baddbmm_(x, y, beta=1, alpha=1, name=None)
1813
```
14+
15+
两者功能一致,仅参数名不一致,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------- | ------------ | ------------------------------------------------------------------------------------------ |
21+
| batch1 | x | 表示输入的第一个 Tensor ,仅参数名不一致。 |
22+
| batch2 | y | 表示输入的第二个 Tensor ,仅参数名不一致。 |
23+
| beta | beta | 表示乘以 input 的标量。 |
24+
| alpha | alpha | 表示乘以 batch1 * batch2 的标量。 |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## [ paddle 参数更多 ]torch.Tensor.lu_solve
2+
3+
### [torch.Tensor.lu_solve](https://pytorch.org/docs/stable/generated/torch.Tensor.lu_solve.html#torch-tensor-lu-solve)
4+
5+
```python
6+
torch.Tensor.lu_solve(LU_data, LU_pivots)
7+
```
8+
9+
### [paddle.linalg.lu_solve](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/lu_solve_cn.html)
10+
11+
```python
12+
paddle.linalg.lu_solve(b, lu, pivots, trans="N", name=None)
13+
```
14+
15+
Pytorch 为 Tensor 类方法,Paddle 为普通函数,另外 Paddle 相比 PyTorch 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ------------------------------------------------------ |
21+
| self | b | 表示欲进行线性方程组求解的右值 Tensor ,调用 torch.Tensor 类方法的 self Tensor 传入。 |
22+
| LU_data | lu | 表示 LU 分解结果矩阵,由 L、U 拼接组成,仅参数名不一致。 |
23+
| LU_pivots | pivots | 表示 LU 分解结果的主元信息 Tensor ,仅参数名不一致。 |
24+
| - | trans | 是否对 A 进行转置 ,PyTorch 无此参数,Paddle 保持默认即可。 |
Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
## [组合替代实现]torch.Tensor.positive
1+
## [ 无参数 ]torch.Tensor.positive
22

33
### [torch.Tensor.positive](https://pytorch.org/docs/stable/generated/torch.Tensor.positive.html#torch.Tensor.positive)
44

55
```python
66
torch.Tensor.positive()
77
```
88

9-
判断 `input` 是否是 bool 类型的 Tensor,如果是则抛出 RuntimeError 异常,否则返回 `input`
10-
11-
Paddle 无此 API,需要组合实现。
12-
13-
### 转写示例
9+
### [paddle.positive](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/positive_cn.html#positive)
1410

1511
```python
16-
# PyTorch 写法
17-
x.positive()
18-
19-
# Paddle 写法
20-
def positive(x):
21-
if x.dtype != paddle.bool:
22-
return x
23-
else:
24-
raise RuntimeError("boolean tensors is not supported.")
25-
26-
positive(x)
12+
paddle.positive(x)
2713
```
14+
15+
Pytorch 为 Tensor 类方法,Paddle 为普通函数,将调用 torch.Tensor 类方法的 self Tensor 传入到 Paddle 接口中即可。
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## [ 组合替代实现 ]torch.optim.lr_scheduler.LRScheduler
2+
3+
### [torch.optim.lr_scheduler.LRScheduler](https://docs.pytorch.org/docs/2.7/generated/torch.optim.lr_scheduler.LRScheduler.html#torch.optim.lr_scheduler.LRScheduler)
4+
5+
```python
6+
torch.optim.lr_scheduler.LRScheduler(optimizer,
7+
last_epoch=-1)
8+
```
9+
10+
### [paddle.optimizer.lr.LRScheduler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/LRScheduler_cn.html#lrscheduler)
11+
12+
```python
13+
paddle.optimizer.lr.LRScheduler(learning_rate=0.1,
14+
last_epoch=-1,
15+
verbose=False)
16+
```
17+
18+
两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下:
19+
20+
### 参数映射
21+
22+
| PyTorch | PaddlePaddle | 备注 |
23+
| ------- | ------------ | ------------------------------------------------------------------------------------------ |
24+
| optimizer | learning_rate | PyTorch 的 optimizer 类型是 torch.optim.Optimizer,Paddle 的 learning_rate 类型是 float,两者功能上不直接一致,但可通过设置 leaning_rate = optimizer.get_lr() 来对应一致。 |
25+
| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。参数完全一致。 |
26+
| - | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。|
27+
28+
### 转写示例
29+
30+
```python
31+
# PyTorch 写法
32+
linear = torch.nn.Linear(10, 10)
33+
class CustomScheduler(torch.optim.lr_scheduler.LRScheduler):
34+
def __init__(
35+
self, optimizer: Optimizer, last_epoch=-1, verbose="deprecated"
36+
):
37+
...
38+
sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters())
39+
scheduler = CustomScheduler(optimizer=sgd, lr_lambda=lambda x:0.95**x)
40+
41+
# Paddle 写法
42+
linear = paddle.nn.linear(10, 10)
43+
class CustomScheduler(paddle.optimizer.lr.LRScheduler):
44+
def __init__(
45+
self,
46+
learning_rate: float = 0.1,
47+
last_epoch: int = -1,
48+
verbose: bool = False,
49+
) -> None:
50+
...
51+
sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters())
52+
scheduler = CustomScheduler(learning_rate=sgd.get_lr(), lr_lambda=lambda x:0.95**x)
53+
sgd.set_lr_scheduler(scheduler)
54+
```

docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.gammaln.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
torch.special.gammaln(input, *, out=None)
77
```
88

9-
### [paddle.lgamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/lgamma_cn.html#lgamma)
9+
### [paddle.gammaln](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/gammaln_cn.html#gammaln)
1010

1111
```python
12-
paddle.lgamma(x, name=None)
12+
paddle.gammaln(x, name=None)
1313
```
1414

1515
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## [组合替代实现]torch.\_foreach_lgamma
2+
3+
### [torch.\_foreach_lgamma](https://pytorch.org/docs/stable/generated/torch._foreach_lgamma.html#torch-foreach-lgamma)
4+
5+
```python
6+
torch._foreach_lgamma(self)
7+
```
8+
9+
Paddle 无此 API,需要组合实现。
10+
11+
### 转写示例
12+
13+
```python
14+
# PyTorch 写法
15+
torch._foreach_lgamma(tensors)
16+
17+
# Paddle 写法
18+
[paddle.lgamma(x) for x in tensors]
19+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## [组合替代实现]torch.\_foreach_lgamma_
2+
3+
### [torch.\_foreach_lgamma_](https://pytorch.org/docs/stable/generated/torch._foreach_lgamma_.html#torch-foreach-lgamma)
4+
5+
```python
6+
torch._foreach_lgamma_(self)
7+
```
8+
9+
Paddle 无此 API,需要组合实现。
10+
11+
### 转写示例
12+
13+
```python
14+
# PyTorch 写法
15+
torch._foreach_lgamma_(tensors)
16+
17+
# Paddle 写法
18+
[paddle.lgamma_(x) for x in tensors]
19+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## [组合替代实现]torch.\_foreach_sqrt
2+
3+
### [torch.\_foreach_sqrt](https://pytorch.org/docs/stable/generated/torch._foreach_sqrt.html#torch-foreach-sqrt)
4+
5+
```python
6+
torch._foreach_sqrt(self)
7+
```
8+
9+
Paddle 无此 API,需要组合实现。
10+
11+
### 转写示例
12+
13+
```python
14+
# PyTorch 写法
15+
torch._foreach_sqrt(tensors)
16+
17+
# Paddle 写法
18+
[paddle.sqrt(x) for x in tensors]
19+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## [组合替代实现]torch.\_foreach_sqrt_
2+
3+
### [torch.\_foreach_sqrt_](https://docs.pytorch.org/docs/stable/generated/torch._foreach_sqrt_.html#torch-foreach-sqrt)
4+
5+
```python
6+
torch._foreach_sqrt_(self)
7+
```
8+
9+
Paddle 无此 API,需要组合实现。
10+
11+
### 转写示例
12+
13+
```python
14+
# PyTorch 写法
15+
torch._foreach_sqrt_(tensors)
16+
17+
# Paddle 写法
18+
[paddle.assign(paddle.sqrt(x), x) for x in tensors]
19+
```

0 commit comments

Comments
 (0)