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

adjoint of new with fewer arguments than fields is broken #1517

Open
acertain opened this issue Aug 11, 2024 · 0 comments
Open

adjoint of new with fewer arguments than fields is broken #1517

acertain opened this issue Aug 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@acertain
Copy link

acertain commented Aug 11, 2024

MRE:

using Zygote

struct MyStruct
    x::Float64
    y::Float64
    MyStruct(x) = new(x)
end

function create_and_use(x)
    s = MyStruct(x)
    return s.x * 2
end

println(create_and_use(1.0))

gradient(create_and_use, 2.0)

output:

2.0
ERROR: LoadError: ArgumentError: new: too few arguments (expected 2)
Stacktrace:
  [1] __new__
    @ ~/.julia/packages/Zygote/nsBv0/src/tools/builtins.jl:9 [inlined]
  [2] adjoint
    @ ~/.julia/packages/Zygote/nsBv0/src/lib/lib.jl:296 [inlined]
  [3] _pullback
    @ ~/.julia/packages/ZygoteRules/M4xmc/src/adjoint.jl:67 [inlined]
  [4] MyStruct
    @ /tmp/a.jl:6 [inlined]
  [5] create_and_use
    @ /tmp/a.jl:10 [inlined]
  [6] _pullback(ctx::Zygote.Context{false}, f::typeof(create_and_use), args::Float64)
    @ Zygote ~/.julia/packages/Zygote/nsBv0/src/compiler/interface2.jl:0
  [7] pullback(f::Function, cx::Zygote.Context{false}, args::Float64)
    @ Zygote ~/.julia/packages/Zygote/nsBv0/src/compiler/interface.jl:90
  [8] pullback
    @ ~/.julia/packages/Zygote/nsBv0/src/compiler/interface.jl:88 [inlined]
  [9] gradient(f::Function, args::Float64)
    @ Zygote ~/.julia/packages/Zygote/nsBv0/src/compiler/interface.jl:147
 [10] top-level scope
    @ /tmp/a.jl:16
in expression starting at /tmp/a.jl:16

Reverting #1220 fixes, also see JuliaLang/julia#47388

This is currently breaking SciMLSensitivity ZygoteAdjoint (not the only problem though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants