Zygote.jl
Zygote.jl copied to clipboard
MethodError: no method matching zero(::Tuple{Float64, Float64})
I have the following code which is very similar to Chris Rackauckas' code from a tutorial where I have changed from Float32 to Float64. The function loss4() works with train!() but functions loss() and loss3() do not work with train!() (they work stand-alone). It's baffling to me. I have tried to do an @enter trace but I quickly got lost with all of the callbacks.
using Flux
using Statistics
# using DifferentialEquations
NNode = Chain(x -> [x],
Dense(1, 32, tanh),
Dense(32, 1),
first)
Flux.f64(NNode)
g(t) = t*NNode(t) + 3.0
ϵ = sqrt(eps(Float64))
loss() = mean(abs2(((g(t+ϵ)-g(t))/ϵ) - cos(2π*t)) for t in 0:(rand(Float64)/50):1.0)
loss4 = function()
t = rand(Float64)
a1 = abs2(((g(t+ϵ)-g(t))/ϵ)-cos(2π*t))
for _ in 1:10
t = rand(Float64)
a1 += abs2(((g(t+ϵ)-g(t))/ϵ)-cos(2π*t))
end
return(a1/11)
end
loss3 = function()
sum = 0
count = 0
for t in 0:rand(Float64)/50:1.0 # changing this to 0:0.1:1.0 doesn't work either.
sum += abs2(((g(t+ϵ)-g(t))/ϵ)-cos(2π*t))
count += 1
end
return(sum/count)
end
Flux.train!(loss3, Flux.params(NNode), Iterators.repeated((), 5000), Flux.Descent(0.01))
Same as #1247 I think, runs if you add https://github.com/FluxML/Zygote.jl/issues/1247#issuecomment-1175332642