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

[Docathon][Add API Legend No.26-30]添加tensor_split系列API图例 #6809

Merged
merged 5 commits into from
Aug 12, 2024

Conversation

fufu0615
Copy link
Contributor

@fufu0615 fufu0615 commented Aug 4, 2024

PADDLEPADDLE_PR=66991

PR types
Add api legends

PR changes
Docs

Description
为tensor_split,hsplit,dsplit,vsplit API文档增加图例
(tensor_split文档的示例代码部分有修改,需要等待英文文档pr合并后更新)

对应的英文文档修复为:PaddlePaddle/Paddle#66991

Copy link

paddle-bot bot commented Aug 4, 2024

感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-6809.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html
预览工具的更多说明,请参考:飞桨文档预览工具

@haoyu2022
Copy link
Contributor

@fufu0615 你是用啥画的图啊

@fufu0615
Copy link
Contributor Author

fufu0615 commented Aug 5, 2024

@fufu0615 你是用啥画的图啊

可以直接用网页端 draw.io

Copy link
Collaborator

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

@megemini 可以看一下社区开发者提供的图例和修改的内容是否正确~

@@ -6,8 +6,12 @@ dsplit
.. py:function:: paddle.dsplit(x, num_or_indices, name=None)


``dsplit`` 全称 Depth Split ,即深度分割,将输入 Tensor 沿着深度轴分割成多个子 Tensor,等价于将 :ref:`cn_api_paddle_tensor_split` API 的参数 axis 固定为 2。注意:使用 ``paddle.dsplit`` 进行变换的 Tensor 维度数量必须不少于 3。
Copy link
Collaborator

Choose a reason for hiding this comment

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

@@ -12,7 +12,7 @@ tensor_split
参数
:::::::::
- **x** (Tensor) - 输入变量,数据类型为 bool、bfloat16、float16、float32、float64、uint8、int8、int32、int64 的多维 Tensor,其维度必须大于 0。
- **num_or_indices** (int|list|tuple) - 如果 ``num_or_indices`` 是一个整数 ``n`` ,则 ``x`` 沿 ``axis`` 拆分为 ``n`` 部分。如果 ``x`` 可被 ``n`` 整除,则每个部分都是 ``x.shape[axis]/n`` 。如果 ``x`` 不能被 ``n`` 整除,则第一个 ``intx.shape[axis]%n)`` 分割大小将为 ``intx.shape[axis]/n)+1`` ,其余部分的大小将是 ``intx.shape[axis]/n`` 。如果 ``num_or_indices`` 是整数索引的列表或元组,则在每个索引处沿 ``axis`` 分割 ``x`` 。例如, ``num_or_indices=[2, 4]`` 在 ``axis=0`` 时将沿轴 0 将 ``x`` 拆分为 ``x[:2]`` 、 ``x[2:4]`` 和 ``x[4:]`` 。
- **num_or_indices** (int|list|tuple) - 如果 ``num_or_indices`` 是一个整数 ``n`` ,则 ``x`` 沿 ``axis`` 拆分为 ``n`` 部分。如果 ``x`` 可被 ``n`` 整除,则每个部分都是 ``x.shape[axis]/n`` 。如果 ``x`` 不能被 ``n`` 整除,则第 ``int(x.shape[axis]/n)+1`` 个部分的大小将是 ``int(x.shape[axis]%n)`` ,其余部分的大小将是 ``int(x.shape[axis]/n)`` 。如果 ``num_or_indices`` 是整数索引的列表或元组,则在每个索引处沿 ``axis`` 分割 ``x`` 。例如, ``num_or_indices=[2, 4]`` 在 ``axis=0`` 时将沿轴 0 将 ``x`` 拆分为 ``x[:2]`` 、 ``x[2:4]`` 和 ``x[4:]`` 。
Copy link
Contributor

Choose a reason for hiding this comment

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

这里有点问题,我这里翻译的可能不太好,原文是

the first int(x.shape[axis] % n) sections will have size int(x.shape[axis] / n) + 1

翻译为 则第一个 .... ,应该翻译为 则前 ... 个

参考代码:

In [5]: x = paddle.rand([13])

In [6]: out = paddle.tensor_split(x, 3)

In [7]: out
Out[7]: 
[Tensor(shape=[5], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        [0.40005636, 0.65518010, 0.31436527, 0.23026623, 0.36780968]),
 Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        [0.55613798, 0.12409472, 0.20364396, 0.83700526]),
 Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        [0.03752962, 0.71997887, 0.79592997, 0.49080023])]

In [8]: x = paddle.rand([8])

In [9]: out = paddle.tensor_split(x, 3)

In [10]: out
Out[10]: 
[Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        [0.75365561, 0.43469149, 0.56143743]),
 Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        [0.89418393, 0.64861047, 0.43100974]),
 Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        [0.99590099, 0.27822134])]

In [11]: 13%3
Out[11]: 1

In [12]: 8%3
Out[12]: 2

In [13]: 13//3
Out[13]: 4

In [14]: 8//3
Out[14]: 2
  • 当长度为 13 ,分割 3 份,则前 13%3=1 个的大小为 13//3+1=5,余下 2 份,大小为 13//3=4,即:[5, 4, 4]
  • 当长度为 8,分割 3 份,则前 8%3=2 个的大小为 8//3+1=3,余下 1 份,大小为 8//3=2,即:[3, 3, 2]

因此,如需修改,可以修改一下原文中的翻译,但是,这里修改后的描述有问题,因为

则第 int(x.shape[axis]/n)+1 个部分的大小将是 int(x.shape[axis]%n)

表示只有一个部分,即 int(x.shape[axis]/n)+1int(x.shape[axis]%n) 这样大小,与实际不符。

另外,图例也需要修改。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

了解了,感谢师傅讲解,改完的图例和文档已推送🫡

@@ -22,7 +22,42 @@ tensor_split
list[Tensor],分割后的 Tensor 列表。


代码示例
代码示例 1
Copy link
Contributor

@megemini megemini Aug 7, 2024

Choose a reason for hiding this comment

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

这里分割开了示例代码,paddle 那边也需要同步修改 ~

Comment on lines 10 to 23
``vsplit`` 全称 Vertical Split 即垂直分割,将输入 Tensor 沿着垂直轴分割成多个子 Tensor ,等价于将 :ref:`cn_api_paddle_tensor_split` API 的参数 axis 固定为 0。

当 Tensor 维度数量等于 1 时:

.. image:: ../../images/api_legend/vsplit/vsplit-1.png
:alt: vsplit 图例-1

当 Tensor 维度数量大于 1 时:

.. image:: ../../images/api_legend/vsplit/vsplit-2.png
:alt: vsplit 图例-2
Copy link
Contributor

Choose a reason for hiding this comment

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

vsplit 维度不能小于 2

Copy link
Contributor

@megemini megemini left a comment

Choose a reason for hiding this comment

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

两个问题

  • 如果图例中有中文,那么英文文档怎么办?可以考虑去掉中文文字说明,或者中英文各一份
  • vsplit 的问题没修改吧?

Copy link
Contributor

@megemini megemini left a comment

Choose a reason for hiding this comment

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

image

最后一个维度不对 ~

@fufu0615
Copy link
Contributor Author

fufu0615 commented Aug 8, 2024

image

最后一个维度不对 ~

抱歉没注意到,已经重新推送了orz

@fufu0615 fufu0615 requested a review from megemini August 8, 2024 09:59
Copy link
Contributor

@megemini megemini left a comment

Choose a reason for hiding this comment

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

LGTM ~

Copy link
Collaborator

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

LGTM~

@luotao1 luotao1 merged commit b5ca07d into PaddlePaddle:develop Aug 12, 2024
2 checks passed
@sunzhongkai588 sunzhongkai588 changed the title [Docathon][Add API Legend No.26~30]添加tensor_split系列API图例 [Docathon][Add API Legend No.26-30]添加tensor_split系列API图例 Aug 19, 2024
Aoraki-Dream pushed a commit to Aoraki-Dream/docs that referenced this pull request Sep 4, 2024
…e#6809)

* 修改tensor_split文档描述并增加图例

* 修改hsplit文档描述并增加图例

* 修改dsplit文档描述并增加图例

* 修改vsplit文档描述并增加图例

* 修改代码块引用和图例参数注释
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants