CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
__all__ = ["LocalFS", "recompute", "DistributedInfer", "HDFSClient"] | ||
|
||
|
||
def recompute(function, *args, **kwargs): | ||
def recompute( | ||
function: Callable[..., Layer], *args: Tensor, **kwargs: Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
从
Paddle/python/paddle/distributed/fleet/recompute/recompute.py
Lines 561 to 564 in 8ddfb0a
if isinstance(function, paddle.nn.Layer): | |
dyfunc_sig = inspect.signature(function.forward) | |
else: | |
dyfunc_sig = inspect.signature(function) |
来看,这里 function
应该就是 Layer
或者 Callable
?或者简单说就是 Callable
?
There was a problem hiding this comment.
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
应该也是任何输入都有可能?那输出也可能是任意的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…eet/utils/__init__.py` (PaddlePaddle#66771) * [Add] typing * [Change] typing to Any
PR Category
User Experience
PR Types
Improvements
Description
类型标注:
python/paddle/distributed/fleet/utils/__init__.py
Related links
@SigureMo @megemini