Open bamos opened 2 years ago
I am not sure I understand fully. The goal of Tutorial 1 is to show how to use Theseus to solve an optimization problem. I'm not sure how the usage of Theseus is needed for the analysis you suggest adding?
I am not sure I understand fully. The goal of Tutorial 1 is to show how to use Theseus to solve an optimization problem. I'm not sure how the usage of Theseus is needed for the analysis you suggest adding?
I was thinking at the end of the derivative tutorial (the second one) since this is another demonstration of the derivatives that can be obtained with Theseus
(Your description above says Tutorial 1. It also seems like you're using Tutorial 1 code.)
I still don't see how Theseus is necessary to obtain these derivatives? The torch documentation suggests the function can be used directly on any torch tensors? Does this somehow depend on the internals of the torch grad
implementation and the Theseus forward
implementation? If so, can you provide more details?
(Your description above says Tutorial 1. It also seems like you're using Tutorial 1 code.)
Ah it's the problem from Tutorial 1 that I added derivatives to, like Tutorial 2 uses
I still don't see how Theseus is necessary to obtain these derivatives? The torch documentation suggests the function can be used directly on any torch tensors? Does this somehow depend on the internals of the torch
grad
implementation and the Theseusforward
implementation? If so, can you provide more details?
Right, it's because the Theseus forward computation can be seen as something that takes in the data x
/y
and optimizes over and returns the best a
/b
. Thus the grad
call here to obtain da/dx
is going backwards and unrolling through Theseus' inner optimization steps.
But this can be done on any function with torch.autograd.grad
, right? I am not still sure I understand how the Theseus computation specifically matters here.
But this can be done on any function with
torch.autograd.grad
, right? I am not still sure I understand how the Theseus computation specifically matters here.
Hmm, it would indeed be possible to solve the least squares problem without Theseus and obtain these derivatives in other ways, but to me, this demonstrates that the Theseus computations to solve the least squares problem indeed enable the derivatives that we say it provides, i.e. that Theseus finds the optimal variables and we can then differentiate through those w.r.t. other parameters defining the optimization problem
Also not every function can be nicely differentiated with torch.autograd.grad
, e.g. if we solve the NLLS problem with one of torch's built-in optimizers that do in-place, non-differentiable operations, then using torch.autograd.grad
through that solution (of a
) doesn't give the right derivatives (w.r.t. x
). Tangentially related, but in this case, higher is one other solution to this that helps adds these derivatives (but the goals/functionality of higher are much different than Theseus' focus on NLLS problems/solvers)
Hmm, it would indeed be possible to solve the least squares problem without Theseus and obtain these derivatives in other ways, but to me, this demonstrates that the Theseus computations to solve the least squares problem indeed enable the derivatives that we say it provides, i.e. that Theseus finds the optimal variables and we can then differentiate through those w.r.t. other parameters defining the optimization problem
So I am not sure @luisenp would want the users to use torch.autograd.grad
directly on Theseus tensors; from our discussion, I believe the preference is to have the user go through the Theseus API only. (If we still want to demonstrate that Theseus computations are nicely differentiable, we should move it to Tutorial 2, since iirc we do not discuss differentiating through functions till then.)
Thanks all for the discussion. @bamos How about starting this as a new short tutorial and then seeing if there is any overlap with others? Including visualization of gradients is also quite valuable.
demonstrates that the Theseus computations to solve the least squares problem indeed enable the derivatives that we say it provides
This can be posed (within the potentially new tutorial) as an explainer and sanity check and not something we recommend users to do in practice as @vshobha mentions, "... preference is to have the user go through the Theseus API only ...".
not every function can be nicely differentiated
This seems useful to demonstrate as a second point after the above. We can try to explore the connection with higher later but it maybe useful to reference it here.
Thanks all for the discussion. @bamos How about starting this as a new short tutorial and then seeing if there is any overlap with others? Including visualization of gradients is also quite valuable.
Yeah! I'll write up a quick new one and send it in soon
demonstrates that the Theseus computations to solve the least squares problem indeed enable the derivatives that we say it provides
This can be posed (within the potentially new tutorial) as an explainer and sanity check and not something we recommend users to do in practice as @vshobha mentions, "... preference is to have the user go through the Theseus API only ...".
Hmm, why should we discourage use-cases like this? If the user wants the gradients through the NLLS solve, calling torch.autograd.grad
or .backward()
on (something derived from) Theseus' output seems functional and reasonable (and the motion planning tutorial now is using .backward()
here too)
One interesting use-case of the derivatives Theseus provides in the quadratic fitting example in tutorial 1 is that they can also be used to obtain the derivative of the function w.r.t. the input data to do some form of sensitivity analysis to see how sensitive the loss/parameters are w.r.t. individual data points. We have a small example of this in section 6.1 of cvxpylayers for logistic regression:![image](https://user-images.githubusercontent.com/707462/145696630-c3f044b3-5bf6-4cd3-8be7-02f46f2d8ae9.png)
I quickly added these for the quadratic fitting example (![image](https://user-images.githubusercontent.com/707462/145696682-d6b25d0e-b486-4496-bb2a-6983e6c94690.png)
da/dxy
) to see what they would look like and we get something reasonable. The following shows that taking these negative gradient steps would decrease the quadratic parametera
.Do you think this would be interesting to include in one of the tutorials/examples? Maybe as a new section at the end of tutorial 2?
\cc @luisenp @mhmukadam @vshobha
Code