Skip to content

In-place versions e.g. logdensity_and_gradient!? #115

@penelopeysm

Description

@penelopeysm

In DynamicPPL/Turing, we quite often wrap models inside something that obeys the LDP interface. However, under the hood we use DifferentiationInterface.value_and_gradient to calculate logdensity_and_gradient.

It's very trivial to extend this code to support in-place versions, by changing from DI.value_and_gradient to DI.value_and_gradient!. Similar considerations apply for the second-order functions too. However, LDP doesn't provide a logdensity_and_gradient! function, which would be the natural place to stick an overload.

Conscious of the comment in #110 (comment)

I am happy to add API for anything if someone actually needs it. If there is a project, however experimental, that needs this, please comment here or make a PR.

I'd mention that I've seen at least two instances where people have manually implemented what is essentially logdensity_and_gradient!, and this is just off the top of my head:

https://github.com/Julia-Tempering/Pigeons.jl/blob/115265329bb291c389349ab05d9298f17183ba0c/ext/PigeonsDynamicPPLExt/interface.jl#L109-L116

https://github.com/TuringLang/AdvancedVI.jl/blob/721964c80d8d98ee8cb3b12466a257449c7d856e/src/algorithms/fisherminbatchmatch.jl#L94-L97

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions