-
-
Notifications
You must be signed in to change notification settings - Fork 611
Use faster activation functions #1837
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,7 +117,8 @@ RNNCell(in::Integer, out::Integer, σ=tanh; init=Flux.glorot_uniform, initb=zero | |
RNNCell(σ, init(out, in), init(out, out), initb(out), init_state(out,1)) | ||
|
||
function (m::RNNCell{F,A,V,<:AbstractMatrix{T}})(h, x::Union{AbstractVecOrMat{T},OneHotArray}) where {F,A,V,T} | ||
σ, Wi, Wh, b = m.σ, m.Wi, m.Wh, m.b | ||
Wi, Wh, b = m.Wi, m.Wh, m.b | ||
σ = NNlib.fast_act(m.σ, x) | ||
h = σ.(Wi*x .+ Wh*h .+ b) | ||
return h, reshape_cell_output(h, x) | ||
end | ||
|
@@ -224,8 +225,8 @@ function (m::LSTMCell{A,V,<:NTuple{2,AbstractMatrix{T}}})((h, c), x::Union{Abstr | |
b, o = m.b, size(h, 1) | ||
g = m.Wi*x .+ m.Wh*h .+ b | ||
input, forget, cell, output = multigate(g, o, Val(4)) | ||
c′ = @. σ(forget) * c + σ(input) * tanh(cell) | ||
h′ = @. σ(output) * tanh(c′) | ||
c′ = @. sigmoid_fast(forget) * c + sigmoid_fast(input) * tanh_fast(cell) | ||
h′ = @. sigmoid_fast(output) * tanh_fast(c′) | ||
Comment on lines
+228
to
+229
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ought these to get the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right. If we decide to disable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be a blessing in disguise, as currently plain |
||
return (h′, c′), reshape_cell_output(h′, x) | ||
end | ||
|
||
|
@@ -309,7 +310,7 @@ function (m::GRUCell{A,V,<:AbstractMatrix{T}})(h, x::Union{AbstractVecOrMat{T},O | |
Wi, Wh, b, o = m.Wi, m.Wh, m.b, size(h, 1) | ||
gxs, ghs, bs = multigate(Wi*x, o, Val(3)), multigate(Wh*h, o, Val(3)), multigate(b, o, Val(3)) | ||
r, z = _gru_output(gxs, ghs, bs) | ||
h̃ = @. tanh(gxs[3] + r * ghs[3] + bs[3]) | ||
h̃ = @. tanh_fast(gxs[3] + r * ghs[3] + bs[3]) | ||
h′ = @. (1 - z) * h̃ + z * h | ||
return h′, reshape_cell_output(h′, x) | ||
end | ||
|
@@ -387,7 +388,7 @@ function (m::GRUv3Cell{A,V,<:AbstractMatrix{T}})(h, x::Union{AbstractVecOrMat{T} | |
Wi, Wh, b, Wh_h̃, o = m.Wi, m.Wh, m.b, m.Wh_h̃, size(h, 1) | ||
gxs, ghs, bs = multigate(Wi*x, o, Val(3)), multigate(Wh*h, o, Val(2)), multigate(b, o, Val(3)) | ||
r, z = _gru_output(gxs, ghs, bs) | ||
h̃ = tanh.(gxs[3] .+ (Wh_h̃ * (r .* h)) .+ bs[3]) | ||
h̃ = tanh_fast.(gxs[3] .+ (Wh_h̃ * (r .* h)) .+ bs[3]) | ||
h′ = @. (1 - z) * h̃ + z * h | ||
return h′, reshape_cell_output(h′, x) | ||
end | ||
|
Uh oh!
There was an error while loading. Please reload this page.