Zygote / ReverseDiff not matching input types

evolbio
Tue, 10 May 2022 19:27:06 +0000
Machine Learning

In my code, the line (y ./ k).^h throws a Zygote / ReverseDiff error but works without problem with ForwardDiff. Here, k and h are views of a parameter vector and y is a subset of the variable vector that depends on the parameters, with y obtained by getindex() on the variable vector

ERROR: MethodError: (::ReverseDiff.ForwardOptimize{typeof(/)})
(::ReverseDiff.TrackedReal{ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}, ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}, ReverseDiff.TrackedArray{ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}, ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}}}}, ::ReverseDiff.TrackedReal{Float64, Float64, ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}}}) is ambiguous. Candidates:
(self::ReverseDiff.ForwardOptimize{F})(t::ReverseDiff.TrackedReal{V, D}, x::Real) where {F, V, D} in ReverseDiff at /opt/julia/packages/ReverseDiff/Z4pL0/src/macros.jl:121
(self::ReverseDiff.ForwardOptimize{F})(x::Real, t::ReverseDiff.TrackedReal{V, D}) where {F, V, D} in ReverseDiff at /opt/julia/packages/ReverseDiff/Z4pL0/src/macros.jl:109
Possible fix, define
(::ReverseDiff.ForwardOptimize{F})(::ReverseDiff.TrackedReal{V, D}, ::ReverseDiff.TrackedReal{V, D}) where {F, V, D, V, D}

I can see in ReverseDiff/Z4pL0/src/macros.jl what candidate macros might look like but I am not sure how to fix the problem. Is it that TrackedReal has three parameters and so does not match the two-parameter types in the macro:
(self::ForwardOptimize{F})(a::TrackedReal{V1,D}, b::TrackedReal{V2,D}) where {F,V1,V2,D}

I don’t have any experience extending Zygote/ForwardDiff although I vaguely get the idea. Not sure how to create a MWE for this particular problem. Thanks.

1 post - 1 participant