I have a problem happening in Flux that I cannot explain. When I run the MVE defined below an error happens. The error is given below the code.
using Flux
using Flux.Tracker
struct AffineB{F, S, T}
W::S
b::T
μ::T
logσ::T
φ::F
end
z(μ, logσ) = μ + exp(logσ)*randn()
function initaffineb(in::Integer, out::Integer, μ, logσ)
s = z.(μ, logσ)
W, b = reshape(s[1:out*in], out, in), reshape(s[out*in+1:end], out)
W, b
end
function initaffineb(in::Integer, out::Integer)
μ, logσ = param(zeros(out*in+out)), param(zeros(out*in+out))
W, b = initaffineb(in, out, μ, logσ)
W, b, μ, logσ
end
function AffineB(in::Integer, out::Integer)
W, b, μ, logσ = initaffineb(in, out)
AffineB(W, b, μ, logσ, identity)
end
function AffineB(in::Integer, out::Integer, φ::Function)
W, b, μ, logσ = initaffineb(in, out)
AffineB(W, b, μ, logσ, φ)
end
function (a::AffineB)(X::AbstractArray)
W, b, φ = a.W, a.b, a.φ
φ.(W*X .+ b)
end
Flux.@treelike AffineB # This should allow me to call params on an AffineB type.
# Simple OR logic problem
x = [0 0 1 1; 0 1 0 1]
y = [0 1 1 1]
a = AffineB(2, 1)
l = sum((a(x) .- y).^2) # Sum squared error
Tracker.back!(l) # Backpropagate
pars = params(a) # Collect all parameters where it dies...
ERROR: TypeError: non-boolean (Missing) used in boolean context
Stacktrace:
[1] ==(::Flux.Tracker.Call{Missing,Tuple{}}, ::Flux.Tracker.Call{Nothing,Tuple{}}) at /home/michael/.julia/packages/Flux/8XpDt/src/tracker/Tracker.jl:28
[2] isleaf(::Flux.Tracker.Tracked{Array{Float64,2}}) at /home/michael/.julia/packages/Flux/8XpDt/src/tracker/Tracker.jl:43
[3] isleaf at /home/michael/.julia/packages/Flux/8XpDt/src/tracker/Tracker.jl:14 [inlined]
[4] (::getfield(Flux, Symbol("##43#45")){Params})(::TrackedArray{…,Array{Float64,2}}) at /home/michael/.julia/packages/Flux/8XpDt/src/treelike.jl:39
[5] #prefor#40 at /home/michael/.julia/packages/Flux/8XpDt/src/treelike.jl:32 [inlined]
[6] #prefor at ./none:0 [inlined]
[7] (::getfield(Flux, Symbol("##41#42")){Flux.Tracker.IdSet{Any},getfield(Flux, Symbol("##43#45")){Params}})(::TrackedArray{…,Array{Float64,2}}) at /home/michael/.julia/packages/Flux/8XpDt/src/treelike.jl:33
[8] foreach(::getfield(Flux, Symbol("##41#42")){Flux.Tracker.IdSet{Any},getfield(Flux, Symbol("##43#45")){Params}}, ::Tuple{TrackedArray{…,Array{Float64,2}},TrackedArray{…,Array{Float64,1}},TrackedArray{…,Array{Float64,1}},TrackedArray{…,Array{Float64,1}},typeof(identity)}) at ./abstractarray.jl:1866
[9] #prefor#40 at /home/michael/.julia/packages/Flux/8XpDt/src/treelike.jl:33 [inlined]
[10] prefor at /home/michael/.julia/packages/Flux/8XpDt/src/treelike.jl:31 [inlined]
[11] params(::AffineB{typeof(identity),TrackedArray{…,Array{Float64,2}},TrackedArray{…,Array{Float64,1}}}) at /home/michael/.julia/packages/Flux/8XpDt/src/treelike.jl:39
[12] top-level scope at none:0
I’m running Flux 0.7.3 and
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core™ i7-6650U CPU @ 2.20GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Any ideas?