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

ADTypes.AutoMooncake(; config=nothing) doesn't work #280

Closed
penelopeysm opened this issue Oct 3, 2024 · 0 comments · Fixed by #281
Closed

ADTypes.AutoMooncake(; config=nothing) doesn't work #280

penelopeysm opened this issue Oct 3, 2024 · 0 comments · Fixed by #281

Comments

@penelopeysm
Copy link
Contributor

penelopeysm commented Oct 3, 2024

Initialising ADTypes.AutoMooncake(; config=nothing) doesn't seem to use a config of Mooncake.Config() by default.

The following MWE uses a feature branch of Turing.jl (TuringLang/Turing.jl#2341):

using Turing
import Mooncake
backend = Turing.AutoMooncake(; config=nothing)  # reexported from ADTypes
@model f() = x ~ Normal(0, 1)
sample(f(), HMC(0.1, 3; adtype=backend), 10)

# works with backend = Turing.AutoMooncake(; config=Mooncake.Config())

The error:

ERROR: type Nothing has no field debug_mode
Stacktrace:
  [1] getproperty(x::Nothing, f::Symbol)
    @ Base ./Base.jl:37
  [2] ADgradient(x::AutoMooncake{…}, ℓ::LogDensityFunction{…})
    @ MooncakeLogDensityProblemsADExt ~/.julia/packages/Mooncake/eEGqO/ext/MooncakeLogDensityProblemsADExt.jl:63
  [3] ADgradient(ℓ::LogDensityFunction{DynamicPPL.TypedVarInfo{…}, DynamicPPL.Model{…}, DynamicPPL.SamplingContext{…}})
    @ Turing.Inference ~/ppl/lib/src/mcmc/Inference.jl:154
  [4] initialstep(rng::Random.TaskLocalRNG, model::DynamicPPL.Model{…}, spl::DynamicPPL.Sampler{…}, vi_original::DynamicPPL.TypedVarInfo{…}; initial_params::Nothing, nadapts::Int64, kwargs::@Kwargs{})
    @ Turing.Inference ~/ppl/lib/src/mcmc/hmc.jl:159
[...]

which points to at least this:

# Interop with ADTypes.
function ADgradient(x::ADTypes.AutoMooncake, ℓ)
debug_mode = x.config.debug_mode
if debug_mode
msg = "Running Mooncake in debug mode. This mode is computationally expensive, " *
"should only be used when debugging a problem with AD, and turned off in " *
"general use. Do this by using " *
"AutoMooncake(; config=Mooncake.Config(debug_mode=false))."
@info msg
end
return ADgradient(Val(:Mooncake), ℓ; debug_mode)
end

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.

1 participant