Enzyme "Attempting to call an indirect active function whose runtime value is inactive" in Forward Over Reverse Mode

I’m attempting to apply forward over reverse mode following the Enzyme.jl tutorial. The function, f:\mathbb{R}^N \rightarrow \mathbb{R^{++}}, is complicated but doesn’t involve any terms more difficult than hyperbolic functions. Reverse mode works fine for computing the gradient, but then when I apply FoR to compute the Hessian I receive the follow and don’t understand what is happening:

ERROR: Attempting to call an indirect active function whose runtime value is inactive:
Backtrace

Stacktrace:
 [1] macro expansion
   @ C:\Users\davle\.julia\packages\Enzyme\baiSZ\src\compiler.jl:6606
 [2] enzyme_call
   @ C:\Users\davle\.julia\packages\Enzyme\baiSZ\src\compiler.jl:6207
 [3] AugmentedForwardThunk
   @ C:\Users\davle\.julia\packages\Enzyme\baiSZ\src\compiler.jl:6095
 [4] runtime_generic_augfwd
   @ C:\Users\davle\.julia\packages\Enzyme\baiSZ\src\rules\jitrules.jl:311
 [5] runtime_generic_augfwd
   @ C:\Users\davle\.julia\packages\Enzyme\baiSZ\src\rules\jitrules.jl:0

ERROR: Attempting to call an indirect active function whose runtime value is inactive:
Backtrace

Stacktrace:
 [1] macro expansion
   @ C:\Users\davle\.julia\packages\Enzyme\baiSZ\src\compiler.jl:6606
 [2] enzyme_call
   @ C:\Users\davle\.julia\packages\Enzyme\baiSZ\src\compiler.jl:6207
 [3] AugmentedForwardThunk
   @ C:\Users\davle\.julia\packages\Enzyme\baiSZ\src\compiler.jl:6095
 [4] runtime_generic_augfwd
   @ C:\Users\davle\.julia\packages\Enzyme\baiSZ\src\rules\jitrules.jl:311
 [5] runtime_generic_augfwd
   @ C:\Users\davle\.julia\packages\Enzyme\baiSZ\src\rules\jitrules.jl:0

While the function itself is likely too long to post, here is my adapted FoR template:

function fn!(z::Vector{Float64}, y::Vector{Float64})
    y[1] = compute_var_y_aug(z, t0, T, θz, θy1, σz, σy, ξ0, ξ1)
    return nothing
end

y = [0.0]
x = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
dy = [0.0]
dx = [1.0, 0.0, 0.0, 0.0, 0.0, 0.0]

bx = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
by = [1.0]
dbx = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
dby = [0.0]

Enzyme.autodiff(
    Forward,
    (zz,yy) -> Enzyme.autodiff_deferred(Reverse, fn!, zz, yy),
    Duplicated(Duplicated(z, bx), Duplicated(dx, dbx)),
    Duplicated(Duplicated(y, by), Duplicated(dy, dby)),
)

FAQ · Enzyme.jl might be helpful.

1 Like

Thanks! It sounds like it has something to do with activity of temporary storage for my specific function.

1 Like

Also, if you run it on GPU or encounter any problems, I suggest taking a look at Enzyme.jl/test at main · EnzymeAD/Enzyme.jl · GitHub.
It was very helpful for me. I think it is a common way to get some ideas on how to write your code when using any packages.

1 Like

Mind posting a complete MWE as an issue?

It’s hard to offer advice without more context on the code.

Upon creating a MWE I found that declaring all types in my functions to be <: Real resolved the issue.

If that surprises you and you want to take a look at the MWE I’ll post to Github.

Yeah still probably helpful to see!

Done. Error in Forward over Reverse Mode for Hessian · Issue #1628 · EnzymeAD/Enzyme.jl · GitHub