From 0dbf5021c4c27aff433529da9ce3061a25c78923 Mon Sep 17 00:00:00 2001 From: inaomIIsFarell <1344594208@qq.com> Date: Wed, 31 Jul 2024 16:01:09 +0800 Subject: [PATCH 1/4] [Typing][C-91]Add annotation for 'python/paddle/incubate/operators/softmax_mask_fuse.py' --- python/paddle/incubate/operators/softmax_mask_fuse.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/paddle/incubate/operators/softmax_mask_fuse.py b/python/paddle/incubate/operators/softmax_mask_fuse.py index ba92e96d408e1..dc412bcda16bb 100644 --- a/python/paddle/incubate/operators/softmax_mask_fuse.py +++ b/python/paddle/incubate/operators/softmax_mask_fuse.py @@ -11,13 +11,19 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + +from typing import TYPE_CHECKING from paddle import _C_ops from paddle.base.layer_helper import LayerHelper from paddle.framework import in_dynamic_or_pir_mode +if TYPE_CHECKING: + from paddle import Tensor + -def softmax_mask_fuse(x, mask, name=None): +def softmax_mask_fuse(x: Tensor, mask: Tensor, name: str | None = None) -> Tensor: """ Do a masked softmax on x. From 87dbe039389d92451e34f1fff236b680826b7edb Mon Sep 17 00:00:00 2001 From: inaomIIsFarell <1344594208@qq.com> Date: Wed, 31 Jul 2024 16:05:46 +0800 Subject: [PATCH 2/4] [Typing][C-92]Add annotation for 'python/paddle/incubate/operators/softmax_mask_fuse_upper_triangle.py' --- .../operators/softmax_mask_fuse_upper_triangle.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/paddle/incubate/operators/softmax_mask_fuse_upper_triangle.py b/python/paddle/incubate/operators/softmax_mask_fuse_upper_triangle.py index 2d742301e7e92..0a92cfb80f353 100644 --- a/python/paddle/incubate/operators/softmax_mask_fuse_upper_triangle.py +++ b/python/paddle/incubate/operators/softmax_mask_fuse_upper_triangle.py @@ -11,13 +11,19 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + +from typing import TYPE_CHECKING from paddle import _C_ops from paddle.base.layer_helper import LayerHelper from paddle.framework import in_dynamic_or_pir_mode +if TYPE_CHECKING: + from paddle import Tensor + -def softmax_mask_fuse_upper_triangle(x): +def softmax_mask_fuse_upper_triangle(x: Tensor) -> Tensor: """ Do a masked softmax on x, which will always mask upper triangle part of x. From e24b14f7ddb852f9b566544027e343c30f9f0f44 Mon Sep 17 00:00:00 2001 From: inaomIIsFarell <1344594208@qq.com> Date: Wed, 31 Jul 2024 18:30:19 +0800 Subject: [PATCH 3/4] =?UTF-8?q?[Typing][C-91]Add=20annotation=20for=20'pyt?= =?UTF-8?q?hon/paddle/incubate/operators/so=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/paddle/incubate/operators/softmax_mask_fuse.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/paddle/incubate/operators/softmax_mask_fuse.py b/python/paddle/incubate/operators/softmax_mask_fuse.py index dc412bcda16bb..b59789894431d 100644 --- a/python/paddle/incubate/operators/softmax_mask_fuse.py +++ b/python/paddle/incubate/operators/softmax_mask_fuse.py @@ -23,7 +23,9 @@ from paddle import Tensor -def softmax_mask_fuse(x: Tensor, mask: Tensor, name: str | None = None) -> Tensor: +def softmax_mask_fuse( + x: Tensor, mask: Tensor, name: str | None = None +) -> Tensor: """ Do a masked softmax on x. From 1bbd8f9bfc116fd276b809569c15997d70b2d3d6 Mon Sep 17 00:00:00 2001 From: inaomIIsFarell <1344594208@qq.com> Date: Thu, 1 Aug 2024 14:58:09 +0800 Subject: [PATCH 4/4] [Typing][C-91, C-92] Add annotations for python/paddle/incubate/operators/{softmax_mask_fuse, softmax_mask_fuse_upper_triangle}.py --- python/paddle/incubate/operators/softmax_mask_fuse.py | 2 +- .../incubate/operators/softmax_mask_fuse_upper_triangle.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/paddle/incubate/operators/softmax_mask_fuse.py b/python/paddle/incubate/operators/softmax_mask_fuse.py index b59789894431d..4a1df93001fff 100644 --- a/python/paddle/incubate/operators/softmax_mask_fuse.py +++ b/python/paddle/incubate/operators/softmax_mask_fuse.py @@ -60,7 +60,7 @@ def softmax_mask_fuse( >>> x = paddle.rand([2, 8, 8, 32]) >>> mask = paddle.rand([2, 1, 8, 32]) - >>> rst = incubate.softmax_mask_fuse(x, mask) + >>> rst = incubate.softmax_mask_fuse(x, mask) # type: ignore[operator] >>> rst.shape [2, 8, 8, 32] """ diff --git a/python/paddle/incubate/operators/softmax_mask_fuse_upper_triangle.py b/python/paddle/incubate/operators/softmax_mask_fuse_upper_triangle.py index 0a92cfb80f353..b06c981a8978f 100644 --- a/python/paddle/incubate/operators/softmax_mask_fuse_upper_triangle.py +++ b/python/paddle/incubate/operators/softmax_mask_fuse_upper_triangle.py @@ -57,7 +57,7 @@ def softmax_mask_fuse_upper_triangle(x: Tensor) -> Tensor: >>> paddle.set_device("gpu") >>> x = paddle.rand((1, 1, 32, 32)) - >>> rst = incubate.softmax_mask_fuse_upper_triangle(x) + >>> rst = incubate.softmax_mask_fuse_upper_triangle(x) # type: ignore[operator] >>> print(rst) Tensor(shape=[1, 1, 32, 32], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[[[1. , 0. , 0. , ..., 0. ,