"The applicable method may be too new" - Inference by loading saved BSON Flux model

Hi, I was trying to do inference with a previously trained Flux CNN that was saved with BSON with the following:

38    @load model_name model
39    model = model |> gpu
40    data = data |> gpu
41    
42    println(typeof(model))
43    t = time()
44    predict = model(data)

This is the error message I got:

Chain{Tuple{Conv{2,2,typeof(elu),CuArray{Float32,4,Nothing},CuArray{Float32,1,Nothing}},Conv{2,2,typeof(elu),CuArray{Float32,4,Nothing},CuArray{Float32,1,Nothing}},Conv{2,2,typeof(elu),CuArray{Float32,4,Nothing},CuArray{Float32,1,Nothing}},BSON.__deserialized_types__.var"##913",Dense{typeof(identity),CuArray{Float32,2,Nothing},CuArray{Float32,1,Nothing}}}}
ERROR: MethodError: no method matching (::BSON.__deserialized_types__.var"##913")(::CuArray{Float32,4,Nothing})
The applicable method may be too new: running in world age 27198, while current world is 27199.
Closest candidates are:
  #23(::Any) at D:\Work\Research\work\old\train_options.jl:78 (method too new to be called from this world context.)
Stacktrace:
 [1] applychain(::Tuple{BSON.__deserialized_types__.var"##913",Dense{typeof(identity),CuArray{Float32,2,Nothing},CuArray{Float32,1,Nothing}}}, ::CuArray{Float32,4,Nothing}) at C:\Users\me\.julia\packages\Flux\2i5P1\src\layers\basic.jl:30 (repeats 4 times)
 [2] (::Chain{Tuple{Conv{2,2,typeof(elu),CuArray{Float32,4,Nothing},CuArray{Float32,1,Nothing}},Conv{2,2,typeof(elu),CuArray{Float32,4,Nothing},CuArray{Float32,1,Nothing}},Conv{2,2,typeof(elu),CuArray{Float32,4,Nothing},CuArray{Float32,1,Nothing}},BSON.__deserialized_types__.var"##913",Dense{typeof(identity),CuArray{Float32,2,Nothing},CuArray{Float32,1,Nothing}}}})(::CuArray{Float32,4,Nothing}) at C:\Users\me\.julia\packages\Flux\2i5P1\src\layers\basic.jl:32
 [3] inference(::Array{Float32,4}, ::String, ::Bool) at D:\Work\Research\work\train\inference.jl:44
 [4] main(::Array{String,1}) at D:\Work\Research\work\train\inference.jl:96
 [5] top-level scope at none:0

The error is from line 44. The first line of the output is what the println(typeof(model)) prints. What is “world age”? How do I solve this problem?

On another note, do I have to save Flux models with BSON? Or can I do it with other IO packages like JLD?

1 Like

Hi,
I just bumped into the same issue. The problem is with loading closures, I reported it in world age issue in loading closure · Issue #69 · JuliaIO/BSON.jl · GitHub

Unfortunately, for storing closures I see no alternatives to BSON.jl