Skip to content

[Auto-Parallel] add fully_shard - #76868

Merged
Xing-lil merged 12 commits into
PaddlePaddle:developfrom
Xing-lil:add_fully_shard
Dec 19, 2025
Merged

Xing-lil merged 12 commits into
PaddlePaddle:developfrom
Xing-lil:add_fully_shard

Conversation

@Xing-lil

@Xing-lil Xing-lil commented Dec 11, 2025 •

Copy link
Copy Markdown
Contributor

PR Category

Auto Parallel

PR Types

Others

Description

添加FSDP接口fully_shard,动手/动半统一接口,model = fully_shard(model, ...)
具体实现逻辑:#76770
card-92763

@paddle-bot

paddle-bot Bot commented Dec 11, 2025

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册。
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

offload_policy,
ignored_params,
):
FullyShardAuto(module, mesh)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这里需要返回 model

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已修改,感谢!

@codecov-commenter

codecov-commenter commented Dec 18, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@2e6ae14). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #76868   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         3           
  Lines              ?        32           
  Branches           ?         0           
===========================================
  Hits               ?        32           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +74 to +84
def fully_shard(
module: paddle.nn.Layer,
*,
mesh: dist.ProcessMesh = None,
reshard_after_forward: bool | int | None = None,
shard_placement_fn: Callable[[paddle.Tensor], dist.Shard | None]
| None = None,
mp_policy: MixedPrecisionPolicy | None = None,
offload_policy: OffloadPolicy | None = None,
ignored_params: Iterable[paddle.Tensor] | None = None,
) -> paddle.nn.Layer:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

注意增加文档

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已补充文档,感谢

from .group_sharded import group_sharded_parallel, save_group_sharded_model

__all__ = ['group_sharded_parallel', 'save_group_sharded_model']
__all__ = ['group_sharded_parallel', 'save_group_sharded_model', "fully_shard"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

建议用户使用的路径是paddle.distributed.sharding.fully_shard 么?是否增加别名兼容业界?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已修改fully_shard路径,感谢

@liym27 liym27 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1、接口:paddle.distributed.fsdp.fully_shard
2、api 文档

@jeff41404 jeff41404 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@SigureMo SigureMo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

发版相关,可以在下个 PR 处理

Comment on lines +18 to +22
if TYPE_CHECKING:
from collections.abc import Iterable

import paddle
import paddle.distributed as dist

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

放在 27 行之后,不要让 TYPE_CHECKING 把 import 分隔开

)


# @dataclass

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个注释能删掉吗?

cast_forward_inputs: bool = True


# @dataclass

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

同上

Comment on lines +79 to +80
shard_placement_fn: Callable[[paddle.Tensor], dist.Shard | None]
| None = None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
shard_placement_fn: Callable[[paddle.Tensor], dist.Shard | None]
| None = None,
shard_placement_fn: (Callable[[paddle.Tensor], dist.Shard | None]
| None = None),

这里格式化的优点难看,试试包一个括号再重新格式化呢?

Examples:
.. code-block:: python

>>> # type: ignore

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

去掉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

好的,感谢

@Xing-lil
Xing-lil merged commit 366098e into PaddlePaddle:develop Dec 19, 2025
91 of 96 checks passed
@Xing-lil Xing-lil mentioned this pull request Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants