Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/api/paddle/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ tensor 数学操作原位(inplace)版本
" :ref:`paddle.uniform_ <cn_api_paddle_uniform_>` ", "Inplace 版本的 uniform API,对输入 x 采用 Inplace 策略"
" :ref:`paddle.lerp_ <cn_api_paddle_lerp_>` ", "Inplace 版本的 lerp API,对输入 x 采用 Inplace 策略"
" :ref:`paddle.hypot_ <cn_api_paddle_hypot_>` ", "Inplace 版本的 hypot API,对输入 x 采用 Inplace 策略"
" :ref:`paddle.masked_fill_ <cn_api_paddle_masked_fill_>` ", "Inplace 版本的 masked_fill API,对输入 x 采用 Inplace 策略"

.. _tensor_logic:

Expand Down Expand Up @@ -384,6 +385,7 @@ tensor 元素操作相关(如:转置,reshape 等)
" :ref:`paddle.view <cn_api_paddle_view>` ", "使用特定的 shape 或者 dtype,返回 x 的一个 view Tensor"
" :ref:`paddle.view_as <cn_api_paddle_view_as>` ", "使用 other 的 shape,返回 x 的一个 view Tensor"
" :ref:`paddle.unfold <cn_api_paddle_unfold>` ", "返回 x 的一个 view Tensor。以滑动窗口式提取 x 的值"
" :ref:`paddle.masked_fill <cn_api_paddle_masked_fill>` ", "根据 mask 信息,将 value 中的值填充到 x 中 mask 对应为 True 的位置。"

.. _tensor_manipulation_inplace:

Expand Down
13 changes: 13 additions & 0 deletions docs/api/paddle/Tensor_cn.rst
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tensor_cn.rst 里写的简单一点吧,就是简单介绍,参数和代码示例就不用放上来了,然后最后加上 请参考xxxxx

Original file line number Diff line number Diff line change
Expand Up @@ -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 策略。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Inplace 版本的 :ref:`_cn_api_paddle_masked_fill` API,对输入 `x` 采用 Inplace 策略。
Inplace 版本的 :ref:`cn_api_paddle_masked_fill` API,对输入 `x` 采用 Inplace 策略。

11 changes: 11 additions & 0 deletions docs/api/paddle/masked_fill__cn.rst
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 策略。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Inplace 版本的 :ref:`cn_api_paddle_add` API,对输入 x 采用 Inplace 策略。
Inplace 版本的 :ref:`cn_api_paddle_masked_fill` 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
28 changes: 28 additions & 0 deletions docs/api/paddle/masked_fill_cn.rst
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
Expand Up @@ -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) | 功能完全一致 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| 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) | 功能完全一致 |

| 17 | [torch.Tensor.fill_](https://pytorch.org/docs/stable/generated/torch.Tensor.fill_.html?highlight=fill_#torch.Tensor.fill_) | [paddle.Tensor.fill_](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#fill-x-value-name-none) | 功能完全一致 |
| 18 | [torch.Tensor.unique](https://pytorch.org/docs/stable/generated/torch.Tensor.unique.html?highlight=unique#torch.Tensor.unique) | [paddle.Tensor.unique](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#unique-return-index-false-return-inverse-false-return-counts-false-axis-none-dtype-int64-name-none) | 功能一致,torch 参数更多, [差异对比](https://github.com/PaddlePaddle/docs/blob/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unique.md) |
| 19 | [torch.Tensor.expand](https://pytorch.org/docs/stable/generated/torch.Tensor.expand.html?highlight=expand#torch.Tensor.expand) | [paddle.Tensor.expand](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#expand-shape-name-none) | 功能一致,仅参数名不一致, [差异对比](https://github.com/PaddlePaddle/docs/blob/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expand.md) |
Expand Down Expand Up @@ -919,6 +919,7 @@
| 302 | [torch.Tensor.dequantize](https://pytorch.org/docs/1.13/generated/torch.Tensor.dequantize.html?highlight=torch+tensor+dequantize#torch.Tensor.dequantize) | | 功能缺失 |
| 303 | [torch.Tensor.sum_to_size](https://pytorch.org/docs/stable/generated/torch.Tensor.sum_to_size.html?highlight=sum_to_size#torch.Tensor.sum_to_size) | | 功能缺失 |
| 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_) | | 功能缺失 |
***持续更新...***
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥这是功能缺失? paddle.masked_fill_ 不是实现了吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥这是功能缺失? paddle.masked_fill_ 不是实现了吗

改漏了 ┭┮﹏┭┮,已修改


## torch.nn.init.XX API 映射列表
Expand Down