Skip to content

add elu and selu activations - #263

Open
CarloLucibello wants to merge 3 commits into
denizyuret:masterfrom
CarloLucibello:elu
Open

add elu and selu activations#263
CarloLucibello wants to merge 3 commits into
denizyuret:masterfrom
CarloLucibello:elu

Conversation

@CarloLucibello

Copy link
Copy Markdown
Collaborator

No description provided.

@CarloLucibello

Copy link
Copy Markdown
Collaborator Author

this should be ready for merge after review

@cangumeli

Copy link
Copy Markdown
Collaborator

Shouldn't elu and selu be primitives if we add them to Knet?

@denizyuret

denizyuret commented Feb 14, 2018 via email

Copy link
Copy Markdown
Owner

@cangumeli

Copy link
Copy Markdown
Collaborator

If elu and selu will be added after each weight layer similar to other activations, defining them as composite operations may bring performance and memory overhead in training. I think they should be implemented similar to how sigm, relu etc. are implemented.

@CarloLucibello CarloLucibello mentioned this pull request Feb 19, 2018
Comment thread src/unary.jl Outdated
p = relu(x)
m = -relu(-x)
return scale*(p + alpha*(exp(m) - 1))
end No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about using elu here?

function selu(x)
    alpha = Float32(1.6732632)
    scale = Float32(1.0507009)
    return scale * elu(x, alpha)
end 

@rened

rened commented Mar 23, 2018

Copy link
Copy Markdown

Elu can be included in unary.jl by adding
("elu", "elu", "(xi>0?xi:exp(xi)-1)"),
and
(:elu, :eluback, :(ifelse(xi>0,xi,exp(xi)-1)), :(ifelse(yi>0,dyi,yi+1))),
below the respective relu lines.

@CarloLucibello
CarloLucibello force-pushed the elu branch 2 times, most recently from ab3a189 to a791dc1 Compare March 23, 2018 14:09
Comment thread src/broadcast.jl
# "fdim",
("invxback","invxback","(-xi*yi*yi)"),
("reluback","reluback","(yi>0?xi:0)"),
("eluback", "eluback", "ifelse(yi>0,dyi,yi+1)"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This part turns to a cuda code snippet. So, I think it must be replaced with the following:

("eluback", "eluback", "(yi>0?xi:yi+1)")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't understand the comment. ifelse(yi>0,dyi,yi+1) is valid julia code and should be the right derivative

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When I tried to build the package, it threw following errors:

cuda01.cu(395): error: identifier "dyi" is undefined
cuda01.cu(395): error: identifier "ifelse" is undefined
cuda01.cu(408): error: identifier "dyi" is undefined
cuda01.cu(408): error: identifier "ifelse" is undefined

I am able to build the package with the ("eluback", "eluback", "(yi>0?xi:yi+1)") code snippet.

@denizyuret

denizyuret commented Apr 17, 2018 via email

Copy link
Copy Markdown
Owner

@denizyuret

Copy link
Copy Markdown
Owner

Manually merged elu after fixing the faulty gradient: for negative values the derivative should be dyi*(yi+1).

@denizyuret

Copy link
Copy Markdown
Owner

Added selu as a cuda kernel for efficiency.

@denizyuret

Copy link
Copy Markdown
Owner

@CarloLucibello can you explain how this gives the intended result in alpha_dropout:
x = q*dropout(x .- alpha, p) .+ alpha #set dropped input to alpha

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.

6 participants