Skip to content
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

Automatic lazy broadcasting/optimization for arrays of distributions #1723

Closed
ElOceanografo opened this issue Oct 28, 2021 · 4 comments
Closed

Comments

@ElOceanografo
Copy link
Contributor

This issue follows up on this Discourse discussion. As @mohamed82008 explained, there multiple performance advantages to using a LazyArray inside an arraydist. To realize them, however, one must a) know about this lazy-array trick, and b) remember/look up the LazyArray syntax (which unfortunately includes a macro @~, which is similar but unrelated to Turing/DynamicPPL's ~).

Would it be possible to make the lazy-array trick more automatic? From a user perspective, I can think of a couple of ways this would work:

  1. Make arraydist convert its argument to a lazy array automatically (maybe based on some heuristic of when it's likely to benefit performance, and/or an optional argument lazy=true)
  2. Provide a macro like @lazyarraydist(...broadcasted computation...) to do the same thing
  3. Just make .~ parse to a lazily broadcasted array distribution

If 3) could work, that would be best, though I don't know if it would come with hidden downsides or implementation challenges. Basically, anything that decreases the number of special-case optimization hacks a user has to remember would be great!

@devmotion
Copy link
Member

Just a heads up, my plan is to remove arraydist and integrate and generalize it into the product distribution in Distributions.

@ElOceanografo
Copy link
Contributor Author

Cool, good to know. So would that that resolve the tracked-array vs. array-of-tracked issue @mohamed82008 was referring to in the discourse thread?

@dlakelan
Copy link
Contributor

dlakelan commented Nov 4, 2021

Hi, following this issue because I'm very interested in what ultimately is going to be the fast way to handle something like this. Currently the most reliable (doesn't cause crashes/backtraces) is for me to do Turing.@addlogprob!(sum(logpdf(....))) all manually.

@yebai
Copy link
Member

yebai commented Nov 12, 2022

We will likely adopt #1723 (comment).

In addition, it is better to keep the module macro transparent so more performance optimisation can be done outside DynamicPPL / Turing. #1900 should make this type of performance optimisation easier because the internal SimpleVarInfo data structure becomes more compatible with the Julia ecosystem.

@yebai yebai closed this as completed Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants