Skip to content

LSTM cannot be trained successfully with the latest release version #1168

@AStupidBear

Description

@AStupidBear

The following script works fine using Flux.jl#tracker, but get stuck on a "plateou" of loss=0.11 using Flux.jl#zygote.

using Flux, Random, Statistics

Random.seed!(1234)

x = randn(Float32, 10, 1, 100)
y = mean(x, dims = 1)

model = Chain(LSTM(10, 100), LSTM(100, 1))

function loss(x, y)
    xs = Flux.unstack(x, 3)
    ys = Flux.unstack(y, 3)
    ŷs = model.(xs)
    l = 0f0
    for t in 1:length(ŷs)
        l += Flux.mse(ys[t], ŷs[t])
    end
    return l / length(ŷs)
end

opt = ADAM(1e-3, (0.9, 0.999))

cb = () -> (println(Flux.data(loss(x, y))); Flux.reset!(model))

Flux.@epochs 10 Flux.train!(loss, params(model), repeat([(x, y)], 100), opt, cb = cb)

This is also reproducible on GPU, JuliaBox, and other computers. You can verify this by yourself by running this script in two environments with Flux.jl#v0.9.0 and Flux.jl#v0.10.4 installed seperately.

Since LSTM implementations are the same across Flux.jl#v0.9.0 and Flux.jl#v0.10.4, I suspect that this is a Zygote issue, but cannot find the root cause and fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions