Optimization.jl
Optimization.jl copied to clipboard
Problem with `maxiters`
When using e.g. ADAM optimiser, one can use a NCycle iterator, i.e.
maxiters_wanted = 1000
train_loader = Flux.Data.DataLoader((0:100,); batchsize = 4, shuffle = true)
data = ncycle(train_loader, maxiters_wanted)
res = Optimization.solve(optprob, opt, data)
In such case, the maximum number of iteration is internally defined as https://github.com/SciML/Optimization.jl/blob/2d597c62fd5f70f9ad9dd07f4008ef0a7207a112/lib/OptimizationFlux/src/OptimizationFlux.jl#L12
But here, length(data) == 2600, while the behaviour wanted is of course to have 1000 iterations. This comes from the fact that IterTools defines length(data::NCycle) as
https://github.com/JuliaCollections/IterTools.jl/blob/831bbd2c584c41af961df1b9ee8954d46e366621/src/IterTools.jl#L806
So we might want to overwrite the length method internally, with something like
import Base.length
import IterTools.NCycle
length(nc::NCycle) = nc.n