Thanks a lot for your help! It does work on a CPU. But unfortunately, on a GPU, I see now the following error:
julia> include("mnist_cae_flux2.jl")
[ Info: Recompiling stale cache file /home/ulg/gher/abarth/.julia/compiled/v1.1/CuArrays/7YFE0.ji for CuArrays [3a865a2d-5b23-5a0f-bc46-62713ec82fae]
[ Info: Recompiling stale cache file /home/ulg/gher/abarth/.julia/compiled/v1.1/Flux/QdkVy.ji for Flux [587475ba-b771-5e3f-ad9e-33799f191a9c]
length(imgs) = 60000
size(model(data[1])) = (28, 28, 1, 64)
loss(data[1]) = 0.10397781f0 (tracked)
[ Info: Epoch 1
┌ Warning: Performing scalar operations on GPU arrays: This is very slow, consider disallowing these operations with `allowscalar(false)`
└ @ GPUArrays ~/.julia/packages/GPUArrays/fLiQ1/src/indexing.jl:16
ERROR: LoadError: MethodError: no method matching culiteral_pow(::typeof(^), ::ForwardDiff.Dual{Nothing,Float32,1}, ::Val{2})
Closest candidates are:
culiteral_pow(::typeof(^), ::Union{Float32, Float64}, ::Val{2}) at /home/ulg/gher/abarth/.julia/packages/CuArrays/wXQp8/src/broadcast.jl:46
culiteral_pow(::typeof(^), ::Union{Float32, Float64}, ::Val{p}) where p at /home/ulg/gher/abarth/.julia/packages/CuArrays/wXQp8/src/broadcast.jl:48
culiteral_pow(::typeof(^), ::Union{Float32, Float64}, ::Val{0}) at /home/ulg/gher/abarth/.julia/packages/CuArrays/wXQp8/src/broadcast.jl:44
...
Stacktrace:
[1] (::getfield(Base.Broadcast, Symbol("##2#4")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##8#10")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##1#3"))},getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##7#9"))}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},typeof(-)}},typeof(CuArrays.culiteral_pow)})(::Function, ::ForwardDiff.Dual{Nothing,Float32,1}, ::ForwardDiff.Dual{Nothing,Float32,1}, ::Val{2}) at ./broadcast.jl:298
[2] partial(::getfield(Base.Broadcast, Symbol("##2#4")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##8#10")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##1#3"))},getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##7#9"))}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},typeof(-)}},typeof(CuArrays.culiteral_pow)}, ::Float32, ::Int64, ::Function, ::Float32, ::Float32, ::Val{2}) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/lib/array.jl:505
[3] _broadcast_getindex at ./broadcast.jl:578 [inlined]
[4] getindex at ./broadcast.jl:511 [inlined]
[5] copy at ./broadcast.jl:787 [inlined]
[6] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.ArrayStyle{CuArray},Nothing,typeof(Tracker.partial),Tuple{Base.RefValue{getfield(Base.Broadcast, Symbol("##2#4")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##8#10")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##1#3"))},getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##7#9"))}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},typeof(-)}},typeof(CuArrays.culiteral_pow)}},CuArray{Float32,4},Int64,Base.RefValue{typeof(^)},CuArray{Float32,4},CuArray{Float32,4},Base.RefValue{Val{2}}}}) at ./broadcast.jl:753
[7] broadcast(::typeof(Tracker.partial), ::Base.RefValue{getfield(Base.Broadcast, Symbol("##2#4")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##8#10")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##1#3"))},getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##7#9"))}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},typeof(-)}},typeof(CuArrays.culiteral_pow)}}, ::CuArray{Float32,4}, ::Int64, ::Vararg{Any,N} where N) at ./broadcast.jl:707
[8] ∇broadcast(::typeof(Tracker.partial), ::Base.RefValue{getfield(Base.Broadcast, Symbol("##2#4")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##8#10")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##1#3"))},getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##7#9"))}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},typeof(-)}},typeof(CuArrays.culiteral_pow)}}, ::CuArray{Float32,4}, ::Int64, ::Base.RefValue{typeof(^)}, ::TrackedArray{…,CuArray{Float32,4}}, ::CuArray{Float32,4}, ::Base.RefValue{Val{2}}) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/lib/array.jl:509
[9] copy(::Base.Broadcast.Broadcasted{Tracker.TrackedStyle,NTuple{4,Base.OneTo{Int64}},typeof(Tracker.partial),Tuple{Base.RefValue{getfield(Base.Broadcast, Symbol("##2#4")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##8#10")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##1#3"))},getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##7#9"))}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},typeof(-)}},typeof(CuArrays.culiteral_pow)}},CuArray{Float32,4},Int64,Base.RefValue{typeof(^)},TrackedArray{…,CuArray{Float32,4}},CuArray{Float32,4},Base.RefValue{Val{2}}}}) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/lib/array.jl:540
[10] materialize at ./broadcast.jl:753 [inlined]
[11] #547 at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/lib/array.jl:513 [inlined]
[12] macro expansion at ./sysimg.jl:275 [inlined]
[13] ntuple at ./sysimg.jl:271 [inlined]
[14] (::getfield(Tracker, Symbol("#back#548")){4,getfield(Base.Broadcast, Symbol("##2#4")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##8#10")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##1#3"))},getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##7#9"))}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},typeof(-)}},typeof(CuArrays.culiteral_pow)},Tuple{Base.RefValue{typeof(^)},TrackedArray{…,CuArray{Float32,4}},CuArray{Float32,4},Base.RefValue{Val{2}}}})(::CuArray{Float32,4}) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/lib/array.jl:513
[15] back_(::Tracker.Call{getfield(Tracker, Symbol("#back#548")){4,getfield(Base.Broadcast, Symbol("##2#4")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##8#10")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##1#3"))},getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##5#6")){getfield(Base.Broadcast, Symbol("##7#9"))}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},typeof(-)}},typeof(CuArrays.culiteral_pow)},Tuple{Base.RefValue{typeof(^)},TrackedArray{…,CuArray{Float32,4}},CuArray{Float32,4},Base.RefValue{Val{2}}}},Tuple{Nothing,Tracker.Tracked{CuArray{Float32,4}},Nothing,Nothing}}, ::CuArray{Float32,4}, ::Bool) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:35
[16] back(::Tracker.Tracked{CuArray{Float32,4}}, ::CuArray{Float32,4}, ::Bool) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:58
[17] foreach at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:38 [inlined]
[18] back_(::Tracker.Call{getfield(Tracker, Symbol("##482#483")){TrackedArray{…,CuArray{Float32,4}}},Tuple{Tracker.Tracked{CuArray{Float32,4}}}}, ::Float32, ::Bool) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:38
[19] back(::Tracker.Tracked{Float32}, ::Float32, ::Bool) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:58
[20] #13 at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:38 [inlined]
[21] foreach at ./abstractarray.jl:1867 [inlined]
[22] back_(::Tracker.Call{getfield(Tracker, Symbol("##278#281")){Rational{Int64}},Tuple{Tracker.Tracked{Float32},Nothing}}, ::Float32, ::Bool) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:38
[23] back(::Tracker.Tracked{Float32}, ::Int64, ::Bool) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:58
[24] #back!#15 at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:77 [inlined]
[25] #back! at ./none:0 [inlined]
[26] #back!#32 at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/lib/real.jl:16 [inlined]
[27] back!(::Tracker.TrackedReal{Float32}) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/lib/real.jl:14
[28] gradient_(::getfield(Flux.Optimise, Symbol("##15#21")){typeof(loss),Tuple{CuArray{Float32,4}}}, ::Tracker.Params) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:4
[29] #gradient#24(::Bool, ::Function, ::Function, ::Tracker.Params) at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:164
[30] gradient at /home/ulg/gher/abarth/.julia/packages/Tracker/SAr25/src/back.jl:164 [inlined]
[31] macro expansion at /home/ulg/gher/abarth/.julia/packages/Flux/dkJUV/src/optimise/train.jl:71 [inlined]
[32] macro expansion at /home/ulg/gher/abarth/.julia/packages/Juno/oLB1d/src/progress.jl:134 [inlined]
[33] #train!#12(::getfield(Flux, Symbol("#throttled#18")){getfield(Flux, Symbol("##throttled#10#14")){Bool,Bool,getfield(Main, Symbol("##12#13")),Int64}}, ::Function, ::Function, ::Tracker.Params, ::Base.Iterators.Zip{Tuple{Array{CuArray{Float32,4},1}}}, ::ADAM) at /home/ulg/gher/abarth/.julia/packages/Flux/dkJUV/src/optimise/train.jl:69
[34] (::getfield(Flux.Optimise, Symbol("#kw##train!")))(::NamedTuple{(:cb,),Tuple{getfield(Flux, Symbol("#throttled#18")){getfield(Flux, Symbol("##throttled#10#14")){Bool,Bool,getfield(Main, Symbol("##12#13")),Int64}}}}, ::typeof(Flux.Optimise.train!), ::Function, ::Tracker.Params, ::Base.Iterators.Zip{Tuple{Array{CuArray{Float32,4},1}}}, ::ADAM) at ./none:0
[35] top-level scope at /home/ulg/gher/abarth/.julia/packages/Flux/dkJUV/src/optimise/train.jl:106
[36] top-level scope at /home/ulg/gher/abarth/.julia/packages/Juno/oLB1d/src/progress.jl:134
[37] top-level scope at util.jl:156
[38] include at ./boot.jl:326 [inlined]
[39] include_relative(::Module, ::String) at ./loading.jl:1038
[40] include(::Module, ::String) at ./sysimg.jl:29
[41] include(::String) at ./client.jl:403
[42] top-level scope at none:0
in expression starting at /home/users/a/b/abarth/projects/Julia/share/mnist_cae_flux2.jl:89
It could be this issue fixed in CuArrays (but not yet released).
https://github.com/JuliaGPU/CuArrays.jl/issues/378