Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tangents vs Cotangents #160

Open
willtebbutt opened this issue Apr 30, 2020 · 5 comments
Open

Tangents vs Cotangents #160

willtebbutt opened this issue Apr 30, 2020 · 5 comments
Labels
help wanted Extra attention is needed speculative fairly out there ideas for consideration in longer term

Comments

@willtebbutt
Copy link
Member

willtebbutt commented Apr 30, 2020

We don't currently maintain a distinction between tangents and cotangents in ChainRules. I've yet to come up with an example where it matters whether or not you do, but it would be good to understand this sooner rather than later.

@willtebbutt willtebbutt added the help wanted Extra attention is needed label Apr 30, 2020
@nickrobinson251 nickrobinson251 added the Complex Differentiation Relating to any form of complex differentiation label Apr 30, 2020
@oxinabox
Copy link
Member

The Swift folk used to make a distrinction,
and then swapped away from it to treating them the same.

They are pretty smart about this, so I think we can follow their lead.
It would be good if someone could find their notes on that

@oxinabox oxinabox added the speculative fairly out there ideas for consideration in longer term label Apr 30, 2020
@nickrobinson251
Copy link
Contributor

swiftlang/swift#24825 (and docs on their types https://github.com/tensorflow/swift/blob/master/docs/DifferentiableTypes.md)

@nickrobinson251 nickrobinson251 removed the Complex Differentiation Relating to any form of complex differentiation label Apr 30, 2020
@willtebbutt
Copy link
Member Author

Good enough for me. I'm going to close this and move on with life.

@oxinabox
Copy link
Member

oxinabox commented May 1, 2020

Actually, maybe not.
Looking at swiftlang/swift#24825 many of their reasons don't apply to us.
Because julia doesn't have a static type system.
So perhaps this bears some more thought

@oxinabox oxinabox reopened this May 1, 2020
@sethaxen
Copy link
Member

Looking at the rules in ChainRules, we do use the tangents and cotangents differently. For the pushforwards, we always (I think) maintain the right type constraints and such so that the output of a function is tangent to the output of the primal. However, specifically for functions of AbstractArrays, we don't. In fact, the pullbacks are technically pulling back over a different primal function than the one we actually evaluated.

Many functions of abstract arrays in Base can generally be described as an embedding into the Arrays, followed by an operation, followed by another embedding into some other space. In the forward pass, those embeddings are implicitly used to project to the tangent at the primal values. The same should happen in reverse to project to the cotangent spaces. However, the general rrules implemented for AbstractArrays leave out the embeddings, instead behaving as though they were already passed something embedded into the Arrays. Consequently, the pullback does not project its output to the cotangent space of the input to the primal function. Since operations on differentials are linear, we can usually get away with this (that is, some pullbacks will project, others won't), so long as the constructor of the AbstractArray subtype eventually projects. (i.e., accumulate-then-project instead of project-then-accumulate). That inversion of the operation order basically stops working the instant a function of the abstract array effectively ignores its embedding into the arrays. Then the change in order matters. (e.g. calling .data in Symmetric, as discussed in JuliaDiff/ChainRules.jl#191).

Sorry for the slight (co)tangent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed speculative fairly out there ideas for consideration in longer term
Projects
None yet
Development

No branches or pull requests

4 participants