Skip to content

Commit f0d96a4

Browse files
authored
映射文档 No.51 - 60 (#5919)
* Add api_difference docs * Fix
1 parent 3eff257 commit f0d96a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1338
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## [torch 参数更多]torch.Tensor.add
2+
3+
### [torch.Tensor.add](https://pytorch.org/docs/1.13/generated/torch.Tensor.add.html#torch.Tensor.add)
4+
5+
```python
6+
torch.Tensor.add(other, *, alpha=1)
7+
```
8+
9+
### [paddle.Tensor.add](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#add-y-name-none)
10+
11+
```python
12+
paddle.Tensor.add(y, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------- | ------------ | -------------------------------------------------------- |
21+
| other | y | 输入的 Tensor,仅参数名不一致。 |
22+
| alpha | - | 表示 other 的乘数,PaddlePaddle 无此参数,需要进行转写。 |
23+
24+
### 转写示例
25+
26+
#### alpha:other 的乘数
27+
28+
```python
29+
# Pytorch 写法
30+
y = torch.tensor([3, 5]).add(torch.tensor([2, 3]), alpha=2)
31+
32+
# Paddle 写法
33+
y = paddle.to_tensor([3, 5]).add(2 * paddle.to_tensor([2, 3]))
34+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## [torch 参数更多]torch.Tensor.add\_
2+
3+
### [torch.Tensor.add\_](https://pytorch.org/docs/1.13/generated/torch.Tensor.add_.html#torch.Tensor.add_)
4+
5+
```python
6+
torch.Tensor.add_(other, *, alpha=1)
7+
```
8+
9+
### [paddle.Tensor.add\_](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#id3)
10+
11+
```python
12+
paddle.Tensor.add_(y, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------- | ------------ | -------------------------------------------------------- |
21+
| other | y | 输入的 Tensor,仅参数名不一致。 |
22+
| alpha | - | 表示 other 的乘数,PaddlePaddle 无此参数,需要进行转写。 |
23+
24+
### 转写示例
25+
26+
#### alpha:other 的乘数
27+
28+
```python
29+
# Pytorch 写法
30+
torch.tensor([3, 5]).add_(torch.tensor([2, 3]), alpha=2)
31+
32+
# Paddle 写法
33+
paddle.to_tensor([3, 5]).add_(2 * paddle.to_tensor([2, 3]))
34+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## [torch 参数更多]torch.Tensor.exponential\_
2+
3+
### [torch.Tensor.exponential\_](https://pytorch.org/docs/1.13/generated/torch.Tensor.exponential_.html#torch.Tensor.exponential_)
4+
5+
```python
6+
torch.Tensor.exponential_(lambd=1, *, generator=None)
7+
```
8+
9+
### [paddle.Tensor.exponential\_](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#exponential-lam-1-0-name-none)
10+
11+
```python
12+
paddle.Tensor.exponential_(lam=1.0, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| --------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| lambd | lam | 指数分布的 λ 参数,仅参数名不一致。 |
22+
| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## [torch 参数更多]torch.Tensor.half
2+
3+
### [torch.Tensor.half](https://pytorch.org/docs/1.13/generated/torch.Tensor.half.html#torch.Tensor.half)
4+
5+
```python
6+
torch.Tensor.half(memory_format=torch.preserve_format)
7+
```
8+
9+
### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype)
10+
11+
```python
12+
paddle.Tensor.astype('float16')
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------- |
21+
| memory_format | - | 表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
22+
| - | dtype | 转换数据类型,PyTorch 无此参数,Paddle 设置为 paddle.float16。 |
23+
24+
### 转写示例
25+
26+
#### dtype 参数:转换数据类型
27+
28+
```python
29+
# PyTorch 写法:
30+
y = x.half()
31+
32+
# Paddle 写法:
33+
y = x.astype(paddle.float16)
34+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## [torch 参数更多]torch.Tensor.long
2+
3+
### [torch.Tensor.long](https://pytorch.org/docs/1.13/generated/torch.Tensor.long.html#torch.Tensor.long)
4+
5+
```python
6+
torch.Tensor.long(memory_format=torch.preserve_format)
7+
```
8+
9+
### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype)
10+
11+
```python
12+
paddle.Tensor.astype('int64')
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------- |
21+
| memory_format | - | 表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
22+
| - | dtype | 转换数据类型,PyTorch 无此参数,Paddle 设置为 paddle.int64。 |
23+
24+
### 转写示例
25+
26+
#### dtype 参数:转换数据类型
27+
28+
```python
29+
# PyTorch 写法:
30+
y = x.long()
31+
32+
# Paddle 写法:
33+
y = x.astype(paddle.int64)
34+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## [torch 参数更多]torch.Tensor.multinomial
2+
3+
### [torch.Tensor.multinomial](https://pytorch.org/docs/1.13/generated/torch.Tensor.multinomial.html#torch.Tensor.multinomial)
4+
5+
```python
6+
torch.Tensor.multinomial(num_samples, replacement=False, *, generator=None)
7+
```
8+
9+
### [paddle.multinomial](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/multinomial_cn.html)
10+
11+
```python
12+
paddle.multinomial(x, num_samples=1, replacement=False, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ----------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| num_samples | num_samples | 采样的次数。 |
22+
| replacement | replacement | 是否是可放回的采样。 |
23+
| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## [torch 参数更多]torch.Tensor.norm
2+
3+
### [torch.Tensor.norm](https://pytorch.org/docs/1.13/generated/torch.Tensor.norm.html#torch.Tensor.norm)
4+
5+
```python
6+
torch.Tensor.norm(p='fro', dim=None, keepdim=False, dtype=None)
7+
```
8+
9+
### [paddle.Tensor.norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#norm-p-fro-axis-none-keepdim-false-name-none)
10+
11+
```python
12+
paddle.Tensor.norm(p='fro', axis=None, keepdim=False, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------- | ------------ | --------------------------------------------- |
21+
| p | p | 范数(ord)的种类。 |
22+
| dim | axis | 使用范数计算的轴,仅参数名不一致。 |
23+
| keepdim | keepdim | 是否在输出的 Tensor 中保留和输入一样的维度。 |
24+
| dtype | - | 输出数据类型,Paddle 无此参数,需要进行转写。 |
25+
26+
### 转写示例
27+
28+
#### dtype 参数:输出数据类型
29+
30+
```python
31+
# Pytorch 写法
32+
x.norm(dim=-1, dtype=torch.float32)
33+
34+
# Paddle 写法
35+
y = x.astype('float32')
36+
y.norm(dim=-1)
37+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## [torch 参数更多]torch.nn.functional.celu
2+
3+
### [torch.nn.functional.celu](https://pytorch.org/docs/1.13/generated/torch.nn.functional.celu.html#torch.nn.functional.celu)
4+
5+
```python
6+
torch.nn.functional.celu(input, alpha=1.0, inplace=False)
7+
```
8+
9+
### [paddle.nn.functional.celu](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/celu_cn.html)
10+
11+
```python
12+
paddle.nn.functional.celu(x, alpha=1.0, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- |
21+
| input | x | 输入的 Tensor,仅参数名不一致。 |
22+
| alpha | alpha | alpha 参数。 |
23+
| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## [torch 参数更多]torch.nn.functional.cosine_embedding_loss
2+
3+
### [torch.nn.functional.cosine_embedding_loss](https://pytorch.org/docs/1.13/generated/torch.nn.functional.cosine_embedding_loss.html#torch.nn.functional.cosine_embedding_loss)
4+
5+
```python
6+
torch.nn.functional.cosine_embedding_loss(input1, input2, target, margin=0, size_average=None, reduce=None, reduction='mean')
7+
```
8+
9+
### [paddle.nn.functional.cosine_embedding_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/cosine_embedding_loss_cn.html)
10+
11+
```python
12+
paddle.nn.functional.cosine_embedding_loss(input1, input2, label, margin=0, reduction='mean', name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------ | ------------ | ---------------------------------------------- |
21+
| input1 | input1 | 输入的 Tensor。 |
22+
| input2 | input2 | 输入的 Tensor。 |
23+
| target | label | 标签,仅参数名不一致。 |
24+
| margin | margin | 可以设置的范围为[-1, 1]|
25+
| size_average | - | 已废弃,和 reduce 组合决定损失计算方式。 |
26+
| reduce | - | 已废弃,和 size_average 组合决定损失计算方式。 |
27+
| reduction | reduction | 指定应用于输出结果的计算方式。 |
28+
29+
### 转写示例
30+
31+
```python
32+
# Pytorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数
33+
if size_average is None:
34+
size_average = True
35+
if reduce is None:
36+
reduce = True
37+
38+
if size_average and reduce:
39+
reduction = 'mean'
40+
elif reduce:
41+
reduction = 'sum'
42+
else:
43+
reduction = 'none'
44+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## [torch 参数更多]torch.nn.functional.ctc_loss
2+
3+
### [torch.nn.functional.ctc_loss](https://pytorch.org/docs/1.13/generated/torch.nn.functional.ctc_loss.html#torch.nn.functional.ctc_loss)
4+
5+
```python
6+
torch.nn.functional.ctc_loss(log_probs, targets, input_lengths, target_lengths, blank=0, reduction='mean', zero_infinity=False)
7+
```
8+
9+
### [paddle.nn.functional.ctc_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/ctc_loss_cn.html)
10+
11+
```python
12+
paddle.nn.functional.ctc_loss(log_probs, labels, input_lengths, label_lengths, blank=0, reduction='mean')
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| -------------- | ------------- | ------------------------------------------------------------------ |
21+
| log_probs | log_probs | 经过 padding 的概率序列。 |
22+
| targets | labels | 经过 padding 的标签序列,仅参数名不一致。 |
23+
| input_lengths | input_lengths | 表示输入 log_probs 数据中每个序列的长度。 |
24+
| target_lengths | label_lengths | 表示 label 中每个序列的长度,仅参数名不一致。 |
25+
| blank | blank | 空格标记的 ID 值。 |
26+
| reduction | reduction | 指定应用于输出结果的计算方式。 |
27+
| zero_infinity | - | 是否设置 infinity 及关联梯度 为 0,Paddle 无此参数,暂无转写方式。 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## [torch 参数更多]torch.nn.functional.elu
2+
3+
### [torch.nn.functional.elu](https://pytorch.org/docs/1.13/generated/torch.nn.functional.elu.html#torch.nn.functional.elu)
4+
5+
```python
6+
torch.nn.functional.elu(input, alpha=1.0, inplace=False)
7+
```
8+
9+
### [paddle.nn.functional.elu](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/elu_cn.html)
10+
11+
```python
12+
paddle.nn.functional.elu(x, alpha=1.0, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- |
21+
| input | x | 输入的 Tensor,仅参数名不一致。 |
22+
| alpha | alpha | alpha 参数。 |
23+
| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## [torch 参数更多]torch.nn.functional.gumbel_softmax
2+
3+
### [torch.nn.functional.gumbel_softmax](https://pytorch.org/docs/1.13/generated/torch.nn.functional.gumbel_softmax.html#torch.nn.functional.gumbel_softmax)
4+
5+
```python
6+
torch.nn.functional.gumbel_softmax(logits, tau=1, hard=False, eps=1e-10, dim=- 1)
7+
```
8+
9+
### [paddle.nn.functional.gumbel_softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/gumbel_softmax_cn.html)
10+
11+
```python
12+
paddle.nn.functional.gumbel_softmax(x, temperature=1.0, hard=False, axis=- 1, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------- | ------------ | ------------------------------------------------------------------------------------------------- |
21+
| logits | x | 一个 N-D Tensor,前 N-1 维用于独立分布 batch 的索引,最后一维表示每个类别的概率,仅参数名不一致。 |
22+
| tau | temperature | 大于 0 的标量,仅参数名不一致。 |
23+
| hard | hard | 如果是 True,返回离散的 one-hot 向量。如果是 False,返回软样本。 |
24+
| eps | - | eps 参数,Paddle 无此参数,暂无转写方式。 |
25+
| dim | axis | 按照维度 axis 计算 softmax,仅参数名不一致。 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## [torch 参数更多]torch.nn.functional.hardswish
2+
3+
### [torch.nn.functional.hardswish](https://pytorch.org/docs/1.13/generated/torch.nn.functional.hardswish.html#torch.nn.functional.hardswish)
4+
5+
```python
6+
torch.nn.functional.hardswish(input, inplace=False)
7+
```
8+
9+
### [paddle.nn.functional.hardswish](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/hardswish_cn.html)
10+
11+
```python
12+
paddle.nn.functional.hardswish(x, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- |
21+
| input | x | 输入的 Tensor,仅参数名不一致。 |
22+
| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |

0 commit comments

Comments
 (0)