Skip to content

Commit 5a996de

Browse files
committed
[API-Compat] CN docs for compat.Unfold & compat.split
1 parent f2520b3 commit 5a996de

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed

docs/api/index_cn.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ API 文档
3131
| paddle.callbacks | 日志回调类,包括 ModelCheckpoint、 |
3232
| | ProgBarLogger 等。 |
3333
+--------------------------+------------------------------------------------------------------------------------+
34+
| paddle.compat | PyTorch-compatible function and module interfaces, with identical calling methods and behaviors to their PyTorch counterparts. |
35+
| | 行为都与 PyTorch 对应接口一致 |
36+
+--------------------------+------------------------------------------------------------------------------------+
3437
| paddle.device | 设备管理相关 API,包括 set_device、get_device 等。 |
3538
+--------------------------+------------------------------------------------------------------------------------+
3639
| paddle.distributed | 分布式相关基础 API。 |

docs/api/index_en.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ In this version, PaddlePaddle has made many optimizations to the APIs. You can r
3434
| paddle.callbacks | Paddle log callback APIs, including ModelCheckpoint, |
3535
| | ProgBarLogger, etc. |
3636
+--------------------------+---------------------------------------------------------------+
37+
| paddle.compat | PyTorch-compatible APIs, with identical calling methods |
38+
| | and behaviors to their PyTorch counterparts. |
39+
+--------------------------+---------------------------------------------------------------+
3740
| paddle.device | Device management related APIs, such as set_device, |
3841
| | get_device, etc. |
3942
+--------------------------+---------------------------------------------------------------+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.. _cn_overview_compat:
2+
3+
paddle.compat
4+
---------------------
5+
6+
paddle.compat 目录下包含飞桨框架支持的 PyTorch 兼容函数与模块接口
7+
8+
.. _about_compat_funcs:
9+
10+
PyTorch 兼容函数
11+
::::::::::::::::::::
12+
13+
.. csv-table::
14+
:header: "API 名称", "API 功能"
15+
:widths: 10, 30
16+
17+
" :ref:`split <cn_api_paddle_compat_split>` ", "允许非整除块大小输入的 Tensor 轴向切分"
18+
19+
20+
.. _about_compat_class:
21+
22+
PyTorch 兼容模块
23+
::::::::::::::::::::
24+
25+
.. csv-table::
26+
:header: "类名称", "类功能"
27+
:widths: 10, 30
28+
29+
" :ref:`Unfold <cn_api_paddle_compat_Unfold>` ", "允许 Tensor 输入的 ``paddle.nn.Unfold`` 兼容版本"

docs/api/paddle/compat/Unfold_cn.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
.. _cn_api_paddle_compat_Unfold:
2+
3+
Unfold
4+
-------------------------------
5+
6+
.. py:class:: paddle.compat.Unfold(kernel_size, dilation=1, padding=0, stride=1)
7+
8+
9+
PyTorch 兼容的 :ref:`cn_api_paddle_nn_Unfold` 版本:
10+
- 关键字参数使用单数形式(例如:``kernel_size`` 而非 kernel_sizes)
11+
- ``padding`` 仅支持输入长度为 1(整数)或 2 的列表,禁止使用 Size4 格式。如需更灵活的输入版本,请使用 :ref:`cn_api_paddle_nn_Unfold`
12+
- 所有输入参数支持 ``Tensor`` 或 ``pir.Value`` 类型(将自动转换为列表)
13+
- 其他特性与 :ref:`cn_api_paddle_nn_Unfold` 完全一致
14+
15+
使用前请详细参考:`【仅参数名不一致】torch.nn.Unfold`_ 以确定是否使用此模块。
16+
17+
.. _【仅参数名不一致】torch.nn.Unfold: https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Unfold.html
18+
19+
**样例**:
20+
21+
::
22+
23+
Given:
24+
x.shape = [5, 10, 25, 25]
25+
kernel_size = [3, 3]
26+
stride = 1
27+
padding = 1
28+
29+
Return:
30+
out.shape = [5, 90, 625]
31+
32+
功能说明
33+
:::::::::::
34+
实现卷积中的 im2col 操作,将卷积核覆盖区域的元素重排列为列向量。输入形状为 [N, C, H, W] 的 ``x`` 将输出形状为 [N, Cout, Lout] 的张量。
35+
36+
37+
参数
38+
:::::::::::
39+
40+
- **kernel_size** (int|list|tuple|Tensor) - 卷积核尺寸。接受 ``[k_h, k_w]`` 或整数 ``k``(视为 ``[k, k]``)
41+
- **dilation** (int|list|tuple|Tensor, 可选) - 卷积膨胀系数。接受单整数或 ``[dilation_h, dilation_w]``。单整数 ``dilation`` 视为 ``[dilation, dilation]``。默认为 1
42+
- **padding** (int|list|tuple|Tensor, 可选) - 各维度填充大小。接受单整数或 ``[padding_h, padding_w]``。``[padding_h, padding_w]`` 将扩展为 ``[padding_h, padding_w, padding_h, padding_w]``。单整数 ``padding`` 将转为 ``[padding, padding, padding, padding]``。默认为 0
43+
- **stride** (int|list|tuple|Tensor, 可选) - 滑动步长。接受单整数或 ``[stride_h, stride_w]``。单整数 ``stride`` 视为 ``[stride, stride]``。默认为 1
44+
45+
形状
46+
:::::::::
47+
- **输入** : 4-D Tensor,形状为[N, C, H, W],数据类型为 float32 或者 float64
48+
- **输出**:形状如上面所描述的[N, Cout, Lout],Cout 每一个滑动 block 里面覆盖的元素个数,Lout 是滑动 block 的个数,数据类型与 ``x`` 相同
49+
50+
51+
代码示例
52+
::::::::::::
53+
54+
COPY-FROM: paddle.compat.Unfold

docs/api/paddle/compat/split_cn.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.. _cn_api_paddle_compat_split:
2+
3+
split
4+
-------------------------------
5+
6+
.. py:function:: paddle.compat.split(tensor, split_size_or_sections, dim=0)
7+
8+
9+
PyTorch 兼容的 :ref:`cn_api_paddle_split` 版本,允许了非整除的 ``split_size_or_sections`` 输入
10+
11+
使用前请详细参考:`【输入参数用法不一致】torch.split`_ 以确定是否使用此模块。
12+
13+
.. _【输入参数用法不一致】torch.split: https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.split.html
14+
15+
.. note::
16+
此 API 遵循 `torch.split`` 的函数签名和行为以实现 PyTorch 兼容。
17+
如需使用 Paddle 原生实现,请参考 :ref:`cn_api_paddle_split`
18+
19+
参数
20+
:::::::::
21+
- **tensor** (Tensor) - 输入 N 维 Tensor,支持 bool、bfloat16、float16、float32、float64、uint8、int8、int32 或 int64 数据类型
22+
- **split_size_or_sections** (int|list|tuple) - 若为整数,则将 Tensor 均匀分割为指定大小的块,与 :ref:`cn_api_paddle_split` 不同,本 API 不要求此参数整除对应维度的通道数:非整除情况下输出元组的最后一个 tensor 对应维度将为余数大小,小于此值。若为列表/元组,则按指定尺寸分割,禁止使用负值(例如对 9 通道的维度,``[2,3,-1]`` 会被拒绝)
23+
- **dim** (int|Tensor, 可选) - 分割维度,可为整数或形状为[]的 0-D Tensor(数据类型需为 ``int32`` 或 ``int64``)。若 ``dim < 0``,则实际维度为 ``rank(x) + dim``。默认值:0
24+
25+
返回
26+
:::::::::
27+
tuple(Tensor) - 分割后的 Tensor 元组
28+
29+
30+
代码示例
31+
:::::::::
32+
33+
COPY-FROM: paddle.compat.split

0 commit comments

Comments
 (0)