Skip to content

AD failure where Zygote succeeds  #63

@marius311

Description

@marius311

MWE:

julia> Zygote.gradient(nt -> nt.x^2, (x=1.,))
((x = 2.0,),)

julia> AD.gradient(AD.ZygoteBackend(), nt -> nt.x^2, (x=1.,))
ERROR: MethodError: no method matching adjoint(::ChainRulesCore.Tangent{NamedTuple{(:x,), Tuple{Float64}}, NamedTuple{(:x,), Tuple{Float64}}})
Closest candidates are:
  adjoint(::Union{QR, LinearAlgebra.QRCompactWY, QRPivoted}) at ~/.julia/juliaup/julia-1.7.3+0.x64/share/julia/stdlib/v1.7/LinearAlgebra/src/qr.jl:509
  adjoint(::Union{Cholesky, CholeskyPivoted}) at ~/.julia/juliaup/julia-1.7.3+0.x64/share/julia/stdlib/v1.7/LinearAlgebra/src/cholesky.jl:538
  adjoint(::Hessenberg) at ~/.julia/juliaup/julia-1.7.3+0.x64/share/julia/stdlib/v1.7/LinearAlgebra/src/hessenberg.jl:423
  ...
Stacktrace:
 [1] _broadcast_getindex_evalf
   @ ./broadcast.jl:670 [inlined]
 [2] _broadcast_getindex
   @ ./broadcast.jl:643 [inlined]
 [3] (::Base.Broadcast.var"#29#30"{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(adjoint), Tuple{Tuple{ChainRulesCore.Tangent{NamedTuple{(:x,), Tuple{Float64}}, NamedTuple{(:x,), Tuple{Float64}}}}}}})(k::Int64)
   @ Base.Broadcast ./broadcast.jl:1075
 [4] ntuple
   @ ./ntuple.jl:48 [inlined]
 [5] copy
   @ ./broadcast.jl:1075 [inlined]
 [6] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(adjoint), Tuple{Tuple{ChainRulesCore.Tangent{NamedTuple{(:x,), Tuple{Float64}}, NamedTuple{(:x,), Tuple{Float64}}}}}})
   @ Base.Broadcast ./broadcast.jl:860
 [7] jacobian(ab::AbstractDifferentiation.ReverseRuleConfigBackend{Zygote.ZygoteRuleConfig{Zygote.Context{false}}}, f::Function, xs::NamedTuple{(:x,), Tuple{Float64}})
   @ AbstractDifferentiation ~/.julia/packages/AbstractDifferentiation/o62DE/src/AbstractDifferentiation.jl:591
 [8] gradient(ab::AbstractDifferentiation.ReverseRuleConfigBackend{Zygote.ZygoteRuleConfig{Zygote.Context{false}}}, f::Function, xs::NamedTuple{(:x,), Tuple{Float64}})
   @ AbstractDifferentiation ~/.julia/packages/AbstractDifferentiation/o62DE/src/AbstractDifferentiation.jl:48
 [9] top-level scope
   @ REPL[6]:1

Does this package expect all arguments be scalars/vectors that have an adjoint defined? Eg this works:

AD.gradient(AD.ZygoteBackend(), nt -> nt.x^2, ComponentVector(x=1.,))

(I'm hoping not because it would definitely hurt usability to not be able to use Zygote's full capability, where that is not a requirement)

AbstractDifferentiation v0.4.3
Zygote v0.6.44

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions