-
Notifications
You must be signed in to change notification settings - Fork 869
【Hackathon 5th No.3】为 Paddle 新增 masked_fill API #6254
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
Changes from 5 commits
ae38a65
d446294
5ba5c98
272d402
68f5af3
ad50009
35dcd16
6de578e
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 | ||||
---|---|---|---|---|---|---|
|
@@ -3047,3 +3047,16 @@ unfold(x, axis, size, step, name=None) | |||||
返回类型:Tensor | ||||||
|
||||||
请参考 :ref:`cn_api_paddle_unfold` | ||||||
|
||||||
masked_fill(x, mask, value, name=None) | ||||||
::::::::: | ||||||
根据 mask 信息,将 value 中的值填充到 x 中 mask 对应为 True 的位置。 | ||||||
|
||||||
返回一个根据 mask 将对应位置填充为 value 的 Tensor。 | ||||||
|
||||||
请参考 :ref:`cn_api_paddle_masked_fill` | ||||||
|
||||||
masked_fill_(x, mask, value, name=None) | ||||||
::::::::: | ||||||
|
||||||
Inplace 版本的 :ref:`_cn_api_paddle_masked_fill` API,对输入 `x` 采用 Inplace 策略。 | ||||||
|
Inplace 版本的 :ref:`_cn_api_paddle_masked_fill` API,对输入 `x` 采用 Inplace 策略。 | |
Inplace 版本的 :ref:`cn_api_paddle_masked_fill` API,对输入 `x` 采用 Inplace 策略。 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,11 @@ | ||||||
.. _cn_api_paddle_masked_fill_: | ||||||
|
||||||
masked_fill\_ | ||||||
------------------------------- | ||||||
|
||||||
.. py:function:: paddle.masked_fill_(x) | ||||||
Inplace 版本的 :ref:`cn_api_paddle_add` API,对输入 x 采用 Inplace 策略。 | ||||||
|
Inplace 版本的 :ref:`cn_api_paddle_add` API,对输入 x 采用 Inplace 策略。 | |
Inplace 版本的 :ref:`cn_api_paddle_masked_fill` API,对输入 x 采用 Inplace 策略。 |
AndSonder marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.. _cn_api_paddle_masked_fill: | ||
|
||
masked_fill | ||
------------------------------- | ||
|
||
.. py:function:: paddle.masked_fill(x, mask, value, name=None) | ||
|
||
|
||
|
||
返回一个 1-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** (Scalar or 0-D Tensor):用于填充目标张量的值,数据类型为 float,double,int,int64_t,float16 或者 bfloat16。 | ||
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
||
返回 | ||
:::::::::::: | ||
返回一个根据 ``mask`` 将对应位置填充为 ``value`` 的 Tensor,数据类型与 ``x`` 相同。 | ||
|
||
|
||
代码示例 | ||
:::::::::::: | ||
|
||
COPY-FROM: paddle.masked_fill |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
## [ 组合替代实现 ]torch.Tensor.masked_fill | ||
## [ 参数完全一致 ] torch.Tensor.masked_fill | ||
|
||
### [torch.Tensor.masked_fill](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_fill.html?highlight=masked_fill#torch.Tensor.masked_fill) | ||
|
||
```python | ||
torch.Tensor.masked_fill(mask, value) | ||
``` | ||
|
||
torch 是类成员方式,paddle 无 masked_fill 函数,需要组合实现。 | ||
|
||
### 转写示例 | ||
### [paddle.Tensor.masked_fill](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#masked-fill-mask-value-name-non) | ||
|
||
```python | ||
# torch 写法 | ||
x.masked_fill(mask, value) | ||
|
||
# paddle 写法 | ||
out = paddle.full(x.shape, value, x.dtype) | ||
x = paddle.where(mask, out, x) | ||
paddle.Tensor.masked_fill(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_fill_ | ||
|
||
### [torch.Tensor.masked_fill_](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_fill_.html?highlight=masked_fill_#torch.Tensor.masked_fill_) | ||
|
||
```python | ||
torch.Tensor.masked_fill_(mask, value) | ||
``` | ||
|
||
### [paddle.Tensor.masked_fill_]() | ||
|
||
```python | ||
paddle.Tensor.masked_fill_(mask, value, name=None) | ||
``` | ||
|
||
两者功能一致,参数完全一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
|---------|--------------| -------------------------------------------------- | | ||
| mask | mask | 布尔张量,表示要填充的位置 | | ||
| value | value | 用于填充目标张量的值 | |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -630,7 +630,7 @@ | |||||
| 13 | [torch.Tensor.int](https://pytorch.org/docs/stable/generated/torch.Tensor.int.html?highlight=int#torch.Tensor.int) | [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#astype-dtype) | 功能一致,torch 参数更多, [差异对比](https://github.com/PaddlePaddle/docs/blob/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.int.md) | | ||||||
| 14 | [torch.Tensor.sigmoid](https://pytorch.org/docs/stable/generated/torch.Tensor.sigmoid.html?highlight=torch+sigmoid#torch.Tensor.sigmoid) | [paddle.nn.functional.sigmoid](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/sigmoid_cn.html) | 功能完全一致。 | | ||||||
| 15 | [torch.Tensor.copy_](https://pytorch.org/docs/stable/generated/torch.Tensor.copy_.html?highlight=copy_#torch.Tensor.copy_) | [paddle.assign](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/assign_cn.html#assign) | 功能一致,torch 参数更多, [差异对比](https://github.com/PaddlePaddle/docs/blob/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.copy_.md) | | ||||||
| 16 | [torch.Tensor.masked_fill](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_fill.html?highlight=masked_fill#torch.Tensor.masked_fill) | [paddle 实现](https://www.paddlepaddle.org.cn/documentation/docs/zh/faq/train_cn.html#paddle-torch-masked-fill-api) | 功能一致,paddle 需组合实现, [差异对比](https://github.com/PaddlePaddle/docs/blob/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_fill.md) | | ||||||
| 16 | [torch.Tensor.masked_fill](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_fill.html?highlight=masked_fill#torch.Tensor.masked_fill) | [paddle.Tensor.masked_fill](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#masked-fill-mask-value-name-none) | 功能完全一致 | | ||||||
|
| 16 | [torch.Tensor.masked_fill](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_fill.html?highlight=masked_fill#torch.Tensor.masked_fill) | [paddle.Tensor.masked_fill](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#masked-fill-mask-value-name-none) | 功能完全一致 | | |
| 16 | [torch.Tensor.masked_fill](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_fill.html?highlight=masked_fill#torch.Tensor.masked_fill) | [paddle.Tensor.masked_fill](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#masked-fill-x-mask-value-name-none) | 功能完全一致 | |
Outdated
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.
为啥这是功能缺失? paddle.masked_fill_
不是实现了吗
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.
为啥这是功能缺失?
paddle.masked_fill_
不是实现了吗
改漏了 ┭┮﹏┭┮,已修改
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.
Tensor_cn.rst 里写的简单一点吧,就是简单介绍,参数和代码示例就不用放上来了,然后最后加上 请参考xxxxx