-
Notifications
You must be signed in to change notification settings - Fork 27
Closed
Description
I think the solution in #667 (fixing #662) likely isn't correct, because now it means functions that do not explicitly depend on the input will hit errors.
While nothing is used by Zygote to indicate that a rule has not been implemented, it might ALSO simply mean that there's no dependence. Thus I think throwing an error on every nothing is wrong. For example, this means we can't differentiate f(x) = 0.0 in Zygote, though other backends work:
julia> import Zygote, ForwardDiff; using DifferentiationInterface
julia> DifferentiationInterface.gradient(x -> 0.0, AutoForwardDiff(), [0.0])
1-element Vector{Float64}:
0.0
julia> DifferentiationInterface.gradient(x -> 0.0, AutoZygote(), [0.0])
ERROR: Zygote failed to differentiate function `#11` with argument types `(Vector{Float64},)` (the pullback returned `nothing`).
Stacktrace:
[1] check_nothing(::Nothing, f::Function, x::Vector{Float64}, contexts::Tuple{})
@ DifferentiationInterfaceZygoteExt ~/.julia/packages/DifferentiationInterface/TFo7D/ext/DifferentiationInterfaceZygoteExt/DifferentiationInterfaceZygoteExt.jl:31I think the best behavior is to just return nothing - it's not perfect, but it will avoid flagging cases like this. Even differentiating the function Base.zero is now an error, because of the fact that
julia> Zygote.gradient(zero, 1.0)
(nothing,)Ran into this for MilesCranmer/SymbolicRegression.jl#404
Metadata
Metadata
Assignees
Labels
No labels