Turing.jl icon indicating copy to clipboard operation
Turing.jl copied to clipboard

Can DifferentiationInterface be useful for Turing?

Open gdalle opened this issue 1 year ago • 6 comments

Hi there! @adrhill and I recently started https://github.com/gdalle/DifferentiationInterface.jl to provide a common interface for automatic differentiation in Julia. We're currently chatting with Lux.jl, Flux.jl and Optimization.jl to see how they can benefit from it, and so my mind went to Turing.jl as another AD power user :) DifferentiationInterface.jl only guarantees support for functions of the type f(x) = y or f!(y, x) with standard numbers or arrays in and out. Within these restrictions, we are compatible with 13 different AD backends, including the cool kids like Enzyme.jl and even the hipsters like Tapir.jl. Do you think it could come in handy? Ping @yebai @willtebbutt

gdalle avatar Apr 02 '24 15:04 gdalle

Some issues that seem related to AD support (not sure they are all relevant here):

  • https://github.com/TuringLang/Turing.jl/issues/2186
  • https://github.com/TuringLang/Turing.jl/issues/2141
  • https://github.com/TuringLang/Turing.jl/issues/2000
  • https://github.com/TuringLang/Turing.jl/issues/1988
  • https://github.com/TuringLang/Turing.jl/issues/1835
  • https://github.com/TuringLang/Turing.jl/issues/1754
  • https://github.com/TuringLang/Turing.jl/issues/1481
  • https://github.com/TuringLang/Turing.jl/issues/1419

gdalle avatar Apr 02 '24 15:04 gdalle

Turing's current interface to autodiff backends is based on LogDensityProblemsAD -- it is a fairly lightweight package for sharing glue code to various autodiff backends. You can take a look there to see how things might work.

yebai avatar Apr 02 '24 15:04 yebai

Looks great!

Is there a summary of how this is different from AbstractDifferentiation.jl somewhere?:)

torfjelde avatar Apr 02 '24 19:04 torfjelde

I updated the summary in this issue: https://github.com/JuliaDiff/AbstractDifferentiation.jl/issues/131

gdalle avatar Apr 02 '24 19:04 gdalle

Hi, I think DifferentiationInterface could be perfectly useful for AdvancedVI. However, for that, I think it would be useful to add an interface where auxiliary information can be passed to the target function. For example, like this. This should be very useful for any statistical application that uses minibatch subsampling. Apparently, Tapir supports passing auxiliary input to the target function. So it would be nice to have a unifying interface that provides access to that. (It would also be really nice if ReverseDiff precompiled tapes provided this feature, but unfortunately doesn't.)

Red-Portal avatar Jun 15 '24 03:06 Red-Portal

Sounds reasonable, I have opened this issue to keep track:

  • https://github.com/gdalle/DifferentiationInterface.jl/issues/311

gdalle avatar Jun 15 '24 05:06 gdalle

Closing this in favour of https://github.com/tpapp/LogDensityProblemsAD.jl/pull/29; Turing will automatically use DI when https://github.com/tpapp/LogDensityProblemsAD.jl/pull/29 is merged.

yebai avatar Sep 02 '24 20:09 yebai