Skip to content

Commit

Permalink
【Hackathon 5th No.7】为 Paddle 新增 apply API (#6429)
Browse files Browse the repository at this point in the history
* add docs apply_

* fix
  • Loading branch information
yangguohao authored Dec 29, 2023
1 parent 23cceca commit e8b395f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
16 changes: 16 additions & 0 deletions docs/api/paddle/Tensor_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,22 @@ any(axis=None, keepdim=False, name=None)

请参考 :ref:`cn_api_paddle_any`

apply(callable)
:::::::::

对当前 Tensor 调用 callable 函数,并且返回该函数计算后返回的值。

返回:计算后的 Tensor

返回类型:Tensor

COPY-FROM: paddle.Tensor.apply

apply_(callable)
:::::::::

Inplace 版本的 `apply` API,对输入 `x` 采用 Inplace 策略。

argmax(axis=None, keepdim=False, dtype=int64, name=None)
:::::::::

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## [ 参数完全一致 ]torch.Tensor.apply_
### [torch.Tensor.apply_](https://pytorch.org/docs/stable/generated/torch.Tensor.apply_.html)

```python
torch.Tensor.apply_(callable)
```

### [paddle.Tensor.apply_]()

```python
paddle.Tensor.apply_(callable)
```


两者功能不同,pytorch 只支持 Inplace 操作,且只对 CPU tensor 才能使用。Paddle 版本可以在 GPU 下运行同时也有 outplace 版本。两者参数一致,具体如下:

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
|----------|--------------|-----------|
| callable | callable | 一个被调用的函数。 |
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@
| 306 | [torch.Tensor.tensor_split](https://pytorch.org/docs/stable/generated/torch.Tensor.tensor_split.html) | [paddle.Tensor.tensor_split](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tensor_split-indices_or_sections-axis-0-name-none) | 功能完全一致,仅参数名不一致 [差异对比](https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tensor_split.md) |
| 307 | [torch.Tensor.masked_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_scatter.html?highlight=resize#torch.Tensor.masked_scatter) | [paddle.Tensor.masked_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#id25) | 功能完全一致 |
| 308 | [torch.Tensor.masked_scatter_](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_scatter_.html?highlight=resize#torch.Tensor.masked_scatter_) | [paddle.Tensor.masked_scatter_](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#id25) | 功能完全一致 |

| 309 | [torch.Tensor.apply_](https://pytorch.org/docs/stable/generated/torch.Tensor.apply_.html) |[paddle.Tensor.apply_](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#id25)| 参数完全一致 , [差异对比](https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.apply_.md)|

| 序号 | PyTorch API | PaddlePaddle API | 备注 |
| ----- | ----------- | ----------------- | --- |
Expand Down

0 comments on commit e8b395f

Please sign in to comment.