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][B-71] Add type annotations for python/paddle/sparse/nn/layer/activation.py #65869

Merged
merged 3 commits into from
Jul 11, 2024

Conversation

megemini
Copy link
Contributor

@megemini megemini commented Jul 9, 2024

PR Category

User Experience

PR Types

Improvements

Description

类型标注:

  • python/paddle/sparse/nn/layer/activation.py

Related links

@SigureMo @megemini

Copy link

paddle-bot bot commented Jul 9, 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
Copy link
Contributor Author

megemini commented Jul 9, 2024

Update 20240709

由于 隐式类型提升规则 示例测试失败:

In [7]: import paddle
   ...: paddle.seed(2022)
   ...: 
   ...: mask = paddle.rand((3, 4)) < 0.7
   ...: x = paddle.rand((3, 4)) * mask
   ...: 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[7], line 5
      2 paddle.seed(2022)
      4 mask = paddle.rand((3, 4)) < 0.7
----> 5 x = paddle.rand((3, 4)) * mask

TypeError: (InvalidType) Type promotion only support calculations between floating-point numbers and between complex and real numbers. But got different data type x: float32, y: bool. (at /home/shun/Documents/Projects/paddle/megemini/Paddle/paddle/phi/common/type_promotion.h:159)

个人感觉不是很合理,floatbool 的 mask 之间运算似乎很常用,现在不支持了?

参考链接:https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/advanced/auto_type_promotion_cn.html#erfeijiangdeleixingtishengguize

@SigureMo

@SigureMo
Copy link
Member

SigureMo commented Jul 9, 2024

个人感觉不是很合理,floatbool 的 mask 之间运算似乎很常用,现在不支持了?

方案肯定是通过评审的,他们觉得不需要支持那就不支持呗

@@ -102,7 +102,7 @@ class Softmax(Layer):
>>> paddle.seed(2022)

>>> mask = paddle.rand((3, 4)) < 0.7
>>> x = paddle.rand((3, 4)) * mask
>>> x = paddle.to_tensor(paddle.rand((3, 4)).numpy() * mask.numpy())
Copy link
Member

Choose a reason for hiding this comment

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

直接 x = paddle.rand([3, 4]) * mask.astype(paddle.float32) 呢?这里转 numpy 再回转就很奇怪了

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 83c7fbe into PaddlePaddle:develop Jul 11, 2024
31 of 32 checks passed
lixcli pushed a commit to lixcli/Paddle that referenced this pull request Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants