-
Notifications
You must be signed in to change notification settings - Fork 777
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
【Hackathon 7th No.38】为Paddle代码转换工具新增API转换规则(第5组) (#6885)
* 【Hackathon 7th No.38】为 Paddle 代码转换工具新增 API 转换规则(第5组) * fix docs * fix * fix * update_param_exp * fix * fix * fix * fix_ * fix * fix * fix * fix
- Loading branch information
1 parent
6304cc9
commit 9d29094
Showing
16 changed files
with
556 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...del_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isneginf.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## [无参数]torch.Tensor.isneginf | ||
|
||
### [torch.Tensor.isneginf ](https://pytorch.org/docs/stable/generated/torch.Tensor.isneginf.html#torch.Tensor.isneginf) | ||
|
||
```python | ||
torch.Tensor.isneginf() | ||
``` | ||
|
||
### [paddle.Tensor.isneginf](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#isneginf-name-none) | ||
|
||
```python | ||
paddle.Tensor.isneginf(name=None) | ||
``` | ||
|
||
两者功能一致,无参数。 |
15 changes: 15 additions & 0 deletions
15
...del_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isposinf.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## [无参数]torch.Tensor.isposinf | ||
|
||
### [torch.Tensor.isposinf](https://pytorch.org/docs/stable/generated/torch.Tensor.isposinf.html#torch.Tensor.isposinf) | ||
|
||
```python | ||
torch.Tensor.isposinf() | ||
``` | ||
|
||
### [paddle.Tensor.isposinf](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#isposinf-name-none) | ||
|
||
```python | ||
paddle.Tensor.isposinf(name=None) | ||
``` | ||
|
||
两者功能一致,无参数。 |
15 changes: 15 additions & 0 deletions
15
...model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isreal.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## [无参数]torch.Tensor.isreal | ||
|
||
### [torch.Tensor.isreal](https://pytorch.org/docs/stable/generated/torch.Tensor.isreal.html#torch.Tensor.isreal) | ||
|
||
```python | ||
torch.Tensor.isreal() | ||
``` | ||
|
||
### [paddle.Tensor.isreal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#isreal-name-none) | ||
|
||
```python | ||
paddle.Tensor.isreal(name=None) | ||
``` | ||
|
||
两者功能一致,无参数。 |
27 changes: 27 additions & 0 deletions
27
...del_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.positive.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## [组合替代实现]torch.Tensor.positive | ||
|
||
### [torch.Tensor.positive](https://pytorch.org/docs/stable/generated/torch.Tensor.positive.html#torch.Tensor.positive) | ||
|
||
```python | ||
torch.Tensor.positive() | ||
``` | ||
|
||
判断 `input` 是否是 bool 类型的 Tensor,如果是则抛出 RuntimeError 异常,否则返回 `input` 。 | ||
|
||
Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
x.positive() | ||
|
||
# Paddle 写法 | ||
def positive(x): | ||
if x.dtype != paddle.bool: | ||
return x | ||
else: | ||
raise RuntimeError("boolean tensors is not supported.") | ||
|
||
positive(x) | ||
``` |
26 changes: 26 additions & 0 deletions
26
...nvert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_reduce.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## [paddle 参数更多]torch.Tensor.scatter_reduce | ||
|
||
### [torch.Tensor.scatter_reduce](https://pytorch.org/docs/stable/generated/torch.Tensor.scatter_reduce.html#torch-tensor-scatter-reduce) | ||
|
||
```python | ||
torch.Tensor.scatter_reduce(dim, index, src, reduce, *, include_self=True) | ||
``` | ||
|
||
### [paddle.Tensor.put_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#put-along-axis-indices-value-axis-reduce-assign-include-self-true-broadcast-true) | ||
|
||
```python | ||
paddle.Tensor.put_along_axis(indices, values, axis, reduce="assign", include_self=True, broadcast=True) | ||
``` | ||
|
||
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------ | ------------ | ------------------------------------------------------------ | | ||
| dim | axis | 表示 scatter 的维度,仅参数名不一致。 | | ||
| index | indices | 表示输入的索引张量,仅参数名不一致。 | | ||
| src | values | 表示需要插入的值,仅参数名不一致。 | | ||
| reduce | reduce | 表示插入 values 时的计算方式,参数默认值不一致。PyTorch 中该参数无默认值,需要输入,Paddle 中默认值为 `assign`,应设置为与 PyTorch 一致。其中 PyTorch 的 `sum` 对应 Paddle 中的 `add`,PyTorch 的 `prod` 对应 Paddle 中 `multiply`。 | | ||
| include_self | include_self | 表示插入 values 时是否包含输入元素中的值。 | | ||
| - | broadcast | 表示是否需要广播索引张量矩阵,PyTorch 无此参数,Paddle 应设置为 `False` 才与 PyTorch 一致 | |
33 changes: 33 additions & 0 deletions
33
...des/model_convert/convert_from_pytorch/api_difference/torch/torch.block_diag.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## [输入参数类型不一致]torch.block_diag | ||
|
||
### [torch.block_diag](https://pytorch.org/docs/stable/generated/torch.block_diag.html#torch-block-diag) | ||
|
||
```python | ||
torch.block_diag(*tensors) | ||
``` | ||
|
||
### [paddle.block_diag](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/block_diag_cn.html) | ||
|
||
```python | ||
paddle.block_diag(inputs, name=None) | ||
``` | ||
|
||
二者功能一致但参数类型不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| -------- | ------------ | ------------------------------------------------------------ | | ||
| *tensors | inputs | 一组输入 Tensor,PyTorch 参数 tensors 为可变参数,Paddle 参数 inputs 为 list(Tensor) 或 tuple(Tensor) 的形式。 | | ||
|
||
### 转写示例 | ||
|
||
#### *tensors:一组输入 Tensor | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.block_diag(x, y, z) | ||
|
||
# Paddle 写法 | ||
paddle.block_diag([x, y, z]) | ||
``` |
194 changes: 194 additions & 0 deletions
194
...uides/model_convert/convert_from_pytorch/api_difference/torch/torch.can_cast.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
## [组合替代实现]torch.can_cast | ||
|
||
### [torch.can_cast](https://pytorch.org/docs/stable/generated/torch.can_cast.html#torch-can-cast) | ||
|
||
```python | ||
torch.can_cast(from_, to) | ||
``` | ||
|
||
判断类型的转换在 PyTorch 的[casting 规则](https://pytorch.org/docs/stable/tensor_attributes.html#type-promotion-doc)中是否被允许。 | ||
|
||
Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.can_cast(x, y) | ||
|
||
# Paddle 写法 | ||
def can_cast(from_, to): | ||
can_cast_dict = { | ||
paddle.bfloat16: { | ||
paddle.bfloat16: True, | ||
paddle.float16: True, | ||
paddle.float32: True, | ||
paddle.float64: True, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: False, | ||
paddle.int8: False, | ||
paddle.int16: False, | ||
paddle.int32: False, | ||
paddle.int64: False, | ||
paddle.bool: False | ||
}, | ||
paddle.float16: { | ||
paddle.bfloat16: True, | ||
paddle.float16: True, | ||
paddle.float32: True, | ||
paddle.float64: True, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: False, | ||
paddle.int8: False, | ||
paddle.int16: False, | ||
paddle.int32: False, | ||
paddle.int64: False, | ||
paddle.bool: False, | ||
}, | ||
paddle.float32: { | ||
paddle.bfloat16: True, | ||
paddle.float16: True, | ||
paddle.float32: True, | ||
paddle.float64: True, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: False, | ||
paddle.int8: False, | ||
paddle.int16: False, | ||
paddle.int32: False, | ||
paddle.int64: False, | ||
paddle.bool: False, | ||
}, | ||
paddle.float64: { | ||
paddle.bfloat16: True, | ||
paddle.float16: True, | ||
paddle.float32: True, | ||
paddle.float64: True, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: False, | ||
paddle.int8: False, | ||
paddle.int16: False, | ||
paddle.int32: False, | ||
paddle.int64: False, | ||
paddle.bool: False, | ||
}, | ||
paddle.complex64: { | ||
paddle.bfloat16: False, | ||
paddle.float16: False, | ||
paddle.float32: False, | ||
paddle.float64: False, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: False, | ||
paddle.int8: False, | ||
paddle.int16: False, | ||
paddle.int32: False, | ||
paddle.int64: False, | ||
paddle.bool: False, | ||
}, | ||
paddle.complex128: { | ||
paddle.bfloat16: False, | ||
paddle.float16: False, | ||
paddle.float32: False, | ||
paddle.float64: False, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: False, | ||
paddle.int8: False, | ||
paddle.int16: False, | ||
paddle.int32: False, | ||
paddle.int64: False, | ||
paddle.bool: False, | ||
}, | ||
paddle.uint8: { | ||
paddle.bfloat16: True, | ||
paddle.float16: True, | ||
paddle.float32: True, | ||
paddle.float64: True, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: True, | ||
paddle.int8: True, | ||
paddle.int16: True, | ||
paddle.int32: True, | ||
paddle.int64: True, | ||
paddle.bool: False, | ||
}, | ||
paddle.int8: { | ||
paddle.bfloat16: True, | ||
paddle.float16: True, | ||
paddle.float32: True, | ||
paddle.float64: True, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: True, | ||
paddle.int8: True, | ||
paddle.int16: True, | ||
paddle.int32: True, | ||
paddle.int64: True, | ||
paddle.bool: False, | ||
}, | ||
paddle.int16: { | ||
paddle.bfloat16: True, | ||
paddle.float16: True, | ||
paddle.float32: True, | ||
paddle.float64: True, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: True, | ||
paddle.int8: True, | ||
paddle.int16: True, | ||
paddle.int32: True, | ||
paddle.int64: True, | ||
paddle.bool: False, | ||
}, | ||
paddle.int32: { | ||
paddle.bfloat16: True, | ||
paddle.float16: True, | ||
paddle.float32: True, | ||
paddle.float64: True, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: True, | ||
paddle.int8: True, | ||
paddle.int16: True, | ||
paddle.int32: True, | ||
paddle.int64: True, | ||
paddle.bool: False, | ||
}, | ||
paddle.int64: { | ||
paddle.bfloat16: True, | ||
paddle.float16: True, | ||
paddle.float32: True, | ||
paddle.float64: True, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: True, | ||
paddle.int8: True, | ||
paddle.int16: True, | ||
paddle.int32: True, | ||
paddle.int64: True, | ||
paddle.bool: False, | ||
}, | ||
paddle.bool: { | ||
paddle.bfloat16: True, | ||
paddle.float16: True, | ||
paddle.float32: True, | ||
paddle.float64: True, | ||
paddle.complex64: True, | ||
paddle.complex128: True, | ||
paddle.uint8: True, | ||
paddle.int8: True, | ||
paddle.int16: True, | ||
paddle.int32: True, | ||
paddle.int64: True, | ||
paddle.bool: True, | ||
} | ||
} | ||
return can_cast_dict[from_][to] | ||
|
||
can_cast(x, y) | ||
``` |
33 changes: 33 additions & 0 deletions
33
...model_convert/convert_from_pytorch/api_difference/torch/torch.cartesian_prod.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## [输入参数类型不一致]torch.cartesian_prod | ||
|
||
### [torch.cartesian_prod](https://pytorch.org/docs/stable/generated/torch.cartesian_prod.html#torch-cartesian-prod) | ||
|
||
```python | ||
torch.cartesian_prod(*tensors) | ||
``` | ||
|
||
### [paddle.cartesian_prod](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cartesian_prod_cn.html) | ||
|
||
```python | ||
paddle.cartesian_prod(x, name=None) | ||
``` | ||
|
||
两者功能一致但参数类型不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| -------- | ------------ | ------------------------------------------------------------ | | ||
| *tensors | x | 一组输入 Tensor , PyTorch 参数 tensors 为可变参, Paddle 参数 x 为 list(Tensor) 或 tuple(Tensor) 的形式。 | | ||
|
||
### 转写示例 | ||
|
||
#### *tensors:一组输入 Tensor | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.cartesian_prod(a, b) | ||
|
||
# Paddle 写法 | ||
paddle.cartesian_prod([a, b]) | ||
``` |
Oops, something went wrong.