-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Typing][B-42][BUAA] Add type annotations for python/paddle/autograd/py_layer.py
#66328
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/autograd/py_layer.py
Outdated
@@ -52,7 +59,7 @@ class PyLayerContext: | |||
... return grad | |||
""" | |||
|
|||
def save_for_backward(self, *tensors): | |||
def save_for_backward(self, *tensors: list[Tensor]) -> None: |
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 save_for_backward(self, *tensors: list[Tensor]) -> None: | |
def save_for_backward(self, *tensors: Tensor) -> None: |
python/paddle/autograd/py_layer.py
Outdated
@@ -90,7 +97,7 @@ def save_for_backward(self, *tensors): | |||
""" | |||
self.container = tensors | |||
|
|||
def saved_tensor(self): | |||
def saved_tensor(self) -> list[Tensor] | None: |
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 saved_tensor(self) -> list[Tensor] | None: | |
def saved_tensor(self) -> tuple[Tensor, ...]: |
python/paddle/autograd/py_layer.py
Outdated
@@ -122,7 +129,7 @@ def saved_tensor(self): | |||
""" | |||
return self.container | |||
|
|||
def mark_not_inplace(self, *args): | |||
def mark_not_inplace(self, *args: tuple) -> None: |
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 mark_not_inplace(self, *args: tuple) -> None: | |
def mark_not_inplace(self, *args: Tensor) -> None: |
python/paddle/autograd/py_layer.py
Outdated
@@ -163,7 +170,7 @@ def mark_not_inplace(self, *args): | |||
""" | |||
self.not_inplace_tensors = args | |||
|
|||
def mark_non_differentiable(self, *args): | |||
def mark_non_differentiable(self, *args: tuple) -> None: |
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 mark_non_differentiable(self, *args: tuple) -> None: | |
def mark_non_differentiable(self, *args: Tensor) -> None: |
python/paddle/autograd/py_layer.py
Outdated
@@ -203,7 +210,7 @@ def mark_non_differentiable(self, *args): | |||
""" | |||
self.non_differentiable = args | |||
|
|||
def set_materialize_grads(self, value: bool): | |||
def set_materialize_grads(self, value: bool = True) -> None: |
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 set_materialize_grads(self, value: bool = True) -> None: | |
def set_materialize_grads(self, value: bool) -> None: |
不要随便增加或修改默认值 ~
python/paddle/autograd/py_layer.py
Outdated
@@ -322,7 +329,7 @@ class PyLayer(with_metaclass(PyLayerMeta, core.eager.PyLayer, PyLayerContext)): | |||
""" | |||
|
|||
@staticmethod | |||
def forward(ctx, *args, **kwargs): | |||
def forward(ctx, *args: tuple, **kwargs: dict) -> Tensor | list[Tensor]: |
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 forward(ctx, *args: tuple, **kwargs: dict) -> Tensor | list[Tensor]: | |
def forward(ctx: PyLayerContext, *args: Any, **kwargs: Any) -> Tensor | Sequence[Tensor]: |
python/paddle/autograd/py_layer.py
Outdated
@@ -361,7 +368,7 @@ def forward(ctx, *args, **kwargs): | |||
) | |||
|
|||
@staticmethod | |||
def backward(ctx, *args): | |||
def backward(ctx, *args: tuple) -> Tensor | list[Tensor]: |
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 backward(ctx, *args: tuple) -> Tensor | list[Tensor]: | |
def backward(ctx: PyLayerContext, *args: Any) -> Tensor | Sequence[Tensor]: |
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.
收到,感谢
python/paddle/autograd/py_layer.py
有问题可以说,为什么把我的修改覆盖了? |
抱歉抱歉,是我对git操作还不够熟练,可能无意中给覆盖了,下次一定注意 |
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.
PR Category
User Experience
PR Types
Improvements
Description
类型标注:
python/paddle/autograd/py_layer.py
Related links
#65008
@SigureMo @megemini