-
Notifications
You must be signed in to change notification settings - Fork 606
Excluding function arguments from differentiation #440
Comments
|
Some hasty answers, feel free to ask for clarification! TF-1250 tracks differentiation with respect to multiple results.
This is probably because you called It doesn't matter that you registered a This is something we can clear up in Differentiable Swift usage documentation:
|
I think you can always avoid mutation via functionalization: make This is invasive though - TF-1250 will support differentiation wrt |
|
I ought to stop closing issues upon answering. Feel free to close if the answers makes sense! |
I think that would be perfect. I've tried that intuitively a few times without knowing it didn't exist yet.
Actually, the error pops up as soon as I add the inout parameter to the function signature, without actually using it in the function at all.
Doesn't a function have to return a single |
This make sense before differentiation supports multiple results (TF-1250). As soon as you add an
True. You can always use
|
Thank you! That connected a few things in my brain. |
So I could pass |
Sure thing! Check out the Wikipedia page on "Gradient":
The differentiable programming manifesto section on "pullback-producing differential operators" shows how
Yes. |
|
Yeah it makes perfect sense mathematically, I guess I just hadn't connected some things yet. I'm 60% sure anything I just said actually makes sense haha |
Differentiation as "an algebraic manipulation of the original equation" sounds like symbolic differentiation à la Wolfram Alpha. Automatic differentiation is in fact quite similar to symbolic differentiation (section 2.1 of "Demystifying Differentiable Programming").
The chain rule of differentiation gives us a way to compute derivatives of composed functions. Here's a short chain: Imagine you have a long chain with a bunch of
In fact, the association (grouping of parentheses) of multiplication affects efficiency. This is the same problem as matrix chain multiplication. The optimal association may be mixed-mode (a mix of forward-mode and reverse-mode differentiation). I'm not sure what introductory resources best explain these ideas. I learned quite a bit from Conal Elliott's "The simple essence of automatic differentiation", but I'm still digesting it after months. |
Yes, exactly what I meant, forgot the term. Thanks for contextualizing my hazy thoughts, I've got a lot to digest here! |


I've gotten stuck at a similar junction a few times. It's where I have a loss function that I'm feeding some stateful data structure, and I want the state of the data as well as the cost at the end. However, the output of the loss function must be a single scalar, so I can't return the state as well. I've been solving it by saving the state off to a global variable (right before
return cost) until now, but I need a better solution.I've tried adding an inout argument to
loss, but I've failed to exclude it from differentiation with@differentiable(wrt: (only one of the two)). I still get the compiler errorCannot differentiate functions with both an 'inout' parameter and a resultSo generally, what exactly is the pattern to include and exclude arguments from differentiation, and specifically, is there a better way to solve my state problem than a global variable?
Thanks!
The text was updated successfully, but these errors were encountered: