Skip to content

Conversation

megemini
Copy link
Contributor

@megemini megemini commented Jun 4, 2024

PR Category

User Experience

PR Types

New features

Description

NO.8 为 Paddle 新增 FeatureAlphaDropout API

相关接口的实现代码。

相关 RFC PaddlePaddle/community#913

20240604

  • 提交第一个 commit,作为 review 参考

Copy link

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

@megemini megemini changed the title 【WIP】【Hackathon 6th No.8】NO.8 为 Paddle 新增 FeatureAlphaDropout API 【Hackathon 6th No.8】NO.8 为 Paddle 新增 FeatureAlphaDropout API Jun 11, 2024
@megemini
Copy link
Contributor Author

megemini commented Jun 12, 2024

@zxcd

我在本地测试了一下,test_dropout_op.py 通过不了,alpha dropout 和 feature alpha dropout 可以通过,是别的用例出问题了 ~

=========================================================================== short test summary info ============================================================================
FAILED test_dropout_op.py::TestDropoutOp2::test_check_output - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[32, 64] is not equal to decomp output rank of shape[]  (at /home/sh...
FAILED test_dropout_op.py::TestDropoutOp6::test_check_output - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[32, 64] is not equal to decomp output rank of shape[]  (at /home/sh...
FAILED test_dropout_op.py::TestBF16DropoutOp::test_check_grad_normal - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[32, 64] is not equal to decomp output rank of shape[]  (at /home/sh...
FAILED test_dropout_op.py::TestBF16DropoutOp::test_check_output - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[32, 64] is not equal to decomp output rank of shape[]  (at /home/sh...
FAILED test_dropout_op.py::TestPirCompositeDropout_6_p_1_0_test_False::test_static_comp - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[100000] is not equal to decomp output rank of shape[]  (at /home/sh...
FAILED test_dropout_op.py::TestPirCompositeDropout_7_p_1_0_test_False_dtype_bfp16::test_static_comp - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[100000] is not equal to decomp output rank of shape[]  (at /home/sh...

另外,我看 CI 里面貌似没有测试这个 test_dropout_op.py

还是说,我把 alpha dropout 和 feature alpha dropout 的测试用例单独拎一个文件出来测试?

还请帮忙看看 ~ 谢谢!

@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations
Copy link
Contributor

Choose a reason for hiding this comment

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

这是干什么的?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

目前在做类型标注 #65008

所以这里索性直接加上了 ~

x (Tensor): The input tensor. The data type is bfloat16, float16, float32 or float64.
p (float | int, optional): Probability of setting units to zero. Default 0.5.
training (bool, optional): A flag indicating whether it is in train phrase or not. Default True.
name (str | None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Copy link
Contributor

Choose a reason for hiding this comment

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

不需要|None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里我解释一下哈 ~ 按理说 type hints 做好之后,docstring 里面的 Args 不需要再写类型了,比如:

原来是

def foo(name=None):
  """
  ...
  Args:
    name (str, optional): xxx  
  """
  ...

应该是

def foo(name: str | None = None) -> None:
  """
  ...
  Args:
    name : xxx  
  """
  ...

但是,由于 paddle 之前没做 type hints,所以保留了 Args 里面的参数类型:

def foo(name: str | None = None) -> None:
  """
  ...
  Args:
    name (str | None, optional) : xxx  
  """
  ...

这里的 optional 与 python 的 Optional 类型不一样,docstring 里面的 optional 表示有默认值,None 也算,所以这里 str | None, optionalstr, optional 是不一样的:

  • str | None, optional 表示,此参数是 str 类型,且有默认值,默认值为 None
  • str, optional 表示,此参数是 str 类型,且有默认值,但是无法表示默认值是什么

p (float | int): Probability of setting units to zero. Default: 0.5
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
p (float | int, optional): Probability of setting units to zero. Default: 0.5
name (str | None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Copy link
Contributor

Choose a reason for hiding this comment

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

同上


Parameters:
p (float | int, optional): Probability of setting units to zero. Default: 0.5
name (str | None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Copy link
Contributor

Choose a reason for hiding this comment

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

同上


res_list = [res1, res2]
for res in res_list:
np.testing.assert_allclose(res.numpy(), res_np, rtol=1e-05)
Copy link
Contributor

Choose a reason for hiding this comment

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

也需要检测一下梯度和反向

self.assertRaises(TypeError, test_Variable)

@test_with_pir_api
def test_errors2(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

给出有意义的命名


class TestFeatureAlphaDropoutFAPIError(unittest.TestCase):
@test_with_pir_api
def test_errors(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

给出有意义的命名

@@ -1319,6 +1319,168 @@ def test_static_fp16_gpu(self):
np.testing.assert_allclose(res[0], input, rtol=1e-05)


class TestFeatureAlphaDropoutFAPI(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

TestFeatureAlphaDropoutFAPI中的F是指什么?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我是参考此测试文件中其他用例写的,好像是这里的习惯写法? F 应该是值 function,也就是 feature_alpha_dropout ,C 应该是指 class,也就是 FeatureAlphaDropout

那我改一下吧 ~

self.assertRaises(ValueError, test_pvalue)


class TestFeatureAlphaDropoutCAPI(unittest.TestCase):
Copy link
Contributor

@zxcd zxcd Jun 13, 2024

Choose a reason for hiding this comment

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

TestFeatureAlphaDropoutCAPI中的C是指什么?另外建议增加bfloat16的测试

@zxcd
Copy link
Contributor

zxcd commented Jun 13, 2024

@zxcd

我在本地测试了一下,test_dropout_op.py 通过不了,alpha dropout 和 feature alpha dropout 可以通过,是别的用例出问题了 ~

=========================================================================== short test summary info ============================================================================
FAILED test_dropout_op.py::TestDropoutOp2::test_check_output - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[32, 64] is not equal to decomp output rank of shape[]  (at /home/sh...
FAILED test_dropout_op.py::TestDropoutOp6::test_check_output - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[32, 64] is not equal to decomp output rank of shape[]  (at /home/sh...
FAILED test_dropout_op.py::TestBF16DropoutOp::test_check_grad_normal - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[32, 64] is not equal to decomp output rank of shape[]  (at /home/sh...
FAILED test_dropout_op.py::TestBF16DropoutOp::test_check_output - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[32, 64] is not equal to decomp output rank of shape[]  (at /home/sh...
FAILED test_dropout_op.py::TestPirCompositeDropout_6_p_1_0_test_False::test_static_comp - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[100000] is not equal to decomp output rank of shape[]  (at /home/sh...
FAILED test_dropout_op.py::TestPirCompositeDropout_7_p_1_0_test_False_dtype_bfp16::test_static_comp - RuntimeError: (PreconditionNotMet) [Prim] For op pd_op.dropout, its origin 1-index output rank of shape[100000] is not equal to decomp output rank of shape[]  (at /home/sh...

另外,我看 CI 里面貌似没有测试这个 test_dropout_op.py

还是说,我把 alpha dropout 和 feature alpha dropout 的测试用例单独拎一个文件出来测试?

还请帮忙看看 ~ 谢谢!

目前看这个属于存量api的问题,你可以单开一个单测。

@megemini
Copy link
Contributor Author

目前看这个属于存量api的问题,你可以单开一个单测。

嗯好!那我把 alpha dropout 和 feature alpha dropout 单独拎一个测试文件!

@megemini megemini requested a review from zxcd June 14, 2024 09:24
[-1., 1.]])
"""

def __init__(self, p=0.5, name=None):
Copy link
Member

Choose a reason for hiding this comment

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

这个 API 忘记标注了?

)
return out

def extra_repr(self):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def extra_repr(self):
def extra_repr(self) -> str:

@megemini megemini requested review from zrr1999 and gouzil as code owners June 14, 2024 16:19
@megemini megemini changed the title 【Hackathon 6th No.8】NO.8 为 Paddle 新增 FeatureAlphaDropout API 【Hackathon 6th No.8】[Typing][A-20]NO.8 为 Paddle 新增 FeatureAlphaDropout API Jun 14, 2024
@megemini megemini changed the title 【Hackathon 6th No.8】[Typing][A-20]NO.8 为 Paddle 新增 FeatureAlphaDropout API 【Hackathon 6th No.8】[Typing][A-15]NO.8 为 Paddle 新增 FeatureAlphaDropout API Jun 14, 2024
@megemini megemini changed the title 【Hackathon 6th No.8】[Typing][A-15]NO.8 为 Paddle 新增 FeatureAlphaDropout API [Typing][A-15]【Hackathon 6th No.8】NO.8 为 Paddle 新增 FeatureAlphaDropout API Jun 14, 2024
@megemini megemini changed the title [Typing][A-15]【Hackathon 6th No.8】NO.8 为 Paddle 新增 FeatureAlphaDropout API [Typing][A-15] 【Hackathon 6th No.8】NO.8 为 Paddle 新增 FeatureAlphaDropout API Jun 14, 2024
Copy link
Member

@SigureMo SigureMo Jun 14, 2024

Choose a reason for hiding this comment

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

怎么在这个 PR 里做了这么多其他的类型提示改动?这会影响这个 PR 本身的 review,不建议这样做

PR 应拆尽拆,不要什么都放在一个大 PR 里

Copy link
Member

Choose a reason for hiding this comment

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

建议将刚刚的类型提示 commit cherry-pick 到新的分支,并在本分支 revert 掉相关 commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到 ~ 😁

SigureMo
SigureMo previously approved these changes Jun 15, 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 🐾 for new API typing

@SigureMo SigureMo changed the title [Typing][A-15] 【Hackathon 6th No.8】NO.8 为 Paddle 新增 FeatureAlphaDropout API 【Hackathon 6th No.8】NO.8 为 Paddle 新增 FeatureAlphaDropout API Jun 15, 2024
SigureMo
SigureMo previously approved these changes Jun 15, 2024
Copy link
Contributor

@zxcd zxcd left a comment

Choose a reason for hiding this comment

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

LGTM

jeff41404
jeff41404 previously approved these changes Jun 20, 2024
Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

paddle-ci-bot bot commented Jun 26, 2024

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

@megemini megemini dismissed stale reviews from jeff41404 and SigureMo via ef757a7 June 26, 2024 05:27
@SigureMo
Copy link
Member

这个可以解决下冲突推进下吧,感觉好久了……

Copy link
Contributor

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

LGTM for docs

@luotao1 luotao1 merged commit fb3154f into PaddlePaddle:develop Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants