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

Backdrop error with static unfold #476

Open
Joaoloula opened this issue Aug 10, 2022 · 0 comments
Open

Backdrop error with static unfold #476

Joaoloula opened this issue Aug 10, 2022 · 0 comments

Comments

@Joaoloula
Copy link

The following works fine:

@gen (grad) function kernel(t::Int, (grad)(a::Real))
    z ~ normal(a, 1)
    return z
end

chain = Gen.Unfold(kernel)
T = 3
trace = Gen.simulate(chain, (T, 0.))

choice_gradients(trace, select(T => :z))

But if I change the annotation to (static, grad), all of a sudden gradients for the last timestep don't work anymore (strangely the gradients work fine for every timestep before that), and I get the following error:

MethodError: no method matching +(::Float64, ::Nothing)
Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/operators.jl:655
  +(::Union{Float16, Float32, Float64}, ::BigFloat) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/mpfr.jl:413
  +(::AbstractFloat, ::Bool) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/bool.jl:172
  ...

Stacktrace:
 [1] macro expansion
   @ ~/.julia/packages/Gen/Dne3u/src/static_ir/backprop.jl:502 [inlined]
 [2] choice_gradients(trace::var"##StaticIRTrace_kernel#1797", selection::StaticSelection{(:z,), Tuple{AllSelection}}, retval_grad::Nothing)
   @ Main ~/.julia/packages/Gen/Dne3u/src/static_ir/backprop.jl:502
 [3] macro expansion
   @ ~/.julia/packages/Gen/Dne3u/src/static_ir/backprop.jl:396 [inlined]
 [4] choice_gradients(trace::var"##StaticIRTrace_kernel#1797", selection::DynamicSelection, retval_grad::Nothing)
   @ Main ~/.julia/packages/Gen/Dne3u/src/static_ir/backprop.jl:502
 [5] choice_gradients(trace::Gen.VectorTrace{Gen.UnfoldType, Float64, var"##StaticIRTrace_kernel#1797"}, selection::DynamicSelection, retval_grad::Nothing)
   @ Gen ~/.julia/packages/Gen/Dne3u/src/modeling_library/unfold/backprop.jl:39
 [6] choice_gradients(trace::Gen.VectorTrace{Gen.UnfoldType, Float64, var"##StaticIRTrace_kernel#1797"}, selection::DynamicSelection)
   @ Gen ~/.julia/packages/Gen/Dne3u/src/gen_fn_interface.jl:405
 [7] top-level scope
   @ In[482]:13
 [8] eval
   @ ./boot.jl:373 [inlined]
 [9] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196

Not sure why this happens---any thoughts?

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

No branches or pull requests

1 participant