auto-differentiation / xad

Powerful automatic differentiation in C++ and Python
https://auto-differentiation.github.io
GNU Affero General Public License v3.0
256 stars 23 forks source link

JIT Code Generation #70

Open auto-differentiation-dev opened 1 year ago

auto-differentiation-dev commented 1 year ago

In some applications, the exact same calculations need to be carried out for different inputs repeatedly. Examples are Monte-Carlo simulation where the execution path (branches, etc.) is independent of the input data point.

Re-recording the tape on every path is redundant in this case, and it may be beneficial to record only one path on tape and then generate compiled code from this recording just in time. This code should produce both the value and the derivatives, and optimisations can be applied to increase performance. The overhead of JIT compilation should be compensated for larger numbers of repeated executions.

It would be good to add such a feature to XAD as an option.

stebos100 commented 1 year ago

Hi All !

I would just like to enquire if this enhancement has been employed within XAD ? And if so is there an example of this being done in code ?

Looking forward to hearing from you

Kind regards Stephan

auto-differentiation-dev commented 1 year ago

Hi Stephan,

This feature has not yet been employed in XAD - it is in planning stage at the moment.

At this point we envisage the following steps, and are interested in feedback and ideas:

NOTE: It is very important that the code-path stays exactly the same for any other inputs, as it's recorded only once. It is essential that no branches, polymorphic function calls, number of loop iterations, etc, depend on the independent input data. Ideas how to enforce and detect data-dependent branching are welcome.