Skip to content

Commit

Permalink
映射文档 No. 59 (PaddlePaddle#5857)
Browse files Browse the repository at this point in the history
* 映射文档 No. 59

* 映射文档 No. 59

* 映射文档 No. 59
  • Loading branch information
wenyin authored and lijialin03 committed May 16, 2023
1 parent 2b72c99 commit 6fab725
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## [ torch 参数更多 ] torch.Tensor.bernoulli

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

```python
torch.Tensor.bernoulli(*, generator=None)
```

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

```python
paddle.bernoulli(x, name=None)
```

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

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
| generator | - | 用于采样的伪随机数生成器, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |

### 转写示例

```python
# torch 写法
x = torch.tensor([0.2, 0.6, 0.8])
y = x.bernoulli()

# paddle 写法
x = paddle.to_tensor([0.2, 0.6, 0.8])
y = paddle.bernoulli(x)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## [ torch 参数更多 ] torch.Tensor.bfloat16

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

```python
torch.Tensor.bfloat16(memory_format=torch.preserve_format)
```

### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype)

```python
paddle.Tensor.astype('bfloat16')
```

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

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |

### 转写示例

```python
# torch 写法
x = torch.randn(3, 3)
y = x.bfloat16()

# paddle 写法
x = paddle.randn([3, 3])
y = x.astype('bfloat16')
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## [ torch 参数更多 ] torch.Tensor.bool

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

```python
torch.Tensor.bool(memory_format=torch.preserve_format)
```

### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype)

```python
paddle.Tensor.astype('bool')
```

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

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |

### 转写示例

```python
# torch 写法
x = torch.tensor([-1, 0, 1])
y = x.bool()

# paddle 写法
x = paddle.to_tensor([-1, 0, 1])
y = x.astype('bool')
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## [ torch 参数更多 ] torch.Tensor.byte

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

```python
torch.Tensor.byte(memory_format=torch.preserve_format)
```

### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype)

```python
paddle.Tensor.astype('uint8')
```

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

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |

### 转写示例

```python
# torch 写法
x = torch.tensor([0, 1, 2, 3])
y = x.byte()

# paddle 写法
x = paddle.to_tensor([0, 1, 2, 3])
y = x.astype('uint8')
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## [ torch 参数更多 ] torch.Tensor.char

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

```python
torch.Tensor.char(memory_format=torch.preserve_format)
```

### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype)

```python
paddle.Tensor.astype('int8')
```

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

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |

### 转写示例

```python
# torch 写法
x.char()

# paddle 写法
x.astype('int8')
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [ torch 参数更多 ] torch.Tensor.clone

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

```python
torch.Tensor.clone(*, memory_format=torch.preserve_format)
```

### [paddle.Tensor.clone](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#clone)

```python
paddle.Tensor.clone()
```

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

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## torch.Tensor.copy_
### [torch.Tensor.copy_](https://pytorch.org/docs/stable/generated/torch.Tensor.copy_.html?highlight=copy_#torch.Tensor.copy_)
## [ torch 参数更多 ] torch.Tensor.copy_

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

```python
torch.Tensor.copy_(src, non_blocking=False)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## [ torch 参数更多 ] torch.Tensor.div

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

```python
torch.Tensor.div(other, *, rounding_mode=None)
```

### [paddle.Tensor.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#divide-y-name-none)

```python
paddle.Tensor.divide(y, name=None)
```

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

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
| other | y | 表示输入的 Tensor ,仅参数名不一致。 |
| rounding_mode | - | 用于指定在执行截断除法时的舍入模式,可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要进行转写。 |

### 转写示例

```python
# torch 写法
x = torch.tensor([4, 8, 12], dtype=torch.float32)
y = torch.tensor([3, 4, 5], dtype=torch.float32)
z1 = x.div(y, rounding_mode='floor') # 向下取整
z2 = x.div(y, rounding_mode='trunc') # 向零取整

# paddle 写法
x = paddle.to_tensor([4, 8, 12], dtype='float32')
y = paddle.to_tensor([3, 4, 5], dtype='float32')
z1 = x.divide(y).floor() # 向下取整
z2 = x.divide(y).trunc() # 向零取整
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## [ torch 参数更多 ] torch.Tensor.divide

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

```python
torch.Tensor.divide(other, *, rounding_mode=None)
```

### [paddle.Tensor.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#divide-y-name-none)

```python
paddle.Tensor.divide(y, name=None)
```

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

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
| other | y | 表示输入的 Tensor ,仅参数名不一致。 |
| rounding_mode | - | 用于指定在执行截断除法时的舍入模式。可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要进行转写。 |

### 转写示例

```python
# torch 写法
x = torch.tensor([4, 8, 12], dtype=torch.float32)
y = torch.tensor([3, 4, 5], dtype=torch.float32)
z1 = x.divide(y, rounding_mode='floor') # 向下取整
z2 = x.divide(y, rounding_mode='trunc') # 向零取整

# paddle 写法
x = paddle.to_tensor([4, 8, 12], dtype='float32')
y = paddle.to_tensor([3, 4, 5], dtype='float32')
z1 = x.divide(y).floor() # 向下取整
z2 = x.divide(y).trunc() # 向零取整
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## [ torch 参数更多 ] torch.Tensor.double

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

```python
torch.Tensor.double(memory_format=torch.preserve_format)
```

### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype)

```python
paddle.Tensor.astype('float64')
```

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

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |

### 转写示例

```python
# torch 写法
x.double()

# paddle 写法
x.astype('float64')
```

0 comments on commit 6fab725

Please sign in to comment.