-
Notifications
You must be signed in to change notification settings - Fork 230
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
alisafaya
wants to merge
1
commit into
denizyuret:master
Choose a base branch
from
alisafaya:add-gelu
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Are we sure the derivative of gelu cannot be expressed in terms of y
instead of x? Can you share the link for the mathematical references?
…On Fri, Apr 3, 2020 at 7:14 PM Ali Safaya ***@***.***> wrote:
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
------------------------------
You can view, comment on, or merge this pull request online at:
#547
Commit Summary
- added gelu cpu implementations (forward, backward) to unary.jl
File Changes
- *M* src/Knet.jl
<https://github.com/denizyuret/Knet.jl/pull/547/files#diff-4cdfe52d4f41ad1634787cb32a0c94f0>
(1)
- *M* src/ops.jl
<https://github.com/denizyuret/Knet.jl/pull/547/files#diff-fb5bd05ac2c8fd9458005bc4956ac070>
(2)
- *M* src/unary.jl
<https://github.com/denizyuret/Knet.jl/pull/547/files#diff-becd4ba6327d1e2208e7b35955df6aea>
(49)
Patch Links:
- https://github.com/denizyuret/Knet.jl/pull/547.patch
- https://github.com/denizyuret/Knet.jl/pull/547.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#547>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN43JRCDAKTZJ6OQYVB26LRKYDPTANCNFSM4L4HDV3Q>
.
|
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. |
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. |
Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: