Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module files that import LightGBM fail to compile #71

Closed
msekino opened this issue Oct 12, 2020 · 18 comments · Fixed by #73
Closed

Module files that import LightGBM fail to compile #71

msekino opened this issue Oct 12, 2020 · 18 comments · Fixed by #73

Comments

@msekino
Copy link
Contributor

msekino commented Oct 12, 2020

I'd like to use LightGBM in a module file.
I made a project "Example" and wrote a following code in Example.jl

module Example
using LightGBM
end

using Example resulted in the following.

┌ Info: Precompiling Example [9e033b86-410e-4dd2-a032-f2c9367e52e7]
└ @ Base loading.jl:1278
ERROR: LoadError: InitError: Evaluation into the closed module `LightGBM` breaks incremental compilation because the side effects will not be permanent. This is likely due to some other module mutating `LightGBM` with `include` during precompilation - don't do this.
Stacktrace:
...

Temporarily, it is possible to avoid the error by putting __precompile__(false) to the beginning of the file, but it doesn't seem to be a very preferred solution.

@yalwan-iqvia
Copy link
Collaborator

Hi @msekino ! Thanks for taking the time to report this

After a quick bit of digging it seems it is due to this:

include(joinpath(@__DIR__, "MLJInterface.jl"))

I'll have to figure out why I did it and then stop doing it without breaking it. I will keep you up to date with this. Hopefully the fix can make it soon.

@yalwan-iqvia
Copy link
Collaborator

WARNING: eval into closed module MLJModelInterface:
:Bool
  ** incremental compilation may be fatally broken for this module **

WARNING: eval into closed module MLJModelInterface:
:Bool
  ** incremental compilation may be fatally broken for this module **

WARNING: eval into closed module MLJModelInterface:
:Bool
  ** incremental compilation may be fatally broken for this module **

WARNING: eval into closed module MLJModelInterface:
:Bool
  ** incremental compilation may be fatally broken for this module **

I think I did it to stop this class of warnings appearing. However, it seems like its no consequence for me to remove this include from the init, which would fix the issue. I will go to MLJ project and see what I can do to suppress those warnings.

I will try to come with a fix soon.

@yalwan-iqvia
Copy link
Collaborator

@ablaom do you know what I might do in order to stop those warnings appearing?

@ablaom
Copy link
Contributor

ablaom commented Oct 12, 2020

Yeah, I've also had problems using eval(and hence macros) inside an __init__ function (see JuliaAI/MLJModels.jl#74). What's the reason for including the file MLJInterface.jl post facto ? If you move it out of __init__ I expect the warnings will go away.

Maybe this helps: JuliaLang/julia#29059 .

@yalwan-iqvia
Copy link
Collaborator

Sorry, I was a little unclear. I was asking because it occurs when I move it out of __init__

@ablaom
Copy link
Contributor

ablaom commented Oct 13, 2020

Oh, I see. This looks like a problem with MLJModelInterface.jl.

My guess is there is an issue with metadata_pkg and metadata_model methods, which have eval in them. Maybe something to do with use of parentmodule, but I'm not sure and not completely understanding why this has not come up with other interfaces. I will investigate. cc @tlienart

Would be helpful to know if you get the warnings if you remove the module wrapping of the code in MLJlInterface.jl.

If my suspicions are right, a solution for you might be to replace the calls to metadata_pkg and metadata_model with explicit trait definitions. (Personally, I prefer this anyhow). See the attached screenshot, which is from https://alan-turing-institute.github.io/MLJ.jl/dev/adding_models_for_general_use/#Trait-declarations-1

Screen Shot 2020-10-14 at 8 07 09 AM

@yalwan-iqvia
Copy link
Collaborator

@yalwan-iqvia
Copy link
Collaborator

@ablaom
Copy link
Contributor

ablaom commented Oct 14, 2020

Yes that's it. Good catch. This needs to be evaluated in the module from where the @mlj_macro is called, which must according be passed to the function you point out as an argument.

Working on a new release of MLJModelsInterface. Thanks for bringing this to my attention.

ablaom added a commit to JuliaAI/MLJModelInterface.jl that referenced this issue Oct 14, 2020
@ablaom
Copy link
Contributor

ablaom commented Oct 14, 2020

@msekino When JuliaRegistries/General#22970 is merged, would you be so kind as to update your project env and confirm that my fix resolves your issue?

@ablaom
Copy link
Contributor

ablaom commented Oct 14, 2020

Oh sorry. @yalwan-iqvia will first need to move the include out of __init__ for this to work.

@msekino
Copy link
Contributor Author

msekino commented Oct 15, 2020

@ablaom Thank you for your help!

I just updated as follows.

(@v1.5) pkg> up
   Updating registry at `C:\Users\msekino\.julia\registries\General`
  Installed MLJModelInterface ─ v0.3.6
  ...
Updating `C:\Users\msekino\.julia\environments\v1.5\Project.toml`
  ...
Updating `C:\Users\msekino\.julia\environments\v1.5\Manifest.toml`
  [e80e1ace] ↑ MLJModelInterface v0.3.5 ⇒ v0.3.6
  ...

I made a project "Example"

julia> using PkgTemplates
[ Info: Precompiling PkgTemplates [14b8a8f1-9102-5b29-a752-f990bacb7fe1]

julia> t = Template(user = "msekino")
  ...

julia> t("Example")
  ...

then, I wrote Example.jl

module Example
using LightGBM
end

However, using Example resulted in the following.

julia> using Example
[ Info: Precompiling Example [400a67cc-5385-4025-bc17-a97de4bd9e1e]
ERROR: LoadError: InitError: Evaluation into the closed module `LightGBM` breaks incremental compilation because the side effects will not be permanent. This is likely due to some other module mutating `LightGBM` with `include` during precompilation - don't do this.
Stacktrace:
 [1] include(::Function, ::Module, ::String) at .\Base.jl:380
 [2] include at .\Base.jl:368 [inlined]
 [3] include at C:\Users\msekino\.julia\packages\LightGBM\3uotD\src\LightGBM.jl:1 [inlined]
 [4] __init__() at C:\Users\msekino\.julia\packages\LightGBM\3uotD\src\LightGBM.jl:21
 [5] _include_from_serialized(::String, ::Array{Any,1}) at .\loading.jl:697
 [6] _require_from_serialized(::String) at .\loading.jl:749
 [7] _require(::Base.PkgId) at .\loading.jl:1040
 [8] require(::Base.PkgId) at .\loading.jl:928
 [9] require(::Module, ::Symbol) at .\loading.jl:923
 [10] include(::Function, ::Module, ::String) at .\Base.jl:380
 [11] include(::Module, ::String) at .\Base.jl:368
 [12] top-level scope at none:2
 [13] eval at .\boot.jl:331 [inlined]
 [14] eval(::Expr) at .\client.jl:467
 [15] top-level scope at .\none:3
during initialization of module LightGBM
in expression starting at D:\workspace\private\Julia\Example\src\Example.jl:3
ERROR: Failed to precompile Example [400a67cc-5385-4025-bc17-a97de4bd9e1e] to C:\Users\msekino\.julia\compiled\v1.5\Example\UxrAa_P2WnP.ji.
Stacktrace:
 [1] error(::String) at .\error.jl:33
 [2] compilecache(::Base.PkgId, ::String) at .\loading.jl:1305
 [3] _require(::Base.PkgId) at .\loading.jl:1030
 [4] require(::Base.PkgId) at .\loading.jl:928
 [5] require(::Module, ::Symbol) at .\loading.jl:923

I'm not sure what caused it. And I'm sorry if I'm doing something wrong...

@yalwan-iqvia
Copy link
Collaborator

@msekino hey sorry for the confusion. What's going on here is that @ablaom has made a fix to an upstream project which I will test now and then make a release. So you'll need an updated version of LightGBM.jl (which I am working on now)

@yalwan-iqvia
Copy link
Collaborator

@ablaom I've done this but do you think there might be a better way?
58661c6

@yalwan-iqvia
Copy link
Collaborator

@msekino when this merge is complete JuliaRegistries/General#22979

it should hopefully resolve your issue. You will need to make sure to update to LightGBM.jl >= 0.3.2

@msekino
Copy link
Contributor Author

msekino commented Oct 15, 2020

@yalwan-iqvia @ablaom
Now I was able to precompile the module without problems!
Thank you very much for the quick resolution!

@msekino msekino closed this as completed Oct 15, 2020
@yalwan-iqvia
Copy link
Collaborator

Thanks for reporting and thanks Anthony for the super quick response 😄

@ablaom
Copy link
Contributor

ablaom commented Oct 15, 2020

@ablaom I've done this but do you think there might be a better way?
58661c6

Nope. That's the way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants