Is there a way I can tell Zygote to automatically apply Zygote.dropgrad()
for all function numerical arguments that are non-differentiable?
Example:
julia> import Zygote
julia> # naiively defining my function, and using Zygote to calculate the gradient
f(n::Integer,x::Real) = sin(n*x)
f (generic function with 1 method)
julia> Zygote.gradient(f, 100, π)
(3.141592653589793, 100.0)
Zygote performs automatic differentiation with respect to n
, although n
is an integer and f
can’t be differentiated with respect to n
.
I hope Zygote can apply Zygote.dropgrad()
to all arguments that are Integers, like n
:
julia> f(n::Integer,x::Real) = sin(Zygote.dropgrad(n) * x)
f (generic function with 1 method)
julia> Zygote.gradient(f, 100, π)
(nothing, 100.0)