Skip to content

Conversation

@Starrysea996
Copy link
Contributor

@Starrysea996 Starrysea996 commented Aug 8, 2025

PR Category

User Experience

PR Types

New features

Description

Add the case where the approximate parameter is a string (“none" and "tanh") for gelu function and GELU class

@paddle-bot
Copy link

paddle-bot bot commented Aug 8, 2025

你的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.

@codecov-commenter
Copy link

codecov-commenter commented Aug 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@e342884). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #74485   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         2           
  Lines              ?         6           
  Branches           ?         0           
===========================================
  Hits               ?         6           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

[ 0.84119201, 1.39957154]])
"""

if isinstance(approximate, bool):
Copy link
Contributor

Choose a reason for hiding this comment

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

加上

if approximate == "tanh":
    approximate = True
elif approximate == "none":
    approximate = False

就行

) -> None:
super().__init__()
self._approximate = approximate
self._origin_approximate = approximate
Copy link
Contributor

Choose a reason for hiding this comment

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

这些转换不用做,直接保留 self._approximate = approximate,并透传到function里去就行,function也是支持str的

zhwesky2010
zhwesky2010 previously approved these changes Aug 11, 2025
Copy link
Contributor

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhwesky2010 zhwesky2010 requested a review from SigureMo August 11, 2025 10:26

def gelu(
x: Tensor, approximate: bool = False, name: str | None = None
x: Tensor, approximate: str | bool = False, name: str | None = None
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
x: Tensor, approximate: str | bool = False, name: str | None = None
x: Tensor, approximate: Literal["tanh", "none"] | bool = False, name: str | None = None

参考 https://www.paddlepaddle.org.cn/documentation/docs/zh/dev_guides/style_guide_and_references/type_annotations_specification_cn.html#shiyonggengjiamingquedeleixingyitigonggenghaodetishixiaoguo 使用 Literal 吧,下同

@zhwesky2010 zhwesky2010 merged commit ecbee80 into PaddlePaddle:develop Aug 12, 2025
72 of 73 checks passed
maxiaolong001 pushed a commit to maxiaolong001/Paddle that referenced this pull request Aug 12, 2025
* change gelu api

* simple gelu function and class

* replace str with literal
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.

4 participants