Skip to content

[Typing][C-52] Add type annotations for python/paddle/distributed/fleet/utils/__init__.py #66771

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

Merged
merged 2 commits into from
Aug 1, 2024

Conversation

megemini
Copy link
Contributor

PR Category

User Experience

PR Types

Improvements

Description

类型标注:

  • python/paddle/distributed/fleet/utils/__init__.py

Related links

@SigureMo @megemini

Copy link

paddle-bot bot commented Jul 30, 2024

你的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.

__all__ = ["LocalFS", "recompute", "DistributedInfer", "HDFSClient"]


def recompute(function, *args, **kwargs):
def recompute(
function: Callable[..., Layer], *args: Tensor, **kwargs: Any
Copy link
Member

Choose a reason for hiding this comment

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

if isinstance(function, paddle.nn.Layer):
dyfunc_sig = inspect.signature(function.forward)
else:
dyfunc_sig = inspect.signature(function)

来看,这里 function 应该就是 Layer 或者 Callable?或者简单说就是 Callable

Copy link
Contributor Author

@megemini megemini Jul 31, 2024

Choose a reason for hiding this comment

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

从示例代码来看

            >>> def get_fc_block(block_idx, input_size, is_last=False):
            ...     block_name = "block_" + str(block_idx)
            ...     block = paddle.nn.Sequential(
            ...         (block_name + "_fc_0", paddle.nn.Linear(input_size, input_size, bias_attr=False)),
            ...         (block_name + "_dropout", paddle.nn.Dropout(p=0.5)),
            ...         (block_name + "_relu_1", paddle.nn.ReLU()),
            ...         (block_name + "_fc_1", paddle.nn.Linear(input_size, input_size, bias_attr=False)),
            ...         (block_name + "_relu_2", paddle.nn.ReLU()),
            ...     )
            ...     if is_last:
            ...         block.add_sublayer(
            ...             block_name + "_fc_2",
            ...             paddle.nn.Linear(
            ...                 input_size, 1, bias_attr=False
            ...             )
            ...         )
            ...     else:
            ...         block.add_sublayer(
            ...             block_name + "_fc_2",
            ...             paddle.nn.Linear(input_size, input_size, bias_attr=False)
            ...         )
            ...     return block

Callable[..., Layer] 可以是合理的输入,那改成 Layer | Callable[..., Layer] Layer | Callable[..., Any]?

另外,*args, **kwargs 应该也是任何输入都有可能?那输出也可能是任意的?

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

@luotao1 luotao1 merged commit 75b33e6 into PaddlePaddle:develop Aug 1, 2024
31 checks passed
Lans1ot pushed a commit to Lans1ot/Paddle that referenced this pull request Aug 5, 2024
…eet/utils/__init__.py` (PaddlePaddle#66771)

* [Add] typing

* [Change] typing to Any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants