Skip to content

Interface for MAP/MLE/VI #2509

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

Open
yebai opened this issue Mar 16, 2025 · 12 comments
Open

Interface for MAP/MLE/VI #2509

yebai opened this issue Mar 16, 2025 · 12 comments
Labels
enhancement: interface API, interface related improvements enhancement

Comments

@yebai
Copy link
Member

yebai commented Mar 16, 2025

Proposal for a unified interface

optimise(model, MAP(), ...)
optimise(model, MLE(), ...)
optimise(model, VI(variational_distribution=q, ...), ...)

This resembles the sample(model, sampler, ...) interface for Monte Carlo sampling-based inference algorithms.

@yebai
Copy link
Member Author

yebai commented Mar 16, 2025

Relates to #2506; cc @Red-Portal

@yebai yebai added enhancement enhancement: interface API, interface related improvements labels Mar 16, 2025
@Red-Portal
Copy link
Member

I think one downside would be that referring to the documentation becomes a little tricky since everything requires specialization. For instance, if I only care about VI, doing ?optimise shows the documentation for unrelated functionalities.

@mhauru
Copy link
Member

mhauru commented Mar 17, 2025

How would the other arguments to optimise look? I'm not familiar with what sorts of arguments VI needs, but if they are different from what MAP/MLE needs, then that would be an argument in favour of separate functions. Another thing that I wonder about is the return value, if that would be very different (point-estimate vs posterior approximation).

I should also check what other PPLs do for this.

@Red-Portal
Copy link
Member

Red-Portal commented Mar 17, 2025

@mhauru I think that could be accommodated by pushing everything VI or ML/MAP specific to the object representing the algorithm like vi( ... ). So, the general interface for optimise could be left simple. But this also raises the question of what's the point of making everything go through optimise.

@DominiqueMakowski
Copy link
Contributor

DominiqueMakowski commented Mar 17, 2025

For what it's worth (i.e., from my basic user perspective), I really hope there is some kind of unified API (and it might emerge through some other packages acting like an interface to Turing, but might as well think of it early) à-la-rstan (brms / rstanarm):

brm(y ~ x,, data = df, algorithm = "sampling")

The algorithm can be swapped for anything ("meanfield", "fullrank", and "pathfinder") through global options. This makes is super convenient to prototype a script, test it and make sure it runs using "fast" algorithms, and then just change the default algo for MCMC and run it without any edits needed to the script.

In the case described above there is some additional considerations if one wants to incorporate approaches that return point-estimates (MLE/MAP optimization), but I don't think it poses that big of a challenge

@Red-Portal
Copy link
Member

Red-Portal commented Mar 17, 2025

Hi Dominique. I think here, the situation is slightly different since the unified interface is over ML and MAP. And the potential users of ML and MAP are most likely very different from VI. (On the other hand, I think choosing between MCMC, Pathfinder, or VI, for example, is a more likely scenario.) Therefore, I think there is less incentive the unify the interface.

@yebai
Copy link
Member Author

yebai commented Mar 20, 2025

A unified interface for all optimisation-based approximate inference algorithms (MAP/MLE/VI) would be nice. There are some implementation details on the optimise(model, InferAlgo(...), ...) function signature, but that could be figured out.

@yebai
Copy link
Member Author

yebai commented Mar 28, 2025

A more ambitious goal would be infer(model, data = df, algorithm = ...; kwargs):

  1. unify sampling, optimisation, and VI-based inference algorithms
  2. automatically construct a conditioned model, i.e. perform model() | data under the hood

@SamuelBrand1
Copy link

Nice!

Can I also give a shout out for Batch based (e.g. https://turinglang.org/DynamicPPL.jl/stable/api/#DynamicPPL.MiniBatchContext ) and (nearly equivalently) tempered (e.g. #2524)

@Red-Portal
Copy link
Member

Hi @SamuelBrand1 , yes, minibatching is on our agenda.

@bvdmitri
Copy link

@yebai

A more ambitious goal would be infer(model, data = df, algorithm = ...; kwargs):

this is how RxInfer does it too

@DominiqueMakowski
Copy link
Contributor

DominiqueMakowski commented Mar 31, 2025

Imagine a future where models are written in a universal backend-agnostic way (e.g., as a string) and then infer(model_as_str, ..., engine="Turing|RxInfer")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement: interface API, interface related improvements enhancement
Projects
None yet
Development

No branches or pull requests

6 participants