User defined gradients

Open
#3,432 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Active
Tech stack
cpp
Domain
backend

Research direction

The issue does not name specific files, tests, or entry points. Start by locating the existing user-defined function and autodiff mechanisms, then determine how a function could provide both its value and gradient while reusing intermediate values. Done means a documented API and tests showing that iterative algorithms avoid unnecessary autodiff work.

Written by the indexing model from the issue text.

Description

This has been come up a few times, and we discussed this yesterday

If a user defined function includes iterative algorithm with a fixed point the implict gradient is 0, but autodiff will diff through that iterative algorithm which may significant cost per each iteration. In such cases it would be useful if the user could define the gradient computation. If that gradient computation could be part of the user defined function (e.g. returning a tuple of value and gradient), then the value and gradient could be computed using the same intermediate values. This would be useful in cases, where the user defined function is something which would not be likely to be added to Stan math, but where avoiding the autodiff through iterative part could make the gradient computation order of magnitude faster.

It's not clear how complicated this would be to implement, but it was suggested that I create this issue and tag @SteveBronder

Dominant language
C++
Stars
2.8k
Forks
388
Avg merge
2d 17h
Merged PRs (30d)
15

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stan-dev/stan

All issues in stan-dev/stan

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.