Hi, I’m trying to train MNIST over GPU using julia, but I face the following error.
here is my code:
X = hcat(float.(reshape.(imgs, :))...) |>gpu;
Y = onehotbatch(labels, 0:9) |> gpu;
batches=[(X[:,:,:,i],Y[:,i]) for i in partition(1:size(X,4),100)];
m = Chain(
Dense(28^2, 32, relu),
Dense(32, 10),
softmax) |>gpu
loss(x, y) = crossentropy(m(x), y)
accuracy(x, y) = mean(onecold(m(x)) .== onecold(y))
evalcb = throttle(() -> @show(accuracy(X, Y)), 600)
opt = ADAM(params(m))
@time @epochs 45 Flux.train!(loss, batches, opt, cb = evalcb)
Here is the error:
MethodError: no method matching *(::TrackedArray{…,CuArray{Float32,2}}, ::CuArray{Float32,4})
Closest candidates are:
*(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:502
*(::TrackedArray{T,2,A} where A where T, !Matched::TrackedArray{T,2,A} where A where T) at /home/fadi/.julia/packages/Flux/jsf3Y/src/tracker/array.jl:320
*(::TrackedArray{T,2,A} where A where T, !Matched::TrackedArray{T,1,A} where A where T) at /home/fadi/.julia/packages/Flux/jsf3Y/src/tracker/array.jl:324
...
Stacktrace:
[1] (::Dense{typeof(relu),TrackedArray{…,CuArray{Float32,2}},TrackedArray{…,CuArray{Float32,1}}})(::CuArray{Float32,4}) at /home/fadi/.julia/packages/Flux/jsf3Y/src/layers/basic.jl:80
[2] (::getfield(Flux, Symbol("##60#61")))(::CuArray{Float32,4}, ::Dense{typeof(relu),TrackedArray{…,CuArray{Float32,2}},TrackedArray{…,CuArray{Float32,1}}}) at /home/fadi/.julia/packages/Flux/jsf3Y/src/layers/basic.jl:31
[3] mapfoldl_impl(::typeof(identity), ::getfield(Flux, Symbol("##60#61")), ::NamedTuple{(:init,),Tuple{CuArray{Float32,4}}}, ::Array{Any,1}) at ./reduce.jl:43
[4] #mapfoldl#170 at ./reduce.jl:70 [inlined]
[5] #mapfoldl at ./none:0 [inlined]
[6] #foldl#171 at ./reduce.jl:88 [inlined]
[7] #foldl at ./none:0 [inlined]
[8] (::Chain)(::CuArray{Float32,4}) at /home/fadi/.julia/packages/Flux/jsf3Y/src/layers/basic.jl:31
[9] loss(::CuArray{Float32,4}, ::Flux.OneHotMatrix{CuArray{Flux.OneHotVector,1}}) at ./In[18]:6
[10] #train!#121(::getfield(Flux, Symbol("#throttled#18")){getfield(Flux, Symbol("##throttled#10#14")){Bool,Bool,getfield(Main, Symbol("##12#13")),Int64}}, ::Function, ::Function, ::Array{Tuple{CuArray{Float32,4},Flux.OneHotMatrix{CuArray{Flux.OneHotVector,1}}},1}, ::getfield(Flux.Optimise, Symbol("##43#47"))) at /home/fadi/.julia/packages/Juno/46C8i/src/progress.jl:109
[11] (::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, ::Array{Tuple{CuArray{Float32,4},Flux.OneHotMatrix{CuArray{Flux.OneHotVector,1}}},1}, ::Function) at ./none:0
[12] top-level scope at /home/fadi/.julia/packages/Juno/46C8i/src/progress.jl:109