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

UndefVarError: CodeInfo not defined #1756

Closed
andreasko opened this issue Dec 23, 2021 · 9 comments · Fixed by #1762
Closed

UndefVarError: CodeInfo not defined #1756

andreasko opened this issue Dec 23, 2021 · 9 comments · Fixed by #1762

Comments

@andreasko
Copy link

andreasko commented Dec 23, 2021

Hey all,

after switching Julia from 1.6.2 to 1.6.5, I experience problems when using ReverseDiff in combination with Memoization, The following MWE fails:

using Turing
using Memoization
using ReverseDiff
setadbackend(:reversediff)
Turing.setrdcache(true)


@model function demo(xs)
   s ~ InverseGamma(2, 3)
   m ~ Normal(10, s)
   xs .~ Normal(m, s)
end
model = demo(randn(10));
chain = sample(model, NUTS(), 10);

The full error message is

UndefVarError: CodeInfo not defined
in eval at base/boot.jl:360 
in top-level scope at test_regional.jl
in top-level scope at base/timing.jl:210 
in macro expansion at test_regional.jl:112 
in  at Turing/uMQmD/src/inference/Inference.jl:132
in #sample#1 at Turing/uMQmD/src/inference/Inference.jl:132 
in sample##kw at Turing/uMQmD/src/inference/Inference.jl:142 
in #sample#2 at Turing/uMQmD/src/inference/Inference.jl:142 
in sample##kw at Turing/uMQmD/src/inference/hmc.jl:116 
in var"#sample#40" at Turing/uMQmD/src/inference/hmc.jl:133
in  at AbstractMCMC/BPJCW/src/sample.jl:107
in var"#mcmcsample#20" at AbstractMCMC/BPJCW/src/sample.jl:114
in macro expansion at AbstractMCMC/BPJCW/src/logging.jl:8 
in macro expansion at ProgressLogging/6KXlp/src/ProgressLogging.jl:328 
in macro expansion at AbstractMCMC/BPJCW/src/sample.jl:123 
in step##kw at DynamicPPL/RcfQU/src/sampler.jl:62 
in var"#step#17" at DynamicPPL/RcfQU/src/sampler.jl:87
in  at Turing/uMQmD/src/inference/hmc.jl:153
in var"#initialstep#41" at Turing/uMQmD/src/inference/hmc.jl:167
in phasepoint at AdvancedHMC/HQHnm/src/hamiltonian.jl:153 
in phasepoint at AdvancedHMC/HQHnm/src/hamiltonian.jl:76 
in ∂H∂θ at AdvancedHMC/HQHnm/src/hamiltonian.jl:31
in ∂logπ∂θ at Turing/uMQmD/src/inference/hmc.jl:433 
in gradient_logp at Turing/uMQmD/src/core/ad.jl:83 
in gradient_logp at Turing/uMQmD/src/core/ad.jl:83 
in gradient_logp at Turing/uMQmD/src/core/compat/reversediff.jl:69 
in memoized_taperesult at Turing/uMQmD/src/core/compat/reversediff.jl:86 
in memoized_taperesult at Memoization/LiJeV/src/Memoization.jl:98
in  at base/boot.jl:571
in var"#s487#29" at base/none
in #s487#29 at Memoization/LiJeV/src/Memoization.jl:117

Sorry in advance if this is not related to Turing but rather to Memoization but, I can't make much sense of the error message.

Cheers!

Edit:
Here is the package list

Memoization v0.1.13
ReverseDiff v1.12.0
Turing v0.19.2

@devmotion
Copy link
Member

Does it work without memoization?

@andreasko
Copy link
Author

yes, when setting Turing.setrdcache(false) the above example works

@devmotion
Copy link
Member

Test errors on the master branch are caused by the same error (eg https://github.com/TuringLang/Turing.jl/runs/4629430127?check_suite_focus=true#step:6:379). It seems tests pass with previous Julia versions (< 1.6.5) and is only present in Julia 1.6.5. Thus it seems one of the changes in Julia 1.6.5 broke memoization. I assume it is an upstream bug in Memoization but I don't have a non-Turing example (put away my computer for some days 🎅).

@torfjelde
Copy link
Member

torfjelde commented Jan 13, 2022

Likely the cause: https://github.com/JuliaLang/julia/blob/9058264a69f9efc1af805c4473c946f87859b731/base/expr.jl#L432-L433

Uncertain how it exactly affects Memoize.jl though.

@devmotion
Copy link
Member

Sorry, forgot about this issue when I got hold of my computer again.

Uncertain how it exactly affects Memoize.jl though.

I don't think it affects Memoization.jl at all - I think it's another case where the name Core for a module in Turing is problematic due to incorrect escaping, similar to simonster/Reexport.jl#33 (comment). I assume Julia tries to resolve Core.CodeInfo in https://github.com/JuliaLang/julia/blob/9058264a69f9efc1af805c4473c946f87859b731/base/expr.jl#L432-L433 as Turing.Core.CodeInfo but of course this is not defined.

@devmotion
Copy link
Member

It's unfortunate that this time the escaping problem is in base Julia and hence it will take much more time until a fix is available (I would assume it would be backported to 1.6 but I have no clue about the release cycle). Hence it is probably much easier and faster to rename Turing.Core.

@torfjelde
Copy link
Member

torfjelde commented Jan 14, 2022

Aaaah one of those again.. And yeah, I'm in the process of renaming it right now.
But indeed seems interpolation of Core.CodeInfo in @generated fixes the issue; just added anoverload to @generated and now memoization works without issues.

@devmotion
Copy link
Member

And yeah, I'm in the process of renaming it right now.

Ah, missed this and opened a separate PR 😄

@devmotion
Copy link
Member

BTW the @generated macro is fixed in the master branch of Julia, and the bugfix will be backported to Julia 1.6 and 1.7.

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