EnzymeAD / Enzyme.jl

Julia bindings for the Enzyme automatic differentiator
https://enzyme.mit.edu
MIT License
443 stars 62 forks source link

Overly strict enforcement of type equality for Duplicated #1441

Closed andrinr closed 4 months ago

andrinr commented 4 months ago

As mentioned in the FAQ:

In some ways, type equality is too strict: two different types can have the same data layout. For instance, a vector and a view of a matrix column are arranged identically in memory.

I am rather new to Julia and I might be mistaken, however I am pretty sure that using views in combination of Enzyme are best practice for differentiating explicit forward solvers. Therefore It does not some ideal that we are not allowed to use Views here.

wsmoses commented 4 months ago

You can use views. You just must use the same offset view in primal and shadow values (this is checked by the constructor).

andrinr commented 4 months ago

But in most cases, the only the primal is a view, while the shadow is not, as we not need to keep track of the entire history of shadow variables. This is even the case in the Box Model example from the Enzyme.jl documentation (no views but copies are used): https://enzyme.mit.edu/julia/stable/generated/box/