JuliaIO / BSON.jl

Other
158 stars 39 forks source link

BSON error when used to load weights in module / package #52

Open Ayushk4 opened 4 years ago

Ayushk4 commented 4 years ago

I am trying something like the following and the error I get is ERROR: UndefVarError: Tracker not defined

Steps to replicate this -

  1. Let ExampleModule.jl file be the following
    module ExampleModule
    using BSON, Tracker, Flux
    include("./file1.jl")
    end
  2. And here is the code in file1.jl
    function load_weights(path) # Loading weights
    c = BSON.load(path)
    return c
    end
  3. Create and save weights like using Flux; using BSON: @save;,w = param(rand(2,2)) and then @save "wt.bson" w.
  4. In a new REPL session , if I do the following -
    
    julia> include("ExampleModule.jl")

julia> ExampleModule.load_weights("wt.bson") ERROR: UndefVarError: Tracker not defined

It throws an error. The same thing happens if `w` in step 3. is replaced by `Flux.Conv` as well.
Also if I do `using Tracker, Flux` at the top level (i.e. in REPL session - step 4.) this starts working fine. Exporting Tracker and Flux also work fine, except for the tests.

The above example is a simplified version to recreate the error I am facing in JuliaText/TextAnalysis.jl#167

## Other Info

Flux v0.8.3 BSON v0.2.3 Julia 1.0.3 OS - Ubuntu 18.04.2 LTS - 64-bit although with Travis CI, doesn't work on osx.



From the looks of it, BSON searches for Tracker and Flux at the topmost level. Am I missing something here?