Skip to content
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][C-73] Add type annotations for python/paddle/incubate/nn/functional/fused_layer_norm.py #67159

Merged
merged 8 commits into from
Aug 18, 2024

Conversation

haoyu2022
Copy link
Contributor

PR Category

User Experience

PR Types

Improvements

Description

类型标注:

  • python/paddle/incubate/nn/functional/ fused_layer_norm.py

Related links

@SigureMo @megemini

Copy link

paddle-bot bot commented Aug 7, 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.

update

Co-authored-by: megemini <megemini@outlook.com>
@paddle-bot paddle-bot bot added the contributor External developers label Aug 7, 2024
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Aug 8, 2024
@luotao1
Copy link
Contributor

luotao1 commented Aug 8, 2024

PR-CI-Codestyle-Check 没过 @haoyu2022

@SigureMo SigureMo changed the title [Typing][C-73] Add type annotations for python/paddle/incubate/nn/functional/ fused_layer_norm.py [Typing][C-73] Add type annotations for python/paddle/incubate/nn/functional/ fused_layer_norm.py Aug 10, 2024
@megemini
Copy link
Contributor

megemini commented Aug 14, 2024

@haoyu2022 帮忙改一下 Codestyle 吧 ~ 谢谢 ~

@haoyu2022
Copy link
Contributor Author

@megemini 好的,稍等😊

Copy link

paddle-ci-bot bot commented Aug 15, 2024

Sorry to inform you that 48e7400's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.


import paddle
from paddle import _C_ops
from paddle.framework import LayerHelper, in_dynamic_mode, in_pir_mode

if TYPE_CHECKING:
from paddle import Tensor


def fused_layer_norm(
Copy link
Contributor

Choose a reason for hiding this comment

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

根据 residual 使用 overload

from __future__ import annotations

from typing import TYPE_CHECKING, overload

import paddle
from paddle import _C_ops
from paddle.framework import LayerHelper, in_dynamic_mode, in_pir_mode

if TYPE_CHECKING:
    from paddle import Tensor

@overload
def fused_layer_norm(
    x: Tensor,
    norm_weight: Tensor,
    norm_bias: Tensor,
    epsilon: float,
    residual_alpha: float = ...,
    begin_norm_axis: int = ...,
    bias: Tensor | None = ...,
    residual: None = ...,
    quant_scale: float = ...,
    quant_round_type: float = ...,
    quant_max_bound: float = ...,
    quant_min_bound: float = ...,
) -> Tensor: ...

@overload
def fused_layer_norm(
    x: Tensor,
    norm_weight: Tensor,
    norm_bias: Tensor,
    epsilon: float,
    residual_alpha: float = ...,
    begin_norm_axis: int = ...,
    bias: Tensor | None = ...,
    residual: Tensor = ...,
    quant_scale: float = ...,
    quant_round_type: float = ...,
    quant_max_bound: float = ...,
    quant_min_bound: float = ...,
) -> tuple[Tensor, Tensor]: ...

def fused_layer_norm(
    x,
    norm_weight,
    norm_bias,
    epsilon,
    residual_alpha=1.0,
    begin_norm_axis=1,
    bias=None,
    residual=None,
    quant_scale=-1,
    quant_round_type=0,
    quant_max_bound=0,
    quant_min_bound=0,
):
    r"""
    Apply Fused LayerNorm kernel. Also support LayerNorm(bias + residual_alpha * residual + x) fused pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,感谢

Copy link
Contributor

@megemini megemini left a comment

Choose a reason for hiding this comment

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

看一下上次 review 的代码 ... ...

@haoyu2022
Copy link
Contributor Author

看一下上次 review 的代码 ... ...

image
我明白意思了。

Copy link
Contributor

@megemini megemini left a comment

Choose a reason for hiding this comment

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

LGTM ~

@SigureMo SigureMo changed the title [Typing][C-73] Add type annotations for python/paddle/incubate/nn/functional/ fused_layer_norm.py [Typing][C-73] Add type annotations for python/paddle/incubate/nn/functional/fused_layer_norm.py Aug 18, 2024
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 🐾

@SigureMo SigureMo merged commit 16c7d97 into PaddlePaddle:develop Aug 18, 2024
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants