Skip to content

Test latest Enzyme #1224

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Test latest Enzyme #1224

wants to merge 1 commit into from

Conversation

ChrisRackauckas
Copy link
Member

No description provided.

@ChrisRackauckas
Copy link
Member Author

@ChrisRackauckas
Copy link
Member Author

Reproducer 1:

using SciMLSensitivity, OrdinaryDiffEq, Enzyme

u0 = [0.0]
p = [2.0, 1.0]
prob = NonlinearProblem((du, u, p) -> du[1] = u[1] - p[1] + p[2], u0, p)

function test_loss(p, prob, alg)
    _prob = remake(prob, p = p)
    sol = sum(solve(_prob, alg,
        sensealg = SteadyStateAdjoint(autojacvec = ReverseDiffVJP())))
    return sol
end

function enzyme_gradient(p, prob, alg)
    dp = Enzyme.make_zero(p)
    dprob = Enzyme.make_zero(prob)
    Enzyme.autodiff(Reverse, test_loss, Active, Duplicated(p, dp),
        Duplicated(prob, dprob), Const(alg))
    return dp
end
dp1_enzyme = enzyme_gradient(p, prob, NewtonRaphson())

Reproducer 2, I think, it's a bit hard to read the GC corruption because it messes with the line numbers, but it seems like it's this:

using OrdinaryDiffEq, SciMLSensitivity, Enzyme
Enzyme.API.typeWarning!(false)

odef(du, u, p, t) = du .= u .* p
const prob = ODEProblem(odef, [2.0], (0.0, 1.0), [3.0])

struct senseloss0{T}
    sense::T
end
function (f::senseloss0)(u0p)
    prob = ODEProblem{true}(odef, u0p[1:1], (0.0, 1.0), u0p[2:2])
    sum(solve(prob, Tsit5(), abstol = 1e-12, reltol = 1e-12, saveat = 0.1))
end
u0p = [2.0, 3.0]
du0p = zeros(2)
Enzyme.autodiff(Reverse, senseloss0(InterpolatingAdjoint()), Active, Duplicated(u0p, du0p))

@ChrisRackauckas
Copy link
Member Author

Both are related to Enzyme on the outside, not the EnzymeVJP. So it's GC corruption related to https://github.com/SciML/DiffEqBase.jl/blob/master/ext/DiffEqBaseEnzymeExt.jl. But I'm not sure what weird stuff is in that rule...

@wsmoses
Copy link

wsmoses commented Jun 30, 2025

Thread 1 received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
warning: 44	./nptl/pthread_kill.c: No such file or directory
(rr) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x000079d26ee4527e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x000079d26ee288ff in __GI_abort () at ./stdlib/abort.c:79
#5  0x000079d26ee2881b in __assert_fail_base (fmt=0x79d26efd01e8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x79d26e4cc98d "pg->osize == p->osize", 
    file=file@entry=0x79d26e4cc7e0 "/home/wmoses/git/julia11/src/gc.c", line=line@entry=1335, function=function@entry=0x79d26e4cd080 <__PRETTY_FUNCTION__.27> "jl_gc_pool_alloc_inner")
    at ./assert/assert.c:96
#6  0x000079d26ee3b517 in __assert_fail (assertion=0x79d26e4cc98d "pg->osize == p->osize", file=0x79d26e4cc7e0 "/home/wmoses/git/julia11/src/gc.c", line=1335, 
    function=0x79d26e4cd080 <__PRETTY_FUNCTION__.27> "jl_gc_pool_alloc_inner") at ./assert/assert.c:105
#7  0x000079d26e2d0632 in jl_gc_pool_alloc_inner (ptls=0x62902ca7f340, pool_offset=896, osize=48) at /home/wmoses/git/julia11/src/gc.c:1335
#8  0x000079d26e2d08a1 in jl_gc_pool_alloc_noinline (ptls=0x62902ca7f340, pool_offset=896, osize=48) at /home/wmoses/git/julia11/src/gc.c:1386
#9  0x000079d26e2cc2a3 in jl_gc_alloc_ (ptls=0x62902ca7f340, sz=40, ty=0x79d216b52ad0) at /home/wmoses/git/julia11/src/julia_internal.h:523
#10 0x000079d26e2dbc70 in jl_gc_alloc (ptls=0x62902ca7f340, sz=40, ty=0x79d216b52ad0) at /home/wmoses/git/julia11/src/gc.c:3946
#11 0x000079d26e2b4e8f in ijl_new_struct_uninit (type=0x79d216b52ad0) at /home/wmoses/git/julia11/src/datatype.c:1675
#12 0x000079d247700a8e in julia_deepcopy_internal_41466 (x=0x0, stackdict=...) at deepcopy.jl:63
#13 0x000079d2477a4563 in jfptr_deepcopy_internal_41467 () from /home/wmoses/git/julia11/usr/share/julia/compiled/v1.11/Pkg/tUTdb_YVuHj.so
#14 0x000079d26e254141 in _jl_invoke (F=0x79d25c1a3970 <jl_system_image_data+52901296>, args=0x7ffcbed12558, nargs=2, mfunc=0x79d263d87e10, world=27076)
    at /home/wmoses/git/julia11/src/gf.c:2929
#15 0x000079d26e254ca9 in ijl_apply_generic (F=0x79d25c1a3970 <jl_system_image_data+52901296>, args=0x7ffcbed12558, nargs=2) at /home/wmoses/git/julia11/src/gf.c:3125
#16 0x000079d21ba2778e in julia_deepcopy_4750 (x=0x0) at deepcopy.jl:29
#17 0x000079d21ba1e47f in jfptr_deepcopy_4751 () from /home/wmoses/.julia/compiled/v1.11/KernelAbstractions/aywHT_DX0BP.so
#18 0x000079d26e254141 in _jl_invoke (F=0x79d25c198360 <jl_system_image_data+52854688>, args=0x7ffcbed126b0, nargs=1, mfunc=0x79d263ab6a10, world=27076)
    at /home/wmoses/git/julia11/src/gf.c:2929
#19 0x000079d26e254282 in ijl_invoke (F=0x79d25c198360 <jl_system_image_data+52854688>, args=0x7ffcbed126b0, nargs=1, mfunc=0x79d263ab6a10) at /home/wmoses/git/julia11/src/gf.c:2955
#20 0x000079d2467a5ed1 in copy_or_reuse () at /home/wmoses/.julia/packages/DiffEqBase/qvEPa/ext/DiffEqBaseEnzymeExt.jl:15
#21 julia_#augmented_primal#1_16471 (kwargs=<error reading variable: Cannot access memory at address 0x3fb999999999999a>, config=..., func=..., prob=..., sensealg=..., u0=..., p=..., 
    args...=...) at /home/wmoses/.julia/packages/DiffEqBase/qvEPa/ext/DiffEqBaseEnzymeExt.jl:25
#22 0x000079d2467a72ab in julia_augmented_primal_16465 (prob=..., u0=..., p=<error reading variable: Cannot access memory at address 0x0>, config=..., func=..., sensealg=..., args...=...)
    at /home/wmoses/.julia/packages/DiffEqBase/qvEPa/ext/DiffEqBaseEnzymeExt.jl:9
#23 julia_#solve#43_2038 (sensealg=..., u0=..., p=..., wrap=..., kwargs=..., prob=..., args...=...) at /home/wmoses/.julia/packages/DiffEqBase/qvEPa/src/solve.jl:1096
#24 0x000079d2467a7a22 in solve () at /home/wmoses/.julia/packages/DiffEqBase/qvEPa/src/solve.jl:1086
#25 julia_loss_2021 (u0=<optimized out>, p=<optimized out>) at /home/wmoses/git/Enzyme.jl/con.jl:12
#26 0x000079d2467a7a22 in julia_loss_2021 (u0=<optimized out>, p=<optimized out>)
#27 0x000079d2467a7a22 in diffejulia_loss_2021_inner_1wrap ()
#28 0x000079d2467aa227 in macro expansion () at /home/wmoses/git/Enzyme.jl/src/compiler.jl:5493
#29 enzyme_call () at /home/wmoses/git/Enzyme.jl/src/compiler.jl:5027
#30 CombinedAdjointThunk () at /home/wmoses/git/Enzyme.jl/src/compiler.jl:4902
#31 autodiff () at /home/wmoses/git/Enzyme.jl/src/Enzyme.jl:517
#32 julia_autodiff_19897 (mode=..., f=..., args...=...) at /home/wmoses/git/Enzyme.jl/src/Enzyme.jl:538
#33 0x000079d2467aa263 in jfptr_autodiff_19898 ()
#34 0x000079d26e254226 in _jl_invoke (F=0x79d26e8bd3a0 <jl_system_image_data+111712>, args=0x7ffcbed12c88, nargs=5, mfunc=0x79d1f3e35110, world=27076)
    at /home/wmoses/git/julia11/src/gf.c:2948
#35 0x000079d26e254ca9 in ijl_apply_generic (F=0x79d26e8bd3a0 <jl_system_image_data+111712>, args=0x7ffcbed12c88, nargs=5) at /home/wmoses/git/julia11/src/gf.c:3125
#36 0x000079d26e279db4 in jl_apply (args=0x7ffcbed12c80, nargs=6) at /home/wmoses/git/julia11/src/julia.h:2157
#37 0x000079d26e27a272 in do_call (args=0x79d1f3e85290, nargs=6, s=0x7ffcbed13110) at /home/wmoses/git/julia11/src/interpreter.c:126
#38 0x000079d26e27ab43 in eval_value (e=0x79d1f3e412d0, s=0x7ffcbed13110) at /home/wmoses/git/julia11/src/interpreter.c:223
#39 0x000079d26e27a644 in eval_stmt_value (stmt=0x79d1f3e412d0, s=0x7ffcbed13110) at /home/wmoses/git/julia11/src/interpreter.c:174
#40 0x000079d26e27d1d2 in eval_body (stmts=0x79d1f3e41030, s=0x7ffcbed13110, ip=13, toplevel=1) at /home/wmoses/git/julia11/src/interpreter.c:666
#41 0x000079d26e27e0ac in jl_interpret_toplevel_thunk (m=0x79d25bff0520 <jl_system_image_data+51118432>, src=0x79d2182e9720) at /home/wmoses/git/julia11/src/interpreter.c:824
#42 0x000079d26e2a8a3f in jl_toplevel_eval_flex (m=0x79d25bff0520 <jl_system_image_data+51118432>, e=0x79d265155f90, fast=1, expanded=0) at /home/wmoses/git/julia11/src/toplevel.c:943
#43 0x000079d26e2a8524 in jl_toplevel_eval_flex (m=0x79d25bff0520 <jl_system_image_data+51118432>, e=0x79d265156250, fast=1, expanded=0) at /home/wmoses/git/julia11/src/toplevel.c:886
#44 0x000079d26e2a8a9f in ijl_toplevel_eval (m=0x79d25bff0520 <jl_system_image_data+51118432>, v=0x79d265156250) at /home/wmoses/git/julia11/src/toplevel.c:952
#45 0x000079d26e2a8d04 in ijl_toplevel_eval_in (m=0x79d25bff0520 <jl_system_image_data+51118432>, ex=0x79d265156250) at /home/wmoses/git/julia11/src/toplevel.c:994
#46 0x000079d258aba402 in eval () at boot.jl:430
#47 japi1_include_string_72421 (mapexpr=..., mod=0x79d26547fb30, code=0x271, filename=0x21) at loading.jl:2734
#48 0x000079d26e252d7c in jl_fptr_args (f=0x79d25b73b060 <jl_system_image_data+41987232>, args=0x7ffcbed13b50, nargs=4, m=0x79d25b73bf50 <jl_system_image_data+41991056>)
    at /home/wmoses/git/julia11/src/gf.c:2590
#49 0x000079d26e254141 in _jl_invoke (F=0x79d25b73b060 <jl_system_image_data+41987232>, args=0x7ffcbed13b50, nargs=4, mfunc=0x79d25b73bf00 <jl_system_image_data+41990976>, world=26680)
    at /home/wmoses/git/julia11/src/gf.c:2929
--Type <RET> for more, q to quit, c to continue without paging--q
Quit
(rr) f 7
#7  0x000079d26e2d0632 in jl_gc_pool_alloc_inner (ptls=0x62902ca7f340, pool_offset=896, osize=48) at /home/wmoses/git/julia11/src/gc.c:1335
1335	            assert(pg->osize == p->osize);
(rr) p pg->osize
$1 = 121
(rr) p p->osize
$2 = 48
(rr) l
1330	        p->freelist = next;
1331	        if (__unlikely(gc_page_data(v) != gc_page_data(next))) {
1332	            // we only update pg's fields when the freelist changes page
1333	            // since pg's metadata is likely not in cache
1334	            jl_gc_pagemeta_t *pg = jl_assume(page_metadata_unsafe(v));
1335	            assert(pg->osize == p->osize);
1336	            pg->nfree = 0;
1337	            pg->has_young = 1;
1338	        }
1339	        msan_allocated_memory(v, osize);
(rr) f 19
#19 0x000079d26e254282 in ijl_invoke (F=0x79d25c198360 <jl_system_image_data+52854688>, args=0x7ffcbed126b0, nargs=1, mfunc=0x79d263ab6a10) at /home/wmoses/git/julia11/src/gf.c:2955
2955	    return _jl_invoke(F, args, nargs, mfunc, world);
(rr) p args[0]
$3 = (jl_value_t *) 0x79d26428cb80
(rr) p jl_(args[0])
SciMLBase.ODEProblem{Array{Float64, 1}, Tuple{Float64, Float64}, true, Array{Float64, 1}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, typeof(Main.fiip), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}(f=SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, typeof(Main.fiip), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}(f=typeof(Main.fiip)(), mass_matrix=LinearAlgebra.UniformScaling{Bool}(λ=true), analytic=nothing, tgrad=nothing, jac=nothing, jvp=nothing, vjp=nothing, jac_prototype=nothing, sparsity=nothing, Wfact=nothing, Wfact_t=nothing, W_prototype=nothing, paramjac=nothing, observed=typeof(SciMLBase.DEFAULT_OBSERVED)(), colorvec=nothing, sys=nothing, initialization_data=nothing, nlprob_data=nothing), u0=Array{Float64, 1}(dims=(2,), mem=Memory{Float64}(2, 0x79d263854530)[1, 1]), tspan=(0, 10), p=Array{Float64, 1}(dims=(4,), mem=Memory{Float64}(4, 0x79d1f3f6dbe0)[1.5, 1, 3, 1]), kwargs=Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}(data=NamedTuple(), itr=()), problem_type=SciMLBase.StandardODEProblem())
$4 = void
(rr) f 10
#10 0x000079d26e2dbc70 in jl_gc_alloc (ptls=0x62902ca7f340, sz=40, ty=0x79d216b52ad0) at /home/wmoses/git/julia11/src/gc.c:3946
3946	    return jl_gc_alloc_(ptls, sz, ty);
(rr) p jl_(ty)
SciMLBase.ODEProblem{Array{Float64, 1}, Tuple{Float64, Float64}, true, Array{Float64, 1}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, typeof(Main.fiip), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}
$5 = void
(rr) q

appears to be in the deepcopy

@wsmoses
Copy link

wsmoses commented Jun 30, 2025

This should now be fixed upstream, @ChrisRackauckas can you rerun?

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 this pull request may close these issues.

2 participants