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

Segfault with nested differentiation triggered by @warn #2063

Open
michel2323 opened this issue Nov 5, 2024 · 3 comments
Open

Segfault with nested differentiation triggered by @warn #2063

michel2323 opened this issue Nov 5, 2024 · 3 comments

Comments

@michel2323
Copy link
Collaborator

michel2323 commented Nov 5, 2024

out.log
The code below segfaults on Julia 1.10 and Enzyme v0.13.13

using Enzyme
import .EnzymeRules: augmented_primal, reverse, Annotation, has_rrule_from_sig
using .EnzymeRules

mutable struct Model
end

function bar!()
    @warn "segfaulting soon"
    # Doesn't sefault with a println
    # println("segfaulting soon")
    return nothing
end

function loop(body::Function, model)
    body(model)
    return model
end

function augmented_primal(config, func::Const{typeof(loop)}, ret, body, model,
)
    func.val(body.val, model.val)
    return AugmentedReturn(nothing, nothing, nothing)
end

function reverse(config, ::Const{typeof(loop)}, dret::Type{<:Const}, tape, body, model::Duplicated,)
    rev_loop(body.val, model.val, model.dval)
    return (nothing, nothing)
end

function rev_loop(
    body::Function,
    model::MT,
    shadowmodel::MT,
) where {MT}
    body(model)
    Enzyme.autodiff(Reverse, Const(body), Duplicated(model, shadowmodel))
end

function foo(model)
    model = loop(model) do model
            bar!()
    end
    return nothing
end

model = Model()
dmodel = Enzyme.make_zero(model)
foo(model)
autodiff(Enzyme.Reverse, foo, Duplicated(model, dmodel))
@wsmoses
Copy link
Member

wsmoses commented Nov 5, 2024

does it err on main?

@michel2323
Copy link
Collaborator Author

Yes. I added the output log that I forgot.

@wsmoses
Copy link
Member

wsmoses commented Dec 6, 2024

@michel2323 can you check if this is resolved by #2161

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

2 participants