Open mrazomej opened 6 months ago
Are you using TaylorDiff v0.2.1 (the latest released version) but looking at the code of the TaylorDiff.jl main branch? Note that there seem to have been a lot of changes between the two.
As for the behaviour being different between versions, I would not suspect rules not being picked up first. It's possible that either TaylorDiff.jl or Julia Base changed some implementation details between 1.9 and 1.10, so that code used to take a path that was differentiable but now is not. Again though, we need to know what versions of Zygote and TaylorDiff you're using, as well as if they're the same versions across 1.9 and 1.10.
Thank you so much for your quick response. I was going to add the versions of the packages, and I completely forgot.
For both, 1.9.4
and 1.10+
I am using the latest versions of the packages.
[e88e6eb3] Zygote v0.6.69
[b36ab563] TaylorDiff v0.2.1
Can you try adding TaylorDiff#main and seeing if that changes things?
Just did it.
pkg> add TaylorDiff#main
Cloning git-repo `https://github.com/JuliaDiff/TaylorDiff.jl.git`
Updating git-repo `https://github.com/JuliaDiff/TaylorDiff.jl.git`
same error
It's possible that either TaylorDiff.jl or Julia Base changed some implementation details between 1.9 and 1.10, so that code used to take a path that was differentiable but now is not.
Can confirm it goes even deeper than this to the compiler. To demonstrate:
1.9:
julia> @code_warntype TaylorScalar((1,))
MethodInstance for TaylorScalar(::Tuple{Int64})
from TaylorScalar(value::Tuple{Vararg{T, N}}) where {T, N} @ TaylorDiff ~/.julia/packages/TaylorDiff/SMDgC/src/scalar.jl:17
Static Parameters
T = Int64
N = 1
Arguments
#self#::Type{TaylorScalar}
value::Tuple{Int64}
Body::TaylorScalar{Int64, 1}
1 ─ %1 = Core.apply_type(TaylorDiff.TaylorScalar, $(Expr(:static_parameter, 1)), $(Expr(:static_parameter, 2)))::Core.Const(TaylorScalar{Int64, 1})
│ %2 = (%1)(value)::TaylorScalar{Int64, 1}
└── return %2
1.10:
julia> @code_warntype TaylorScalar((1,))
MethodInstance for TaylorScalar(::Tuple{Int64})
from TaylorScalar(value::Tuple{Vararg{T, N}}) where {T, N} @ TaylorDiff ~/.julia/packages/TaylorDiff/SMDgC/src/scalar.jl:17
Static Parameters
T = Int64
N = 1
Arguments
#self#::Type{TaylorScalar}
value::Tuple{Int64}
Body::TaylorScalar{Int64, 1}
1 ─ %1 = Core.apply_type(TaylorDiff.TaylorScalar, $(Expr(:static_parameter, 1)), $(Expr(:static_parameter, 2)))::Core.Const(TaylorScalar{Int64, 1})
│ %2 = %new(%1, value)::TaylorScalar{Int64, 1}
└── return %2
Essentially, the compiler can skip the intermediate step of calling the Type constructor when constructing new values. This means that rules like https://github.com/JuliaDiff/TaylorDiff.jl/blob/4f7b477b188ef15f6a4368285bb2c40319089a48/src/chainrules.jl#L9-L12 may not be picked up because Zygote has a fallback path for Expr(:new)
it uses unconditionally. Evidently something needs to change to workaround this change in internals, but it's not clear who should make that change yet.
@ToucheSir any news on this issue?
Unfortunately, no. I've not heard anything from the Base Julia side about possible solutions and I wouldn't know how to tackle this on the Zygote side. If somebody has news on the former or a concrete proposal for the latter, please chime in.
Zygote
fails to userrule
s defined by other packages when run withJulia 1.10+
I noticed this when looking at compatibility with
TaylorDiff.jl
.In
Julia 1.9.4
:In
Julia 1.10+
:The last line gives the following error:
But those
@adjoint
s are definitely defined inTaylorDiff.jl