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

Add gelu and mul grad #501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add gelu and mul grad #501

wants to merge 1 commit into from

Conversation

MARD1NO
Copy link
Collaborator

@MARD1NO MARD1NO commented Mar 18, 2025

PR Category

Type of Change

Description

Issue

Progress

  • Change is properly reviewed (1 reviewer required, 2 recommended).
  • Change is responded to an issue.
  • Change is fully covered by a UT.

Performance

@MARD1NO MARD1NO marked this pull request as ready for review March 18, 2025 11:59
@MARD1NO MARD1NO requested a review from StrongSpoon March 18, 2025 11:59
@triton.jit
def gelu_none_and_mul_grad_kernel(x, y, dgrad):
x_fp32 = x.to(tl.float32)
x_gelu = 0.5 * x_fp32 * (1 + erf(x_fp32 * 0.7071067811))
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we give a named symbol to the constant? Or just 2**-0.5

Comment on lines +32 to +38
d_gelu = 0.5 * (
1.0
+ erf(x_fp32 * 0.7071067811)
+ x_fp32 * coeff * tl.exp(-0.5 * x_fp32 * x_fp32)
)

dx = dgrad * y * d_gelu
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest following the naming convention in chain rule. In this particular case,
d_gelu = d_out * y
dx = d_gelu * 0.5 * (
1.0
+ erf(x_fp32 * 0.7071067811)
+ x_fp32 * coeff * tl.exp(-0.5 * x_fp32 * x_fp32)
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants