Skip to content

Commit e88b180

Browse files
authored
add torch.bucketize etc. (#5878)
* model_convert add torch.is_nonzero .etc * model_convert add is_nonzero .etc * model_convert add is_nonzero .etc * model_convert add is_nonzero .etc * add xlogy.etc * add randn_like .etc * comment * add vdot etc. * add aminmax etc. * fix parameter * add bucketizr etc. * add bucketizr etc. * add bucketizr etc.
1 parent b97a2f7 commit e88b180

14 files changed

+191
-26
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## [仅 Paddle 参数更多]torch.Tensor.count_nonzero
2+
### [torch.Tensor.count_nonzero](https://pytorch.org/docs/stable/generated/torch.Tensor.count_nonzero.html#torch.Tensor.count_nonzero)
3+
4+
```python
5+
torch.Tensor.count_nonzero(dim=None)
6+
```
7+
8+
### [paddle.Tensor.count_nonzero](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#count-nonzero-axis-none-keepdim-false-name-none)
9+
10+
```python
11+
paddle.Tensor.count_nonzero(axis=None, keepdim=False, name=None)
12+
```
13+
14+
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下:
15+
16+
### 参数映射
17+
| PyTorch | PaddlePaddle | 备注 |
18+
| ------------- | ------------ | ------------------------------------------------------ |
19+
| <font color='red'> dim </font> | <font color='red'> axis </font> | 表示进行运算的轴,仅参数名不一致。 |
20+
| - | <font color='red'> keepdim </font> | 是否在输出 Tensor 中保留减小的维度, Pytorch 无此参数, Paddle 保持默认即可。 |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ paddle.Tensor.divide(y, name=None)
1919
| PyTorch | PaddlePaddle | 备注 |
2020
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
2121
| other | y | 表示输入的 Tensor ,仅参数名不一致。 |
22-
| rounding_mode | - | 用于指定在执行截断除法时的舍入模式,可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要进行转写。 |
22+
| rounding_mode | - | 用于指定在执行截断除法时的舍入模式,可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要进行转写。Paddle 可通过组合 paddle.trunc 或 paddle.floor 实现。 |
2323

2424
### 转写示例
2525

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ paddle.Tensor.divide(y, name=None)
1919
| PyTorch | PaddlePaddle | 备注 |
2020
| ------------- | ------------ | ----------------------------------------------------------------------------------- |
2121
| other | y | 表示输入的 Tensor ,仅参数名不一致。 |
22-
| rounding_mode | - | 用于指定在执行截断除法时的舍入模式。可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要进行转写。 |
22+
| rounding_mode | - | 用于指定在执行截断除法时的舍入模式。可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要进行转写。Paddle 可通过组合 paddle.trunc 或 paddle.floor 实现。 |
2323

2424
### 转写示例
2525

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## [ torch 参数更多]torch.Tensor.repeat_interleave
2+
3+
### [torch.Tensor.repeat_interleave](https://pytorch.org/docs/stable/generated/torch.Tensor.repeat_interleave.html#torch.Tensor.repeat_interleave)
4+
5+
```python
6+
torch.Tensor.repeat_interleave(repeats, dim=None, *, output_size=None)
7+
```
8+
9+
### [paddle.Tensor.repeat_interleave](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#repeat-interleave-repeats-axis-none-name-none)
10+
11+
```python
12+
paddle.Tensor.repeat_interleave(repeats, axis=None, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
| PyTorch | PaddlePaddle | 备注 |
19+
| ------- | ------------ | --------------------------------------------------- |
20+
| repeats | repeats | 表示指定复制次数的 1-D Tensor 或指定的复制次数。 |
21+
| dim | axis | 表示复制取值的维度,仅参数名不一致。 |
22+
| output_size | - | 表示给定维度的总输出尺寸,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## [ 无参数 ]torch.sgn
2+
### [torch.Tensor.sgn](https://pytorch.org/docs/stable/generated/torch.Tensor.sgn.html#torch.Tensor.sgn)
3+
4+
```python
5+
torch.Tensor.sgn()
6+
```
7+
8+
### [paddle.Tensor.sgn](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#sgn-name-none)
9+
10+
```python
11+
paddle.Tensor.sgn()
12+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## [ torch 参数更多 ]torch.Tensor.sub
2+
### [torch.Tensor.sub](https://pytorch.org/docs/stable/generated/torch.Tensor.sub.html#torch.Tensor.sub)
3+
4+
```python
5+
torch.Tensor.sub(other, *, alpha=1)
6+
```
7+
8+
### [paddle.Tensor.subtract](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/subtract_cn.html#subtract)
9+
10+
```python
11+
paddle.Tensor.subtract(y,
12+
name=None)
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
### 参数映射
17+
| PyTorch | PaddlePaddle | 备注 |
18+
| ------------- | ------------ | ------------------------------------------------------ |
19+
| other | y | 表示减数的 Tensor,仅参数名不一致。 |
20+
| alpha | - | 表示`other`的乘数,PaddlePaddle 无此参数,需要进行转写。Paddle 应设置 y = alpha * other。 |
21+
22+
23+
### 转写示例
24+
#### alpha:表示`other`的乘数
25+
```python
26+
# Pytorch 写法
27+
x.sub(y, alpha=2)
28+
29+
# Paddle 写法
30+
x.subtract(2 * y)
31+
32+
# 注:Paddle 直接将 alpha 与 y 相乘实现
33+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## [ torch 参数更多 ]torch.Tensor.subtract
2+
### [torch.Tensor.subtract](https://pytorch.org/docs/stable/generated/torch.Tensor.subtract.html#torch.Tensor.subtract)
3+
4+
```python
5+
torch.Tensor.subtract(other, *, alpha=1)
6+
```
7+
8+
### [paddle.Tensor.subtract](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/subtract_cn.html#subtract)
9+
10+
```python
11+
paddle.Tensor.subtract(y,
12+
name=None)
13+
```
14+
15+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
16+
### 参数映射
17+
| PyTorch | PaddlePaddle | 备注 |
18+
| ------------- | ------------ | ------------------------------------------------------ |
19+
| other | y | 表示减数的 Tensor,仅参数名不一致。 |
20+
| alpha | - | 表示`other`的乘数,PaddlePaddle 无此参数,需要进行转写。Paddle 应设置 y = alpha * other。 |
21+
22+
23+
### 转写示例
24+
#### alpha:表示`other`的乘数
25+
```python
26+
# Pytorch 写法
27+
x.subtract(y, alpha=2)
28+
29+
# Paddle 写法
30+
x.subtract(2 * y)
31+
32+
# 注:Paddle 直接将 alpha 与 y 相乘实现
33+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## [torch 参数更多 ] torch.bucketize
2+
### [torch.bucketize](https://pytorch.org/docs/stable/generated/torch.bucketize.html#torch.bucketize)
3+
4+
```python
5+
torch.bucketize(input, boundaries, *, out_int32=False, right=False, out=None)
6+
```
7+
8+
### [paddle.bucketize](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/bucketize_cn.html#paddle-bucketize)
9+
10+
```python
11+
paddle.bucketize(x, sorted_sequence, out_int32=False, right=False, name=None)
12+
```
13+
14+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
15+
### 参数映射
16+
| PyTorch | PaddlePaddle | 备注 |
17+
| ------------- | ------------ | ------------------------------------------------------ |
18+
| <font color='red'>input</font>| <font color='red'>x</font> | 表示输入的 Tensor ,仅参数名不一致。 |
19+
| <font color='red'>boundaries</font>| <font color='red'>sorted_sequence</font> | 数据的边界,仅参数名不一致。 |
20+
| <font color='red'>out_int32</font>| <font color='red'>out_int32</font> | 输出的数据类型是否为 int32。 |
21+
| <font color='red'>right</font>| <font color='red'>right</font> | 根据给定输入在 sorted_sequence 查找对应的上边界或下边界。 |
22+
| <font color='red'>out</font> | - | 表示输出的 Tensor, Paddle 无此参数,需要进行转写。 |
23+
24+
25+
### 转写示例
26+
#### out:指定输出
27+
```python
28+
# Pytorch 写法
29+
torch.bucketize(x, boundaries, out=y)
30+
31+
# Paddle 写法
32+
paddle.assign(paddle.bucketize(x, boundaries), y)
33+
```

docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.chain_matmul.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
```python
55
torch.chain_matmul(*matrices, out=None)
66
```
7-
### 功能介绍
8-
用于实现多个矩阵相乘,PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。
7+
Paddle 无此 API,需要组合实现。
8+
9+
### 转写示例
10+
911
```python
10-
import paddle
12+
# Pytorch 写法
13+
y = torch.chain_matmul(a, b, c)
1114

12-
def chain_matmul(*matrices, out=None):
13-
assert len(matrices) >= 1, "Expected one or more matrices."
14-
if len(matrices) == 1:
15-
return matrices[0]
16-
out = paddle.matmul(matrices[0], matrices[1])
17-
for i in range(2, len(matrices)):
18-
out = paddle.matmul(out, matrices[i])
19-
return out
15+
# Paddle 写法
16+
y = a @ b @ c
2017
```

0 commit comments

Comments
 (0)