Skip to content

新增local_map API的中文文档 #7245

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

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open

Conversation

zty-king
Copy link
Contributor

@zty-king zty-king commented Apr 8, 2025

No description provided.

Copy link

paddle-bot bot commented Apr 8, 2025

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

Comment on lines 76 to 95
方法
:::::::::

wrapped_func()
'''''''''

包装后返回的函数。该函数会:

1. 将输入的分布式张量转换为本地张量
2. 在本地执行函数计算
3. 将计算结果按照指定的分布策略转换回分布式张量

**参数**

- **args** (Any) - 位置参数,通常包含分布式张量
- **kwargs** (Any) - 额外的关键字参数

**返回**

按照 out_placements 指定的分布策略转换后的分布式张量
Copy link
Contributor

Choose a reason for hiding this comment

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

local_map is a API of function that does not need to describe methods, only API of class need to describe member methods in the class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@jeff41404 jeff41404 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.

另外,在 paddle/distributed/Overview 的总览里加上该 API 的引用

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

.. code-block:: python
Copy link
Collaborator

Choose a reason for hiding this comment

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

中文示例代码统一用 COPY-FROM: paddle.xxx 的形式,xxx 为 API 的调用路径,目的为和英文代码保持一致

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 16 to 18
- **in_placements** (list[list[dist.Placement]] | None) - 指定输入张量的要求分布。如果指定,每个内层列表描述对应输入张量的分布要求。外层列表长度必须与输入张量数量匹配。对于不具有分布式属性的输入应设为 None,默认为 None
- **process_mesh** (Optional[ProcessMesh]) - 计算设备网格。所有分布式张量必须位于同一个 process_mesh 上。如未指定则从输入张量推断
- **reshard_inputs** (bool) - 当输入分布式张量的分布方式与要求的 in_placements 不匹配时,是否自动重分布。默认 False
Copy link
Collaborator

Choose a reason for hiding this comment

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

参考 API 参数写法

  • 可选参数应该写为如 in_placements (list[list[dist.Placement]],可选) 的形式
  • 标点符号注意,都需要为中文标点符号。 输入应设为 None,默认为 None 中间用的是英文,修改一下。另外结尾的句号都不要忘记
  • 对于每个可选参数们都要说明:1. 默认值是什么 2. 默认值的含义。 像 process_mesh 就没说默认值和默认值的含义

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@SigureMo SigureMo Apr 15, 2025

Choose a reason for hiding this comment

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

可选参数应该写为如 in_placements (list[list[dist.Placement]],可选) 的形式

不懂不要乱说啊,类型提示的 Optional 和这里的可选语义完全不一样

类型提示里的 Optional[T] 代表输入类型可以是 T 或者 None,现代语法更常用的是 T | None

可选参数指参数有默认值

两者没有强关联性!

def fn1(x: int): ... # 类型只能是 int
def fn2(x: int | None): ... # 类型可以是 int | None,注意不是可选参数,因为没有默认值
def fn3(x: int = 1): ... # 类型只能是 int,有默认值,即可选参数
def fn4(x: int | None = None): ... # 类型可以是 int | None,同时是可选参数,默认值为 None

Copy link
Collaborator

@sunzhongkai588 sunzhongkai588 Apr 16, 2025

Choose a reason for hiding this comment

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

@SigureMo 我看源码对应的类型提示 in_placements: list[list[dist.Placement]] | None = None 不是可选参数么

Copy link
Member

Choose a reason for hiding this comment

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

之前并不是,这是昨天刚改的

Copy link
Member

Choose a reason for hiding this comment

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

而且 list[list[dist.Placement]] | None 是类型提示,= None 不是类型提示

Copy link
Collaborator

Choose a reason for hiding this comment

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

一师傅回的好快。所以这里应该改为 in_placements (list[list[dist.Placement]] | None,可选) 是么

Copy link
Member

Choose a reason for hiding this comment

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

可以这样

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants