Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add GELU layer for vision transformers#23219

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
alalek merged 2 commits intoopencv:4.xfromfengyuentau:add_gelu
Feb 10, 2023
Merged

Conversation

@fengyuentau
Copy link
Member

This PR adds the CPU and OCL kernels of GELU and GELU-Approximation layers.

Merge withopencv/opencv_extra#1044

References:

Pull Request Readiness Checklist

See details athttps://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Copy link
Member

@alalekalalek left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Member

@alalekalalek left a comment

Choose a reason for hiding this comment

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

Thank you!

fengyuentau reacted with rocket emoji
@fengyuentau
Copy link
MemberAuthor

@rogday Could you review if possible?

@vpisarevvpisarev removed the request for review fromrogdayFebruary 10, 2023 08:45
Comment on lines 310 to 324
__kernelvoidGeluForward(constintn,__globalT*in,__globalT*out)
{
intindex=get_global_id(0);
if(index<n)
out[index]= (T)0.5f*in[index]* ( (T)1.f+erf(in[index]*M_SQRT1_2) );
}

__kernelvoidGeluApproximationForward(constintn,__globalT*in,__globalT*out,
constKERNEL_ARG_DTYPEsqrt_2_pi,
constKERNEL_ARG_DTYPEcoef_sqrt_2_pi)
{
intindex=get_global_id(0);
if(index<n)
out[index]= (T)0.5f*in[index]* ( (T)1.f+tanh(in[index]* (sqrt_2_pi+coef_sqrt_2_pi*in[index]*in[index])) );
}
Copy link
Member

Choose a reason for hiding this comment

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

Please use this OpenCL code:

__kernel void GeluForward(const int n, __global T* in, __global T* out){    int index = get_global_id(0);    if (index < n)    {        T x = in[index];        out[index] = (T)0.5f * x * ( (T)1.f + erf(x * M_SQRT1_2) );    }}__kernel void GeluApproximationForward(const int n, __global T* in, __global T* out){    // see GeluApproximationConstants from .cpp    const T sqrt_2_pi = 0.7978845834732056f;    const T coef_sqrt_2_pi = 0.044714998453855515f * sqrt_2_pi;    int index = get_global_id(0);    if(index < n)    {        T x = in[index];        out[index] = (T)0.5f * x * ( (T)1.f + tanh(x * (sqrt_2_pi + coef_sqrt_2_pi * x * x)) );    }}

and dropsetKernelParams() method.

rogday reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Okay

@alalekalalek merged commitc2b7c1f intoopencv:4.xFeb 10, 2023
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull requestMar 30, 2023
Add GELU layer for vision transformers* add gelu and gelu approximation* drop setKernelParams
@asmorkalovasmorkalov mentioned this pull requestMay 31, 2023
geversonsto pushed a commit to stodev-com-br/opencv that referenced this pull requestJun 3, 2023
Add GELU layer for vision transformers* add gelu and gelu approximation* drop setKernelParams
@fengyuentaufengyuentau deleted the add_gelu branchFebruary 21, 2024 08:19
@fengyuentaufengyuentau mentioned this pull requestFeb 21, 2024
48 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@alalekalalekalalek approved these changes

Assignees

@alalekalalek

Labels

category: dnn (onnx)ONNX suport issues in DNN modulecategory: dnnfeature

Projects

None yet

Milestone

4.8.0

Development

Successfully merging this pull request may close these issues.

2 participants

@fengyuentau@alalek

[8]ページ先頭

©2009-2025 Movatter.jp