You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This isn't that big a deal, as the workarounds are fairly obvious, but it is rather strange. Note this seems very related (same root issue?) as #1114.
This is on the latest Flux Master. IDE is Windows-Juno with Julia 1.4.
using Revise, CUDAapi, Flux, BenchmarkTools
import CuArrays
struct MWEStruct{Ta<:AbstractVector, Tb<:AbstractVector}
a::Ta
b::TbendMWEStruct(N) =MWEStruct(rand(N), rand(N))
(m::MWEStruct)(x) = x
functionmwe(N)
Flux.@functor MWEStruct
cpustruct =MWEStruct(N)
println("type of cpu struct: ", typeof(cpustruct))
gpustruct = cpustruct |> gpu
println("type of gpu struct: ", typeof(gpustruct))
endprintln("First run:")
mwe(10)
println("\nSecond run:")
mwe(10)
Output:
First run:
type of cpu struct: MWEStruct{Array{Float64,1},Array{Float64,1}}
type of gpu struct: MWEStruct{Array{Float64,1},Array{Float64,1}}
Second run:
type of cpu struct: MWEStruct{Array{Float64,1},Array{Float64,1}}
type of gpu struct: MWEStruct{CuArrays.CuArray{Float32,1,Nothing},CuArrays.CuArray{Float32,1,Nothing}}
The text was updated successfully, but these errors were encountered:
I believe this is because you call the functor macro inside a function. Put it somewhere outside, e.g right after the declaration of MWEStruct.
This explanation might not be 100%, but here's my understanding of it: The function it creates for you will not be available until you hit the global scope so that the world age advances which in this case is after mwe returns. Search for "world age problem julia language" for more info.
This isn't that big a deal, as the workarounds are fairly obvious, but it is rather strange. Note this seems very related (same root issue?) as #1114.
This is on the latest Flux Master. IDE is Windows-Juno with Julia 1.4.
Output:
The text was updated successfully, but these errors were encountered: