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. 59 #5857

Merged
merged 3 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,33 @@
## [ torch 参数更多 ] torch.Tensor.bernoulli

### [torch.Tensor.bernoulli](https://pytorch.org/docs/stable/generated/torch.Tensor.bernoulli.html#torch-tensor-bernoulli)
Copy link
Collaborator

Choose a reason for hiding this comment

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

pytorch链接需要是 1.13 版本下的链接 ,其余文件也辛苦修改一下
image


```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)
```

其中 torch 是类成员函数,而 paddle 是非类成员函数,因此第一个参数 `x` 不进行对比,Pytorch 相比 Paddle 支持更多其他参数,具体如下:
Copy link
Collaborator

Choose a reason for hiding this comment

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

直接写 其中 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/stable/generated/torch.Tensor.bfloat16.html#torch-tensor-bfloat16)
Copy link
Collaborator

Choose a reason for hiding this comment

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

链接改为 1.13 版本下的~


```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/stable/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/stable/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/stable/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/stable/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
@@ -0,0 +1,22 @@
## [ torch 参数更多 ] torch.Tensor.div

### [torch.Tensor.div](https://pytorch.org/docs/stable/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 无此功能,暂无转写方式。|
Copy link
Collaborator

Choose a reason for hiding this comment

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

trunc可以写为 向零取整
这里可以通过paddle.trunc()和paddle.floor()转写完成

import paddle
a = paddle.to_tensor([0.9, 1.2])
b = paddle.to_tensor([-0.2, 0.7])
res1 = a.divide(b).trunc()  # 向零取整
res2 = a.divide(b).floor()  # 向下取整
print(res1)
print(res2)

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## [ torch 参数更多 ] torch.Tensor.divide

### [torch.Tensor.divide](https://pytorch.org/docs/stable/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 无此功能,暂无转写方式。|
Copy link
Collaborator

Choose a reason for hiding this comment

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

和上面一个转写方式一样

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/stable/generated/torch.Tensor.char.html#torch-tensor-char)

```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')
```