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

Algebraic Solver Differentiation Speedup #2401

Closed
jgaeb opened this issue Mar 2, 2021 · 1 comment
Closed

Algebraic Solver Differentiation Speedup #2401

jgaeb opened this issue Mar 2, 2021 · 1 comment

Comments

@jgaeb
Copy link
Contributor

jgaeb commented Mar 2, 2021

Description

(This issue is a revival of #1257. Essentially all of what follows is cribbed from @charlesm93!)

It may be possible to improve how derivatives are propagated through the the algebraic solver. The basic idea is to use the implicit function theorem to get an “almost adjoint” method. Currently the vari class for the algebraic solver is implemented so that the Jacobian is calculated explicitly.

Using nested gradients (#1856), it is, however, possible to avoid constructing the entire Jacobian. Instead, using the method outlined here, it should be possible (in the notation of the linked post) to replace this computation with a single reverse mode sweep and n forward-mode sweeps (to calculate the partial derivatives of f with respect to v) and a matrix-vector solve. This will also eliminate a matrix-matrix solve, and additional speedup may come from getting the partial derivatives of f with respect to v from the solver itself rather than calculating them explicitly.

The plan is to rewrite stan::math::algebra_solver_vari to defer the calculation of the adjoints until .solve() is actually called. (This may require some tweaks to the Newton and Powell solver wrappers that use it as well.)

Expected Output

Propagating derivatives through implicit algebraic equations in reverse mode should be faster.

Discussion on Forum

https://discourse.mc-stan.org/t/algebraic-solver-differentiation-speedup/20845

Current Version:

v4.0.1

bbbales2 added a commit to jgaeb/math that referenced this issue Apr 17, 2021
bbbales2 added a commit to jgaeb/math that referenced this issue Apr 17, 2021
bbbales2 added a commit to jgaeb/math that referenced this issue Jun 26, 2021
@jgaeb
Copy link
Contributor Author

jgaeb commented Aug 19, 2021

Closed by #2421!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant