Open CarloLucibello opened 4 years ago
This is part of how Julia works:
julia> function test()
f = eval(:(x -> x))
f(1)
end
test (generic function with 1 method)
julia> test()
ERROR: MethodError: no method matching (::var"#3#4")(::Int64)
The applicable method may be too new: running in world age 26764, while current world is 26765.
So I'm not sure there's much we can do about it. I'd suggest that this is a bad code pattern and one should just stick to loading bson files at the toplevel.
If you really need it, you can use invokelatest
.
I had similar problem too, I solved it by modifying the function I want to serialize in a way that all used variables are used as the input, so the function does not depend on the outer context. Then it works. Although it's a bit annoying, it's definitely less fragile.
While working at https://github.com/FluxML/model-zoo/pull/209, I encountered the following problem when loading a saved closure within the function
train
:Notice that if I just execute the body of the function in REPL, everything works fine: