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

Adding GELU implementation #547

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

Adding GELU implementation #547

wants to merge 1 commit into from

Conversation

alisafaya
Copy link
Collaborator

After editing backward function implementation in unary.jl to include xi, It worked on cpu.

But I think this edition @primitive $f(x),dy,y $g.(dy,y) -> @primitive $f(x),dy,y $g.(dy,y,x) has broke the implementation of all the activation function for gpu.
I am getting this error for KnetArrays:

julia> x = Param(KnetArray(randn(2, 4))); 
julia> @gcheck(gelu.(x))
ERROR: MethodError: no method matching geluback(::Knet.Bcasted{KnetArray{Float64,2}}, ::Knet.Bcasted{KnetArray{Float64,2}}, ::Knet.Bcasted{KnetArray{Float64,2}})
Closest candidates are:
  geluback(::Knet.Bcasted{#s175} where #s175<:(KnetArray{Float64,N} where N), ::Knet.Bcasted{#s174} where #s174<:(KnetArray{Float64,N} where N)) at /home/asafaya19/Knet.jl/src/binary.jl:122
  geluback(::Knet.Bcasted, ::Knet.Bcasted) at /home/asafaya19/Knet.jl/src/binary.jl:137
  geluback(::Knet.Bcasted, ::Any) at /home/asafaya19/Knet.jl/src/binary.jl:139
  ...
Stacktrace:
 [1] broadcasted(::Base.Broadcast.Style{KnetArray}, ::Function, ::KnetArray{Float64,2}, ::KnetArray{Float64,2}, ::KnetArray{Float64,2}) at /home/asafaya19/Knet.jl/src/karray.jl:1309
 [2] broadcasted(::Function, ::KnetArray{Float64,2}, ::KnetArray{Float64,2}, ::KnetArray{Float64,2}) at ./broadcast.jl:1237
 [3] broadcasted(::Base.Broadcast.Style{AutoGrad.Value}, ::Function, ::KnetArray{Float64,2}, ::AutoGrad.Result{KnetArray{Float64,2}}, ::Param{KnetArray{Float64,2}}) at /home/asafaya19/.julia/packages/AutoGrad/FSgUc/src/core.jl:54
 [4] broadcasted(::Function, ::KnetArray{Float64,2}, ::AutoGrad.Result{KnetArray{Float64,2}}, ::Param{KnetArray{Float64,2}}) at ./broadcast.jl:1237
 [5] back(::typeof(Base.Broadcast.broadcasted), ::Type{AutoGrad.Arg{2}}, ::KnetArray{Float64,2}, ::AutoGrad.Result{KnetArray{Float64,2}}, ::typeof(gelu), ::Param{KnetArray{Float64,2}}) at ./none:0
 [6] #differentiate#3(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(AutoGrad.differentiate), ::Function) at /home/asafaya19/.julia/packages/AutoGrad/FSgUc/src/core.jl:165
 [7] differentiate at /home/asafaya19/.julia/packages/AutoGrad/FSgUc/src/core.jl:135 [inlined]
 [8] #gcheck#233(::Tuple{}, ::Int64, ::Int64, ::Float64, ::Float64, ::Float64, ::typeof(gcheck), ::Function) at /home/asafaya19/.julia/packages/AutoGrad/FSgUc/test/gradcheck.jl:158
 [9] gcheck(::Function) at /home/asafaya19/.julia/packages/AutoGrad/FSgUc/test/gradcheck.jl:158
 [10] top-level scope at REPL[8]:1

@denizyuret
Copy link
Owner

denizyuret commented Apr 5, 2020 via email

@alisafaya
Copy link
Collaborator Author

alisafaya commented Apr 5, 2020

I tried to do that but I wasn't able to express the derivative using y only since the function has a complicated derivative form.
Here is the paper of GELU
And here is the derivation using Wolframalpha.

@denizyuret
Copy link
Owner

Try using this external implementation for now.

I want to go towards using CUDAnative and CuArrays, so it doesn't seem worth making a big overhaul of existing KnetArray code.

@alisafaya
Copy link
Collaborator Author

Thanks!

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.

None yet

2 participants