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

Incorrect gradients LSTM #1222

Closed
triepels opened this issue Jun 12, 2020 · 1 comment
Closed

Incorrect gradients LSTM #1222

triepels opened this issue Jun 12, 2020 · 1 comment

Comments

@triepels
Copy link

triepels commented Jun 12, 2020

I am building an LSTM network using Flux.jl. The network consists of an LSTM layer followed by a sigmoid (dense) layer. I found that the gradients of the LSTM layer estimated by Zygote.jl's gradient function deviate considerably from numerical approximations. The gradients of the dense layer are correct. I have made a small reproducible example below. I suspect that this issue is related to #1209.

using Flux

ϵ = 1e-6

x = [rand(2) for i in 1:3]

m = Flux.Chain(
    Flux.LSTM(2, 3),
    Flux.Dense(3, 1, σ))

m = m |> f64

grads = gradient(() -> m.(x)[1][1], Flux.params(m))

Flux.reset!(m)
m[1].cell.Wi[1] += ϵ

o1 = m.(x)[1][1]

Flux.reset!(m)
m[1].cell.Wi[1] -= 2*ϵ

o2 = m.(x)[1][1]

display(grads[m[1].cell.Wi][1])
display((o1-o2)/(2*ϵ))
@triepels
Copy link
Author

The issue is fixed by this branch.

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

No branches or pull requests

1 participant