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

Mixed type, variable length, memcpy #1672

Open
jgreener64 opened this issue Jul 24, 2024 · 0 comments
Open

Mixed type, variable length, memcpy #1672

jgreener64 opened this issue Jul 24, 2024 · 0 comments

Comments

@jgreener64
Copy link
Contributor

I am on Julia 1.10.3 and Enzyme main (5fc2309). The following works:

struct A1{T}
    x::T
end

struct B{T}
    as::T
end

function f1(x, ::Val{AT}) where AT
    as = [A1(x) for i in 1:10]
    as2 = AT(as)
    b = B(as2)
    return b.as[1].x
end

autodiff(Reverse, f1, Active, Active(2.0), Const(Val(Array)))[1][1] # Gives 1.0

However, adding an unused field to the struct makes the gradient disappear:

struct A2{T}
    index::Int
    x::T
end

function f2(x, ::Val{AT}) where AT
    as = [A2(i, x) for i in 1:10]
    as2 = AT(as)
    b = B(as2)
    return b.as[1].x
end

autodiff(Reverse, f2, Active, Active(2.0), Const(Val(Array)))[1][1] # Gives 0.0, should be 1.0
@wsmoses wsmoses changed the title Zero gradient with array conversion Mixed type, variable length, memcpy Sep 28, 2024
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