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

AD failure where Zygote succeeds #63

Closed
marius311 opened this issue Aug 23, 2022 · 4 comments
Closed

AD failure where Zygote succeeds #63

marius311 opened this issue Aug 23, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@marius311
Copy link

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
@ToucheSir
Copy link

For some reason, gradient(::ReverseRuleConfigBackend, ...) falls back to jacobian instead of calling https://github.com/JuliaDiff/AbstractDifferentiation.jl/blob/v0.4.3/src/ruleconfig.jl#L10 directly. That seems somewhat concerning, is there a reason the two functions haven't been hooked up? In the meantime, I suppose you could call pullback_function yourself.

@devmotion
Copy link
Member

This causes also #57, I noticed a while ago (#57 (comment)).

@ToucheSir
Copy link

Since there was a request for naming issues related to performance or awkward API in #88 (comment), wanted to bump this since I think it covers both. It also affects more than Zygote (as seen in the many linked issues) and even has (stalled?) PRs trying to address it.

@devmotion
Copy link
Member

Fixed by #128. On the master branch I get

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

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

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

4 participants