-
Notifications
You must be signed in to change notification settings - Fork 777
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
【Hackathon 5th No.4】为 Paddle 新增 masked_scatter API #6405
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.. _cn_api_paddle_masked_scatter_: | ||
|
||
masked_scatter\_ | ||
------------------------------- | ||
|
||
.. py:function:: paddle.masked_scatter_(x) | ||
Inplace 版本的 :ref:`cn_api_paddle_masked_scatter` API,对输入 x 采用 Inplace 策略。 | ||
|
||
更多关于 inplace 操作的介绍请参考 `3.1.3 原位(Inplace)操作和非原位操作的区别`_ 了解详情。 | ||
|
||
.. _3.1.3 原位(Inplace)操作和非原位操作的区别: https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/beginner/tensor_cn.html#id3 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,28 @@ | ||||||
.. _cn_api_paddle_masked_scatter: | ||||||
|
||||||
masked_scatter | ||||||
------------------------------- | ||||||
|
||||||
.. py:function:: paddle.masked_scatter(x, mask, value, name=None) | ||||||
|
||||||
|
||||||
|
||||||
返回一个 N-D 的 Tensor,Tensor 的值是根据 ``mask`` 信息,将 ``value`` 中的值逐个填充到 ``x`` 中 ``mask`` 对应为 ``True`` 的位置,``mask`` 的数据类型是 bool。 | ||||||
|
||||||
参数 | ||||||
:::::::::::: | ||||||
|
||||||
- **x** (Tensor) - 输入 Tensor,数据类型为 float,double,int,int64_t,float16 或者 bfloat16。 | ||||||
- **mask** (Tensor) - 布尔张量,表示要填充的位置。mask 的数据类型必须为 bool。 | ||||||
- **value** (Tensor):用于填充目标张量的值,数据类型为 float,double,int,int64_t,float16 或者 bfloat16。 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||||||
|
||||||
返回 | ||||||
:::::::::::: | ||||||
返回一个根据 ``mask`` 将对应位置逐个填充 ``value`` 中的 Tensor,数据类型与 ``x`` 相同。 | ||||||
|
||||||
|
||||||
代码示例 | ||||||
:::::::::::: | ||||||
|
||||||
COPY-FROM: paddle.masked_scatter |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 辛苦 @zhwesky2010 review下~ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## [ 参数完全一致 ] torch.Tensor.masked_scatter | ||
|
||
### [torch.Tensor.masked_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_scatter.html?highlight=masked_scatter#torch.Tensor.masked_scatter) | ||
|
||
```python | ||
torch.Tensor.masked_scatter(mask, value) | ||
``` | ||
|
||
### [paddle.Tensor.masked_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#masked-scatter-mask-value-name-non) | ||
|
||
```python | ||
paddle.Tensor.masked_scatter(mask, value, name=None) | ||
``` | ||
|
||
两者功能一致,参数完全一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
|---------|--------------| -------------------------------------------------- | | ||
| mask | mask | 布尔张量,表示要填充的位置 | | ||
| value | value | 用于填充目标张量的值 | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## [ 参数完全一致 ] torch.Tensor.masked_scatter_ | ||
|
||
### [torch.Tensor.masked_scatter_](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_scatter_.html?highlight=masked_scatter#torch.Tensor.masked_scatter_) | ||
|
||
```python | ||
torch.Tensor.masked_scatter_(mask, value) | ||
``` | ||
|
||
### [paddle.Tensor.masked_scatter_]() | ||
|
||
```python | ||
paddle.Tensor.masked_scatter_(mask, value, name=None) | ||
``` | ||
|
||
两者功能一致,参数完全一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
|---------|--------------| -------------------------------------------------- | | ||
| mask | mask | 布尔张量,表示要填充的位置 | | ||
| value | value | 用于填充目标张量的值 | |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -625,7 +625,7 @@ | |
梳理了`torch.Tensor.XX`类 API 的 PyTorch-PaddlePaddle API 映射列表。 | ||
|
||
| 序号 | PyTorch API | PaddlePaddle API | 备注 | | ||
|-----| --- | --- | --- | | ||
-----|-----| --- | --- | --- | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为啥要改这个? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 恢复了 |
||
| 1 | [torch.Tensor.device](https://pytorch.org/docs/stable/generated/torch.Tensor.device.html) | [paddle.Tensor.place](https://www.paddlepaddle.org.cn/documentation/docs/api/paddle/Tensor_cn.html#place) | 功能一致, 无参数 , [差异对比](https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.device.md) | | ||
| 2 | [torch.Tensor.grad](https://pytorch.org/docs/stable/generated/torch.Tensor.grad.html) | [paddle.Tensor.grad](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#grad) | 功能一致, 无参数 , [差异对比](https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.grad.md) | | ||
| 3 | [torch.Tensor.imag](https://pytorch.org/docs/stable/generated/torch.Tensor.imag.html) | [paddle.Tensor.imag](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#imag-name-none) | 功能一致, 无参数 , [差异对比](https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.imag.md) | | ||
|
@@ -932,6 +932,8 @@ | |
| 304 | [torch.Tensor.resize_](https://pytorch.org/docs/stable/generated/torch.Tensor.resize_.html?highlight=resize#torch.Tensor.resize_) | | 功能缺失 | | ||
| 305 | [torch.Tensor.masked_fill_](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_fill_.html?highlight=resize#torch.Tensor.masked_fill_) | [paddle.Tensor.masked_fill_](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#id25) | 功能完全一致 | | ||
| 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) | 功能完全一致 | | ||
|
||
|
||
| 序号 | PyTorch API | PaddlePaddle API | 备注 | | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done