Skip to content
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.28】为 Paddle 新增 slice_scatter API #6409

Merged
merged 3 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api/paddle/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ tensor 元素操作相关(如:转置,reshape 等)
" :ref:`paddle.scatter_nd_add <cn_api_paddle_scatter_nd_add>` ", "通过对 Tensor 中的单个值或切片应用稀疏加法,从而得到输出的 Tensor"
" :ref:`paddle.shard_index <cn_api_paddle_shard_index>` ", "根据分片(shard)的偏移量重新计算分片的索引"
" :ref:`paddle.slice <cn_api_paddle_slice>` ", "沿多个轴生成 input 的切片"
" :ref:`paddle.slice_scatter <cn_api_paddle_slice_scatter>` ", "沿着 axes 将 value 矩阵的值嵌入到 x 矩阵"
" :ref:`paddle.split <cn_api_paddle_split>` ", "将输入 Tensor 分割成多个子 Tensor"
" :ref:`paddle.tensor_split <cn_api_paddle_tensor_split>` ", "将输入 Tensor 分割成多个子 Tensor,允许不等分"
" :ref:`paddle.hsplit <cn_api_paddle_hsplit>` ", "将输入 Tensor 沿第零个维度分割成多个子 Tensor"
Expand Down
11 changes: 11 additions & 0 deletions docs/api/paddle/Tensor_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3165,6 +3165,17 @@ select_scatter(x, values, axis, index, name=None)

请参考 :ref:`cn_api_paddle_select_scatter`

slice_scatter(value, axes, starts, ends, strides, name=None)
:::::::::

沿着 `axes` 将 `value` 矩阵的值嵌入到 `x` 矩阵。返回一个新的 Tensor 而不是视图。

返回:计算后的 Tensor

返回类型:Tensor

请参考 :ref:`cn_api_paddle_slice_scatter`

signbit(x, name=None)
:::::::::

Expand Down
28 changes: 28 additions & 0 deletions docs/api/paddle/slice_scatter_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. _cn_api_paddle_slice_scatter:

slice_scatter
-------------------------------

.. py:function:: paddle.slice_scatter(x, value, axes, starts, ends, strides, name=None)

沿着 `axes` 将 `value` 矩阵的值嵌入到 `x` 矩阵。返回一个新的 Tensor 而不是视图。 `axes` 需要与 `starts`, `ends` 和 `strides` 尺寸一致。

参数
:::::::::
- **x** (Tensor) - 输入的 Tensor 作为目标矩阵,数据类型为: `bool`、 `float16`、 `float32`、 `float64`、 `uint8`、 `int8`、 `int16`、 `int32`、 `int64`、 `bfloat16`、 `complex64`、 `complex128`。
- **value** (Tensor) - 需要插入的值,数据类型为: `bool`、 `float16`、 `float32`、 `float64`、 `uint8`、 `int8`、 `int16`、 `int32`、 `int64`、 `bfloat16`、 `complex64`、 `complex128`。
- **axes** (list|tuple) - 指定沿着哪几个维度嵌入对应的值。
- **starts** (list|tuple) - 嵌入的起始索引。
- **ends** (list|tuple) - 嵌入的截止索引。
- **strides** (list|tuple) - 嵌入的步长。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 `None`。

返回
:::::::::

Tensor, 与 ``x`` 数据类型与形状相同。

代码示例
:::::::::

COPY-FROM: paddle.slice_scatter
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## [ 参数不一致 ]torch.Tensor.slice_scatter

### [torch.Tensor.slice_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.slice_scatter.html#torch-tensor-slice-scatter)

```python
Tensor.slice_scatter(src, dim=0, start=None, end=None, step=1)
```

### [paddle.Tensor.slice_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#slice_scatter-value-axes-starts-ends-strides-name-none)

```python
Tensor.slice_scatter(value, axes, starts, ends, strides, name=None)
```

两者功能一致,参数不一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| src | value | 嵌入的值,仅参数名不一致。 |
| dim | axes | 嵌入的维度,PyTorch 为 int 类型,Paddle 为 list of int。 |
| start | starts | 嵌入起始索引,PyTorch 为 int 类型,Paddle 为 list of int。 |
| end | ends | 嵌入截至索引,PyTorch 为 int 类型,Paddle 为 list of int。 |
| step | strides | 嵌入步长,PyTorch 为 int 类型,Paddle 为 list of int。 |

### 转写示例

```python
# Pytorch 写法
x.slice_scatter(src, dim=0, start=1, end=5, step=2)

# Paddle 写法
x.slice_scatter(value, axes=[0], starts=[1], ends=[5], strides=[2])
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## [ 参数不一致 ]torch.Tensor.slice_scatter

### [torch.slice_scatter](https://pytorch.org/docs/stable/generated/torch.slice_scatter.html#torch.slice_scatter)

```python
torch.slice_scatter(input, src, dim=0, start=None, end=None, step=1)
```

### [paddle.slice_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/slice_scatter.html)

```python
paddle.slice_scatter(x, value, axes, starts, ends, strides, name=None)
```

两者功能一致,参数不一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的目标矩阵, 仅参数名不一致。 |
| src | value | 嵌入的值,仅参数名不一致。 |
| dim | axes | 嵌入的维度,PyTorch 为 int 类型,Paddle 为 list of int。 |
| start | starts | 嵌入起始索引,PyTorch 为 int 类型,Paddle 为 list of int。 |
| end | ends | 嵌入截至索引,PyTorch 为 int 类型,Paddle 为 list of int。 |
| step | strides | 嵌入步长,PyTorch 为 int 类型,Paddle 为 list of int。 |

### 转写示例

```python
# Pytorch 写法
torch.slice_scatter(input, src, dim=0, start=1, end=5, step=2)

# Paddle 写法
paddle.slice_scatter(x, value, axes=[0], starts=[1], ends=[5], strides=[2])
```
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
| NOT-IMPLEMENTED-ITEM(`torch.bitwise_right_shift`, https://pytorch.org/docs/stable/generated/torch.bitwise_right_shift.html#torch.bitwise_right_shift) |
| NOT-IMPLEMENTED-ITEM(`torch.is_conj`, https://pytorch.org/docs/stable/generated/torch.is_conj.html#torch.is_conj) |
| NOT-IMPLEMENTED-ITEM(`torch.select_scatter`, https://pytorch.org/docs/stable/generated/torch.select_scatter.html#torch.select_scatter) |
| NOT-IMPLEMENTED-ITEM(`torch.slice_scatter`, https://pytorch.org/docs/stable/generated/torch.slice_scatter.html#torch.slice_scatter) |
| REFERENCE-MAPPING-ITEM(`torch.slice_scatter`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.slice_scatter.md) |
| NOT-IMPLEMENTED-ITEM(`torch.scatter_reduce`, https://pytorch.org/docs/stable/generated/torch.scatter_reduce.html#torch.scatter_reduce) |
| NOT-IMPLEMENTED-ITEM(`torch.set_deterministic_debug_mode`, https://pytorch.org/docs/stable/generated/torch.set_deterministic_debug_mode.html#torch.set_deterministic_debug_mode) |
| NOT-IMPLEMENTED-ITEM(`torch.get_deterministic_debug_mode`, https://pytorch.org/docs/stable/generated/torch.get_deterministic_debug_mode.html#torch.get_deterministic_debug_mode) |
Expand Down Expand Up @@ -798,7 +798,7 @@
| 170 | [torch.Tensor.diagonal_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.diagonal_scatter.html#torch.Tensor.diagonal_scatter) | [paddle.Tensor.diagonal_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#diagonal-scatter-x-y-offset-0-axis1-0-axis2-1-name-none) | 功能完全一致,仅参数名不一致 [差异对比](https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagonal_scatter.md) |
| 171 | [torch.Tensor.scatter_reduce](https://pytorch.org/docs/stable/generated/torch.Tensor.scatter_reduce.html#torch.Tensor.scatter_reduce) | | 功能缺失 |
| 172 | [torch.Tensor.select_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.select_scatter.html#torch.Tensor.select_scatter) | | 功能缺失 |
| 173 | [torch.Tensor.slice_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.slice_scatter.html#torch.Tensor.slice_scatter) | | 功能缺失 |
| 173 | [torch.Tensor.slice_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.slice_scatter.html#torch.Tensor.slice_scatter) | [paddle.Tensor.slice_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#slice_scatter-value-axis-0-start-none-stop-none-step-1-name-none) | 功能完全一致,仅参数名不一致 [差异对比](https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.slice_scatter.md) |
| 174 | [torch.Tensor.hsplit](https://pytorch.org/docs/stable/generated/torch.Tensor.hsplit.html#torch.Tensor.hsplit) | [paddle.Tensor.hsplit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#hsplit-num-or-sections-name-none) | 功能完全一致,仅参数名不一致 [差异对比](https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hsplit.md) |
| 175 | [torch.Tensor.vsplit](https://pytorch.org/docs/stable/generated/torch.Tensor.vsplit.html#torch.Tensor.vsplit) | [paddle.Tensor.vsplit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#vsplit-num-or-sections-name-none) | 功能完全一致,仅参数名不一致 [差异对比](https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.vsplit.md) |
| 176 | [torch.Tensor.dsplit](https://pytorch.org/docs/stable/generated/torch.Tensor.dsplit.html#torch.Tensor.dsplit) | [paddle.Tensor.dsplit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#dsplit-num-or-sections-name-none) | 功能完全一致,仅参数名不一致 [差异对比](https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dsplit.md) |
Expand Down Expand Up @@ -1108,7 +1108,7 @@
| NOT-IMPLEMENTED-ITEM(`torch.Tensor.is_conj`, https://pytorch.org/docs/stable/generated/torch.Tensor.is_conj.html#torch.Tensor.is_conj) |
| NOT-IMPLEMENTED-ITEM(`torch.Tensor.scatter_reduce`, https://pytorch.org/docs/stable/generated/torch.Tensor.scatter_reduce.html#torch.Tensor.scatter_reduce) |
| NOT-IMPLEMENTED-ITEM(`torch.Tensor.select_scatter`, https://pytorch.org/docs/stable/generated/torch.Tensor.select_scatter.html#torch.Tensor.select_scatter) |
| NOT-IMPLEMENTED-ITEM(`torch.Tensor.slice_scatter`, https://pytorch.org/docs/stable/generated/torch.Tensor.slice_scatter.html#torch.Tensor.slice_scatter) |
| REFERENCE-MAPPING-ITEM(`torch.Tensor.slice_scatter`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.slice_scatter.md) |
| REFERENCE-MAPPING-ITEM(`torch.Tensor.hsplit`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hsplit.md) |
| REFERENCE-MAPPING-ITEM(`torch.Tensor.vsplit`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.vsplit.md) |
| REFERENCE-MAPPING-ITEM(`torch.Tensor.dsplit`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dsplit.md) |
Expand Down