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

Error with Constant Output on Zygote #614

Closed
jmurphy6895 opened this issue Nov 6, 2024 · 2 comments
Closed

Error with Constant Output on Zygote #614

jmurphy6895 opened this issue Nov 6, 2024 · 2 comments

Comments

@jmurphy6895
Copy link

As a follow on to #525 and #527, the AutoZygote() interface also has issues with constant output. Using the same code

using SatelliteToolboxTransformations

using DifferentiationInterface
import Zygote

jd_utc = date_to_jd(2004, 4, 6, 7, 51, 28.386009)

f_fd, df_fd = value_and_derivative(
    get_Δat,
    AutoFiniteDiff(),
    jd_utc
)

f_ad, df_ad = value_and_derivative(
    get_Δat,
    AutoZygote(),
    jd_utc
)

Zygote.gradient(get_Δat, jd_utc)

The error provided was

ERROR: MethodError: no method matching iterate(::Nothing)
The function iterate exists, but no method is defined for this combination of argument types.

Closest candidates are:
iterate(::ExponentialBackOff)
@ Base error.jl:264
iterate(::ExponentialBackOff, ::Any)
@ Base error.jl:264
iterate(::LibGit2.GitConfigIter)
@ LibGit2 C:\Users\jmurp\AppData\Local\Programs\Julia-1.11.1\share\julia\stdlib\v1.11\LibGit2\src\config.jl:225

Stacktrace:
[1] dot(x::Float64, y::Nothing)
@ LinearAlgebra C:\Users\jmurp\AppData\Local\Programs\Julia-1.11.1\share\julia\stdlib\v1.11\LinearAlgebra\src\generic.jl:855
[2]
@ DifferentiationInterface C:\Users\jmurp.julia\packages\DifferentiationInterface\tBGja\src\first_order\pushforward.jl:179
[3] #6
@ C:\Users\jmurp.julia\packages\DifferentiationInterface\tBGja\src\first_order\pushforward.jl:210 [inlined]
[4] ntuple
@ .\ntuple.jl:48 [inlined]
[5] value_and_pushforward
@ C:\Users\jmurp.julia\packages\DifferentiationInterface\tBGja\src\first_order\pushforward.jl:209 [inlined]
[6] value_and_derivative
@ C:\Users\jmurp.julia\packages\DifferentiationInterface\tBGja\src\first_order\derivative.jl:97 [inlined]
[7] value_and_derivative(::typeof(get_Δat), ::AutoZygote, ::Float64)
@ DifferentiationInterface C:\Users\jmurp.julia\packages\DifferentiationInterface\tBGja\src\fallbacks\no_prep.jl:61
[8] top-level scope @ c:\Users\jmurp.julia\dev\SatelliteToolboxTransformations\test\runtests.jl:23

On a positive note, both Forward and Reverse Enzyme seem to be working on the function call.

@gdalle
Copy link
Member

gdalle commented Nov 6, 2024

I think this is a fundamental limitation of Zygote, because when there is no chain rule, the returned value for the pullback is nothing:

julia> using Zygote

julia> f(x) = 1.0
f (generic function with 1 method)

julia> Zygote.gradient(f, 2.0)
(nothing,)

Interpreting this nothing in any other way (e.g. replacing it with a zero derivative) may lead to incorrect results, which is why I prefer to error. However, the error message could be nicer, as suggested by #604. What do you think?

@jmurphy6895
Copy link
Author

Thanks for the quick reply! Gotcha, yeah I think that's a fair solution.

In my problem, I don't think this will usually be an issue in practice but I'm just trying to make sure all the functions leading into the larger scope won't cause issues. Being able to grab that error I think will tell me that this function wouldn't cause problems.

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

2 participants