Skip to content

iterating through a DataLoader is still broken #843

@tiemvanderdeure

Description

@tiemvanderdeure

Describe the bug 🐞
Iterating over a DataLoader is still broken on 4.0.3. If epochs is less than the number of elements in DataLoader, only the first epochs elements get evaluated.

Expected behavior
Surely this should iterate over the entire dataset epochs times

Minimal Reproducible Example 👇

function lossf(θ, data)
    @show data
    return sum.^2)
end
dataloader = DataLoader(collect(1:10), batchsize = 1)
opt_func = OptimizationFunction(
    lossf,
    Optimization.AutoZygote())
opt_prob = OptimizationProblem(opt_func, [2.0], dataloader)
res_adam = solve(
    opt_prob, Optimisers.Adam(0.001); epochs = 3)

Error & Stacktrace ⚠️
No stacktrace, but julia outputs this:

data = [1]
data = [2]
data = [3]
data = [3]
data = [1]
data = [2]
data = [3]
data = [3]
data = [1]
data = [2]
data = [3]
data = [3]
retcode: Default
u: 1-element Vector{Float64}:
 1.9940003690339771

Environment (please complete the following information):
Latest versions of Optimization and OptimizationOptimisers

Additional context
The problem is in this line:

if i == maxiters #Last iter, revert to best.

Probably the if condition should be something like epoch == maxiters && i == length(data). It would also be good to add a test.

Related to #835 and #842

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions