Skip to content

Commit 4da15bc

Browse files
authored
映射文档 No. 59 (#5857)
* 映射文档 No. 59 * 映射文档 No. 59 * 映射文档 No. 59
1 parent b6c3f51 commit 4da15bc

File tree

10 files changed

+294
-2
lines changed

10 files changed

+294
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## [ torch 参数更多 ] torch.Tensor.bernoulli
2+
3+
### [torch.Tensor.bernoulli](https://pytorch.org/docs/1.13/generated/torch.Tensor.bernoulli.html#torch.Tensor.bernoulli)
4+
5+
```python
6+
torch.Tensor.bernoulli(*, generator=None)
7+
```
8+
9+
### [paddle.bernoulli](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bernoulli_cn.html#bernoulli)
10+
11+
```python
12+
paddle.bernoulli(x, name=None)
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| generator | - | 用于采样的伪随机数生成器, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
22+
23+
### 转写示例
24+
25+
```python
26+
# torch 写法
27+
x = torch.tensor([0.2, 0.6, 0.8])
28+
y = x.bernoulli()
29+
30+
# paddle 写法
31+
x = paddle.to_tensor([0.2, 0.6, 0.8])
32+
y = paddle.bernoulli(x)
33+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## [ torch 参数更多 ] torch.Tensor.bfloat16
2+
3+
### [torch.Tensor.bfloat16](https://pytorch.org/docs/1.13/generated/torch.Tensor.bfloat16.html#torch.Tensor.bfloat16)
4+
5+
```python
6+
torch.Tensor.bfloat16(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('bfloat16')
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
22+
23+
### 转写示例
24+
25+
```python
26+
# torch 写法
27+
x = torch.randn(3, 3)
28+
y = x.bfloat16()
29+
30+
# paddle 写法
31+
x = paddle.randn([3, 3])
32+
y = x.astype('bfloat16')
33+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## [ torch 参数更多 ] torch.Tensor.bool
2+
3+
### [torch.Tensor.bool](https://pytorch.org/docs/1.13/generated/torch.Tensor.bool.html#torch.Tensor.bool)
4+
5+
```python
6+
torch.Tensor.bool(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('bool')
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
22+
23+
### 转写示例
24+
25+
```python
26+
# torch 写法
27+
x = torch.tensor([-1, 0, 1])
28+
y = x.bool()
29+
30+
# paddle 写法
31+
x = paddle.to_tensor([-1, 0, 1])
32+
y = x.astype('bool')
33+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## [ torch 参数更多 ] torch.Tensor.byte
2+
3+
### [torch.Tensor.byte](https://pytorch.org/docs/1.13/generated/torch.Tensor.byte.html#torch.Tensor.byte)
4+
5+
```python
6+
torch.Tensor.byte(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('uint8')
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
22+
23+
### 转写示例
24+
25+
```python
26+
# torch 写法
27+
x = torch.tensor([0, 1, 2, 3])
28+
y = x.byte()
29+
30+
# paddle 写法
31+
x = paddle.to_tensor([0, 1, 2, 3])
32+
y = x.astype('uint8')
33+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## [ torch 参数更多 ] torch.Tensor.char
2+
3+
### [torch.Tensor.char](https://pytorch.org/docs/1.13/generated/torch.Tensor.char.html#torch.Tensor.char)
4+
5+
```python
6+
torch.Tensor.char(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('int8')
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
22+
23+
### 转写示例
24+
25+
```python
26+
# torch 写法
27+
x.char()
28+
29+
# paddle 写法
30+
x.astype('int8')
31+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## [ torch 参数更多 ] torch.Tensor.clone
2+
3+
### [torch.Tensor.clone](https://pytorch.org/docs/1.13/generated/torch.Tensor.clone.html#torch.Tensor.clone)
4+
5+
```python
6+
torch.Tensor.clone(*, memory_format=torch.preserve_format)
7+
```
8+
9+
### [paddle.Tensor.clone](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#clone)
10+
11+
```python
12+
paddle.Tensor.clone()
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |

docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.copy_.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## torch.Tensor.copy_
2-
### [torch.Tensor.copy_](https://pytorch.org/docs/stable/generated/torch.Tensor.copy_.html?highlight=copy_#torch.Tensor.copy_)
1+
## [ torch 参数更多 ] torch.Tensor.copy_
2+
3+
### [torch.Tensor.copy_](https://pytorch.org/docs/1.13/generated/torch.Tensor.copy_.html#torch.Tensor.copy_)
34

45
```python
56
torch.Tensor.copy_(src, non_blocking=False)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## [ torch 参数更多 ] torch.Tensor.div
2+
3+
### [torch.Tensor.div](https://pytorch.org/docs/1.13/generated/torch.Tensor.div.html#torch.Tensor.div)
4+
5+
```python
6+
torch.Tensor.div(other, *, rounding_mode=None)
7+
```
8+
9+
### [paddle.Tensor.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#divide-y-name-none)
10+
11+
```python
12+
paddle.Tensor.divide(y, name=None)
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| other | y | 表示输入的 Tensor ,仅参数名不一致。 |
22+
| rounding_mode | - | 用于指定在执行截断除法时的舍入模式,可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要进行转写。 |
23+
24+
### 转写示例
25+
26+
```python
27+
# torch 写法
28+
x = torch.tensor([4, 8, 12], dtype=torch.float32)
29+
y = torch.tensor([3, 4, 5], dtype=torch.float32)
30+
z1 = x.div(y, rounding_mode='floor') # 向下取整
31+
z2 = x.div(y, rounding_mode='trunc') # 向零取整
32+
33+
# paddle 写法
34+
x = paddle.to_tensor([4, 8, 12], dtype='float32')
35+
y = paddle.to_tensor([3, 4, 5], dtype='float32')
36+
z1 = x.divide(y).floor() # 向下取整
37+
z2 = x.divide(y).trunc() # 向零取整
38+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## [ torch 参数更多 ] torch.Tensor.divide
2+
3+
### [torch.Tensor.divide](https://pytorch.org/docs/1.13/generated/torch.Tensor.divide.html#torch.Tensor.divide)
4+
5+
```python
6+
torch.Tensor.divide(other, *, rounding_mode=None)
7+
```
8+
9+
### [paddle.Tensor.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#divide-y-name-none)
10+
11+
```python
12+
paddle.Tensor.divide(y, name=None)
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| other | y | 表示输入的 Tensor ,仅参数名不一致。 |
22+
| rounding_mode | - | 用于指定在执行截断除法时的舍入模式。可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要进行转写。 |
23+
24+
### 转写示例
25+
26+
```python
27+
# torch 写法
28+
x = torch.tensor([4, 8, 12], dtype=torch.float32)
29+
y = torch.tensor([3, 4, 5], dtype=torch.float32)
30+
z1 = x.divide(y, rounding_mode='floor') # 向下取整
31+
z2 = x.divide(y, rounding_mode='trunc') # 向零取整
32+
33+
# paddle 写法
34+
x = paddle.to_tensor([4, 8, 12], dtype='float32')
35+
y = paddle.to_tensor([3, 4, 5], dtype='float32')
36+
z1 = x.divide(y).floor() # 向下取整
37+
z2 = x.divide(y).trunc() # 向零取整
38+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## [ torch 参数更多 ] torch.Tensor.double
2+
3+
### [torch.Tensor.double](https://pytorch.org/docs/1.13/generated/torch.Tensor.double.html#torch-Tensor-double)
4+
5+
```python
6+
torch.Tensor.double(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('float64')
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
21+
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
22+
23+
### 转写示例
24+
25+
```python
26+
# torch 写法
27+
x.double()
28+
29+
# paddle 写法
30+
x.astype('float64')
31+
```

0 commit comments

Comments
 (0)